-
Notifications
You must be signed in to change notification settings - Fork 23
Add new OIDC role for source mirror updates #1343
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||
| locals { | ||||||
| github_domain = "token.actions.githubusercontent.com" | ||||||
|
|
||||||
| mirror_roles = { | ||||||
| "sts.amazonaws.com" = { | ||||||
| "role_name_suffix" = "SpackSourceMirror${var.deployment_name == "prod" ? "" : "-${var.deployment_name}"}-${var.deployment_stage}", | ||||||
| "conditions" = [ | ||||||
| "repo:spack/spack-packages:ref:refs/heads/develop", | ||||||
| ], | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| data "aws_caller_identity" "current" {} | ||||||
|
|
||||||
| data "aws_iam_policy_document" "github_oidc_assume_role" { | ||||||
| for_each = local.mirror_roles | ||||||
|
|
||||||
| statement { | ||||||
| effect = "Allow" | ||||||
| actions = ["sts:AssumeRoleWithWebIdentity"] | ||||||
|
|
||||||
| principals { | ||||||
| type = "Federated" | ||||||
| identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${local.github_domain}"] | ||||||
| } | ||||||
|
|
||||||
| condition { | ||||||
| test = "StringEquals" | ||||||
| variable = "${local.github_domain}:aud" | ||||||
| values = [each.key] | ||||||
| } | ||||||
|
|
||||||
| condition { | ||||||
| test = "StringEqual" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| variable = "${local.github_domain}:sub" | ||||||
| values = each.value.conditions | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| resource "aws_iam_role" "source_mirror_sync" { | ||||||
| for_each = data.aws_iam_policy_document.github_oidc_assume_role | ||||||
|
|
||||||
| name = "SourceMirrorSync${local.mirror_roles[each.key].role_name_suffix}" | ||||||
| assume_role_policy = each.value.json | ||||||
| max_session_duration = 3600 * 6 # only allow a max of 6 hours for a session to be active | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||||||||||||||||||||
| variable "deployment_name" { | ||||||||||||||||||||||||
| type = string | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| variable "deployment_stage" { | ||||||||||||||||||||||||
| type = string | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| variable "region" { | ||||||||||||||||||||||||
| type = string | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+1
to
+11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file isn't needed (see comment about module)
Suggested change
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,3 +26,12 @@ module "spack_gitlab" { | |||||||||||||||||||
|
|
||||||||||||||||||||
| gitlab_token = var.gitlab_token | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| module "spack_github" { | ||||||||||||||||||||
| source = "../modules/spack_github" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| deployment_name = "prod" | ||||||||||||||||||||
| deployment_stage = "blue" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| region = "us-east-1" | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+29
to
+37
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module block isn't needed if we move the new resources into the
Suggested change
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = "~> 1.11.3" | ||
| required_version = "~> 1.11" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| terraform { | ||
| required_version = "~> 1.11.3" | ||
| required_version = "~> 1.11" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file doesn't need to be its own module - it's not using any of the variables it takes as input, and isn't reused anywhere. We can just move this entire file to
terraform/production/mirrors_iam.tf, and that eliminates all the unncessary module boilerplate.Essentially, exactly what we do for this file https://github.com/spack/spack-infrastructure/blob/main/terraform/production/iam.tf