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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 Group for the CAPA maintainers
    • With the group having admin access in the account
  • IAM user for each maintainer of CAPA
    • Users added to the maintainer IAM group
  • IAM user for image builder automation
    • Minimum permissions as set out by packer for publishing AMIs
    • Access key encrypted with pgp key

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

Thanks @bryantbiggs 🙇 I will refactor this to use IAM Identity Centre instead


resource "aws_iam_group_policy_attachment" "maintainer-admin" {
group = aws_iam_group.maintainers.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
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 a least-privilege alternative to this access that we can grant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes for sure. How about initially we scope the "admin" down to only the services that are used for AMI publishing. The original thinking was that more elevated permissions would be needed initially whilst we work out all the automation / diagnose issues.

Ultimately, we could make it so it's just the build agent (prow or GHA) that has access.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, I don't even agree with giving AdministratorAccess to Prow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The more i think about it (based on your feedback), the maintainers don't need access to the account. Just whatever CI we use. I'll also re-think this based on that.

Comment on lines 22 to 25
resource "aws_iam_user_login_profile" "imagebuilder_login" {
user = aws_iam_user.imagebuilder.name
password_reset_required = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is there a login profile here? What would break if it were missing?


resource "aws_iam_access_key" "imagebuilder" {
user = aws_iam_user.imagebuilder.name
pgp_key = "mQINBGKe9M0BEACqiPeuyj4wm7uIfLqeYxDwj6QFf9D/vxnusBEy3Y7AoIUsRE7hAIAIkKxFseqPsz1BjhZFUHyz7W81He4LH5NafzjR//Rb0h6acmJARHSyrBJsDC837CPxJJaVkhX2Y2rim+MJyqsPUxvCoEY+9mf1z6IOQLFS1eglGxyo7SI4JvZtNUS/SXfa1LhaQ11DtuVB0MPd86xCaXLMr5gUOreh63IySuXIZibeUNpZeqAVsm0OKhHb8qDSo2tCKUqUB4lCF4VkOnqetO4lQQl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RWh9DesH14qLNmFwgYO2Rh5sYNtNp12G1Mzy1I6VSpaBZBh/CaKP6oaNG/0xJiY5m74kN9aTLRwBScbLIMT07KBM919oLRHjzDaMj657xTYLSqlew2q5XHqjTosopXHpRier/67MBU5LmleJ0ipTDDu+5cKlXteU9pIBj4YgyBVC/PtSHO3SbvDR7xdgFJs7JitkazONMrKf1ejXO/QF62MnRlGttAn96yJz4quowMIUFD1Fl8Vjj2/mCDQiPtYvjy/5s5Qoz+F3CJxejEEaaxSivdvg3bECkzEA2Ii/SZ9Nr8o9yDByOUHo16a1qEoxfSfpsvU0c30oUL+jYk2FlT80JnTf8VQczE+Q/M0E6/q/xI5C5nW9bYT8A1Dln47VGBmtGxkNZETilda5IjNyU4rmsAO6GxFalk3woAGBQ9XmDj1pyrieUbcj1k22QA=="
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we make this an input?

Or, better, switch to something else (eg OIDC) as a way to get session credentials.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes OIDC is a good way to go, thanks for the suggestion.

value = aws_iam_access_key.imagebuilder.id
}

resource "aws_iam_user_policy_attachment" "test-attach" {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are we testing?

"ec2:StopInstances",
"ec2:TerminateInstances"
],
"Resource": "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it feasible to scope this down, eg by resource tag?

resource "aws_iam_policy" "imagebuilder" {
name = "capa-image-builder-policy"
path = "/"
description = "Minimum required policy for image builder"
Copy link
Contributor

Choose a reason for hiding this comment

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

The actual policy seems broader than the description suggests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the permissions required for Packer when creating AMIs: https://developer.hashicorp.com/packer/integrations/hashicorp/amazon#iam-task-or-instance-role

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but I actually don't agree with Hashicorp here.

Check out https://blog.stefan-koch.name/2021/05/16/restricted-packer-aws-permissions

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 haven't seen that before, makes sense. Thats great, thanks for sharing that @sftim.

@sftim
Copy link
Contributor

sftim commented Aug 6, 2024

We have identity centre enabled for the management account

It's now also possible for an account to have its own IAM identity center.

@richardcase
Copy link
Contributor Author

It's now also possible for an account to have its own IAM identity center.

Yes and agreed that would be a better approach. I was planning on refactoring this to use identity centre based on feedback from @bryantbiggs (#6517 (comment)). So even better now that 2 people have suggested it.

Appreciate the review @sftim 🙇

@nrb
Copy link
Contributor

nrb commented Sep 3, 2024

Looking at some job failures on the CAPA suite (https://prow.k8s.io/job-history/gs/kubernetes-jenkins/pr-logs/directory/pull-cluster-api-provider-aws-e2e), I think we need this to make our CI healthy again.

Specifically, the job seems to be failing because of this error, taken from https://storage.googleapis.com/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_cluster-api-provider-aws/5039/pull-cluster-api-provider-aws-e2e/1829396767259496448/artifacts/clusters/bootstrap/resources/clusterctl-upgrade-1ab59h/AWSMachine/clusterctl-upgrade-3ymerb-control-plane-26mxd.yaml

message: 'failed to create AWSMachine instance: failed to find ami: found no AMIs
  with the name: "capa-ami-ubuntu-18.04-?1.25.0-*"'
reason: InstanceProvisionFailed

To my knowledge, the AMIs that CAPA was using were kept in an AWS account that VMware owned but stopped maintaining. I'm wondering if it has since been deleted.

@richardcase
Copy link
Contributor Author

richardcase commented Sep 9, 2024

In the process of using OIDC and a restricted role.

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

New changes are detected. LGTM label has been removed.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: richardcase
Once this PR has been reviewed and has the lgtm label, please assign dims for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

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.

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]>

terraform {
backend "s3" {
bucket = "cncf-k8s-infra-aws-capa-ami-tfstate"
Copy link
Member

@ameukam ameukam Sep 10, 2024

Choose a reason for hiding this comment

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

In which account this bucket is created ? I assume we want to manually create this ?

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 don't know to be honest. Which account are the TF buckets usually created in?

Copy link
Member

Choose a reason for hiding this comment

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

We usually keep the remote backend in the same AWS account. There is a pending effort to centralize the remote backends in a dedicated account. I'll manually create this bucket for this.

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, thank you @ameukam

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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