Skip to content

Commit

Permalink
wip: refactor to use oidc instead of iam users
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Case <[email protected]>
  • Loading branch information
richardcase committed Sep 9, 2024
1 parent 640607f commit 1f526a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 130 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ limitations under the License.
*/


resource "aws_iam_user" "imagebuilder" {
name = "imagebuilder"
}

resource "aws_iam_user_login_profile" "imagebuilder_login" {
user = aws_iam_user.imagebuilder.name
password_reset_required = true
}

resource "aws_iam_access_key" "imagebuilder" {
user = aws_iam_user.imagebuilder.name
pgp_key = "mQINBGKe9M0BEACqiPeuyj4wm7uIfLqeYxDwj6QFf9D/vxnusBEy3Y7AoIUsRE7hAIAIkKxFseqPsz1BjhZFUHyz7W81He4LH5NafzjR//Rb0h6acmJARHSyrBJsDC837CPxJJaVkhX2Y2rim+MJyqsPUxvCoEY+9mf1z6IOQLFS1eglGxyo7SI4JvZtNUS/SXfa1LhaQ11DtuVB0MPd86xCaXLMr5gUOreh63IySuXIZibeUNpZeqAVsm0OKhHb8qDSo2tCKUqUB4lCF4VkOnqetO4lQQlMHrW6S6O/HQ8X/PPXVVvR8L8IjDLVEp5UcIgQwNmy3uCOR6AYj6OpMxGLg9iTyidB2JPV+bynkanjWYXQAnHwfhL2F67ihPvV0FqX52n+WUdYjxqLV/sZcIDj9FNIvw+6043q7hx2N80p/aaX6yFHZmcw4ygpTblgWw/7JTu1gGtASY6Jik95UiyDmEOrLdo7PNQyajkKsTvEVHwHEI8SEMpJr1fLrJms5QDebG9vtfEAFa3a2/nv0tfv+eTBMSKLvjvAmh88m5rQjRaIi971N2BlYTkdsCgQQPV+kwT2vtuI12RAn/ykH76WuEjXVtEliQPVwrAJQxTAWND481Q7SohQI9VcdhARV66gCctTaooWQdTYDd2FU61XA4FEo7QV8czrcc1pnzSLOLU+Acr3NQMkrwARAQABtCdSaWNoYXJk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Dj1pyrieUbcj1k22QA=="
}

output "imagebuilder_accesskey" {
value = aws_iam_access_key.imagebuilder.encrypted_secret
}

output "imagebuilder_keyid" {
value = aws_iam_access_key.imagebuilder.id
}

resource "aws_iam_user_policy_attachment" "test-attach" {
user = aws_iam_user.imagebuilder.name
policy_arn = aws_iam_policy.imagebuilder.arn
}

resource "aws_iam_policy" "imagebuilder" {
name = "capa-image-builder-policy"
path = "/"
Expand Down
42 changes: 42 additions & 0 deletions infra/aws/terraform/cncf-k8s-infra-aws-capa-ami/oidc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "aws_iam_openid_connect_provider" "github" {
url = "https://token.actions.githubusercontent.com"

client_id_list = [
"sts.amazonaws.com",
]

thumbprint_list = ["d89e3bd43d5d909b47a18977aa9d5ce36cee184c"]
}

data "aws_iam_policy_document" "capa-gh-trust" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]

principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.github.arn]
}

condition {
test = "ForAnyValue:StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}

condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:kubernetes-sigs/cluster-api-provider-aws"]
}
}
}

resource "aws_iam_role" "gh-image-builder" {
name = "gh-image-builder"
assume_role_policy = data.aws_iam_policy_document.capa-gh-trust.json
}

resource "aws_iam_role_policy_attachment" "gh-image-builder" {
role = aws_iam_role.gh-image-builder.name
policy_arn = aws_iam_policy.imagebuilder.arn
}
4 changes: 2 additions & 2 deletions infra/aws/terraform/cncf-k8s-infra-aws-capa-ami/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ limitations under the License.
terraform {
backend "s3" {}

required_version = "~> 1.6.0"
required_version = "~> 1.8.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.35"
version = "~> 5.66"
}
}
}
Expand Down

0 comments on commit 1f526a9

Please sign in to comment.