Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added tf infra for AWS ami account #6517

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

richardcase
Copy link
Contributor

@richardcase richardcase commented Mar 4, 2024

This adds AWS infra provisioning using terraform for the AWS account to be used to publish CAPA AMIs.

It adds the following:

  • IAM role with the permissions required for packer AMI publishing
  • OIDC provider for GitHub
  • Associates the role to the provider and limits the kubernetes-sigs/cluster-api-provider-aws

Fixes: #5010

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/infra Infrastructure management, infrastructure design, code in infra/ area/infra/aws Issues or PRs related to Kubernetes AWS infrastructure size/L Denotes a PR that changes 100-499 lines, ignoring generated files. sig/k8s-infra Categorizes an issue or PR as relevant to SIG K8s Infra. labels Mar 4, 2024
See the License for the specific language governing permissions and
limitations under the License.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an automated way to keep this file in sync with the team membership?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could look at doing something for that in the future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe using .tfvars?

@richardcase richardcase changed the title [WIP] feat: added tf infra for AWS ami account feat: added tf infra for AWS ami account Apr 30, 2024
@richardcase richardcase marked this pull request as ready for review April 30, 2024 09:56
@k8s-ci-robot k8s-ci-robot added area/bash Bash scripts, testing them, writing less of them, code in infra/gcp/ and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 30, 2024
@richardcase richardcase force-pushed the capa_ami_account_users branch 3 times, most recently from d3086f6 to eedff35 Compare April 30, 2024 10:34
Copy link

@salasberryfin salasberryfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only nitpicking on the README.

infra/aws/terraform/cncf-k8s-infra-aws-capa-ami/README.md Outdated Show resolved Hide resolved
@Danil-Grigorev
Copy link
Member

Thanks for addressing it @richardcase
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 3, 2024
*/


resource "aws_iam_user" "ankitasw" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing IAM users like this in 2024 is a bit sad - is this because we do not have SSO setup?

*/

terraform {
backend "s3" {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is state stored, or how is the bucket identified to store the state?

@richardcase
Copy link
Contributor Author

@bryantbiggs - thats for the review comments. I've been AFK for the last ~5 weeks on a break. I'll pick this up again and will get back to you asap on the comments.

@richardcase
Copy link
Contributor Author

richardcase commented Aug 6, 2024

We could potentially use IAM Identity centre for the AMI account(819546954734) instead of using IAM users/groups directly. We have identity centre enabled for the management account (see here.

Off the top of my head this would mean roughly:

  • Creating a new IAM Identity centre group for CAPA maintainers
  • Adding IAM identity centre users for each maintainer (with there email address) and assign to the group
    • Ideally ensuring that the OTP option is enabled on create user
    • Enforce MFA
  • Assign a "Admin" permission for account 819546954734 to the CAPA maintainer group

seeing IAM users like this in 2024 is a bit sad - is this because we do not have SSO setup?

@bryantbiggs - do you think that using IAM Identity Centre would be better than whats is currently in this PR? It still requires us to create/list the users in TF but at least we are not relying on the password output and a human to send them to the respective maintainer.

@bryantbiggs
Copy link
Contributor

bryantbiggs commented Aug 6, 2024

yes, SSO would be better. no matter what, we'll have to map users somewhere at the end of the day - but with SSO, we avoid the use of long lived credentials and it will give us the ability to map users to multiple accounts (as needed)

cc @upodroid

@richardcase
Copy link
Contributor Author

Done:

  • Update to use OIDC

Todo:

@@ -0,0 +1,42 @@
resource "aws_iam_openid_connect_provider" "github" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - we do have this https://github.com/terraform-aws-modules/terraform-aws-iam/tree/master/modules/iam-github-oidc-provider

Also, this is set ONCE per account - not sure if this would be the right place or if there is somewher where account level settings are created cc @ameukam

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, i wasn't aware of these. Thanks @bryantbiggs . I will update to use the modules instead of the handcrafted versions.

This is account is purely for the CAPA amis, so seems reasonable to have it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use this module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks technically fine but we need to double check with the Github admin team if we are allowed to do this.
(Kubernetes organizations are not the responsibilities of the Infra SIG)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall i ask in #github-management?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback from #github-management is that we shouldn't use OIDC from GHA in this way. Prow with IRSA should be used.

I will update the PR accordingly.

@richardcase richardcase force-pushed the capa_ami_account_users branch 2 times, most recently from a4c8147 to dc3bd39 Compare September 10, 2024 07:02
Comment on lines +24 to +26
for val in "${arr[@]}"; do
aws ec2 disable-image-block-public-access --region "$val"
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do this with a HCL code ? cc @bryantbiggs

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_image_block_public_access

Don't have to be in this PR. Just want to be sure we can skip bash configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking the other CAPA maintainer whether we need to continue publishing the AMIs to 15 regions. And whether we can just publish to 1 instead. If we change to just one then we can remove this completly.

But if there was a way that this could be done in HCL then that would give us options.

@richardcase
Copy link
Contributor Author

Thank you @ameukam and @bryantbiggs for the feedback, its very much appreciated.

source = "terraform-aws-modules/iam/aws//modules/iam-github-oidc-role"

name = "gh-image-builder"
subjects = ["kubernetes-sigs/cluster-api-provider-aws:*"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason why we are using github actions instead of prow? We can configure prow jobs to assume AWS roles very easily

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we started this work in was advised to use TF. Do we use IRSA or pod identity with any Prow jobs at present?

Copy link
Contributor Author

@richardcase richardcase Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a quick look i only see assume roles in a few jobs and these are "trusted" jobs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, with kops and capz.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, i will hunt them out. Thanks @upodroid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@upodroid - any chance you could point me at one of the jobs? I'm not really seeing how this is done from Prow.

I can see this trusted job: https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes/sig-k8s-infra/trusted/sig-k8s-infra-registry.yaml#L32

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@upodroid - any chance you could point me at one of the existing jobs that use assume roles?

@richardcase
Copy link
Contributor Author

After chatting with @upodroid the assume_role block has been removed.

@richardcase
Copy link
Contributor Author

@upodroid @ameukam - do you think there are any other changes required to this? I'd love to run this against the AMI account so that we can start publishing AMIs again.

Copy link
Member

@upodroid upodroid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Please apply this and cancel the hold when you are ready to merge this.
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 3, 2024
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 3, 2024
This adds AWS infra provisioning using terraform for the AWS account to
be used to publish CAPA AMIs.

Signed-off-by: Richard Case <[email protected]>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2024
@richardcase
Copy link
Contributor Author

richardcase commented Oct 4, 2024

Thanks @upodroid . This has now been run against the AMI account. I had to make a slight change to the bucket name as i created it in the wrong region. Would you be able to LGTM again?

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 4, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: richardcase, upodroid

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@richardcase
Copy link
Contributor Author

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 4, 2024
@k8s-ci-robot k8s-ci-robot merged commit 4ef41d1 into kubernetes:main Oct 4, 2024
3 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.32 milestone Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/bash Bash scripts, testing them, writing less of them, code in infra/gcp/ area/infra/aws Issues or PRs related to Kubernetes AWS infrastructure area/infra Infrastructure management, infrastructure design, code in infra/ cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/k8s-infra Categorizes an issue or PR as relevant to SIG K8s Infra. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REQUEST: Need for AWS account for hosting CAPA generated AMIs
9 participants