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

Add Terraform for registry-k8s-io s3 buckets #3605

Merged

Conversation

BobyMCbobs
Copy link
Member

@BobyMCbobs BobyMCbobs commented Apr 7, 2022

Adds

  • buckets for different regions (currently us-west-1, us-west-2)
  • an IAM user for read+write access

to be used for registry.k8s.io in AWS

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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 Apr 7, 2022
@BobyMCbobs
Copy link
Member Author

Currently having issues with making the buckets publicly accessible but other than that it appears to be working

terraform apply -var prefix=test-

/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 Apr 7, 2022
@BobyMCbobs
Copy link
Member Author

@ameukam
Copy link
Member

ameukam commented Apr 8, 2022

/approve

Leave the LGTM to @dims or @jaypipes for the AWS features needed.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 8, 2022
@dims
Copy link
Member

dims commented Apr 8, 2022

/approve
/lgtm

/hold for @jaypipes to peek (feel free to remove hold in a day or so)

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ameukam, BobyMCbobs, dims

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

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 11, 2022
@BobyMCbobs
Copy link
Member Author

I managed to get there with the public bucket read 🎉

cc @jaypipes

This was commented out in case it might've been used.
Removing since the "syncing" will just be pushing to all of the buckets.
limitations under the License.
*/

variable "prefix" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to support things like a sandbox?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah! So before or after it's provisioned, for testing the Terraform a prefix can be added to test in another account with different names for things.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

bucket = aws_s3_bucket.registry-k8s-io.bucket

rule {
object_ownership = "BucketOwnerEnforced"
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 60 to 63
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:DeleteObject"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the Resource here refers to just the bucket resource, I believe the only permission you need in this block is:

s3:ListBucket

since all of the other permissions are only applicable to the Object resources referenced by the Resource string "${aws_s3_bucket.registry-k8s-io.arn}/*"

Copy link
Member Author

Choose a reason for hiding this comment

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

The intent of this aws_iam_user_policy is to allow the IAM user created in the above folder's accounts.tf to r/w the bucket for CI related things. The IAM user would be the one that is used with the promotion tools.

Should be permissions still be reduced here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@BobyMCbobs The IAM user that is writing objects to these buckets needs these permissions:

On the bucket resource (i.e. "${aws_s3_bucket.registry-k8s-io.arn}/":

  • s3:ListBucket

On the object resources within that bucket (i.e. "${aws_s3_bucket.registry-k8s-io.arn}/*":

  • s3:PutObject
  • s3:GetObject
  • s3:DeleteObject

Hope that makes sense! :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you @jaypipes, I've updated the permissions in 3a99bd5

"Action" : [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
Copy link
Contributor

Choose a reason for hiding this comment

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

And here, I don't believe you need to have s3:ListBucket since that is applicable to the bucket, not the objects within it.

type = string
}

variable "prefix" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be useful to have a comment here explaining the use of the prefix variable.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jaypipes, this is a good idea. I'll add it

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment in 6dc9f4c

@BobyMCbobs
Copy link
Member 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 Apr 11, 2022
@riaankleinhans
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 12, 2022
@k8s-ci-robot k8s-ci-robot merged commit 0b85573 into kubernetes:main Apr 12, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Apr 12, 2022
Comment on lines +17 to +20
resource "aws_iam_user" "registry-k8s-io-access" {
name = "${var.prefix}registry-k8s-io-access"
path = "/"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of this IAM user?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the principal that has the ability to push to the mirrored image layers we're storing in S3. I suppose we could have used an IAM Role instead of an IAM User, though.

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. 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
Development

Successfully merging this pull request may close these issues.

None yet

7 participants