|
7 | 7 | namespace = local.helm_releases[index(local.helm_releases.*.id, "gha-runner-scale-set")].namespace
|
8 | 8 | }
|
9 | 9 | kube_github_runner_github_token = lookup(jsondecode(data.aws_secretsmanager_secret_version.infra.secret_string), "github_pat_token", "")
|
| 10 | + service_account_name = "gha-runner-scale-set-gha-rs-no-permission" |
10 | 11 |
|
11 | 12 | gha_runner_scale_set_values = <<VALUES
|
12 | 13 | githubConfigUrl: "https://github.com/madopsio/madactions"
|
@@ -57,3 +58,54 @@ resource "helm_release" "gha_runner_scale_set" {
|
57 | 58 | ]
|
58 | 59 | depends_on = [module.gha_runner_scale_set_controller_namespace]
|
59 | 60 | }
|
| 61 | + |
| 62 | +resource "aws_iam_role" "github_actions_runner_role" { |
| 63 | + count = local.gha_runner_scale_set.enabled ? 1 : 0 |
| 64 | + name = "${local.gha_runner_scale_set.name}-role" |
| 65 | + |
| 66 | + assume_role_policy = data.aws_iam_policy_document.github_actions_runner_assume_role_policy.json |
| 67 | +} |
| 68 | + |
| 69 | +data "aws_iam_policy_document" "github_actions_runner_assume_role_policy" { |
| 70 | + statement { |
| 71 | + actions = ["sts:AssumeRoleWithWebIdentity"] |
| 72 | + effect = "Allow" |
| 73 | + |
| 74 | + principals { |
| 75 | + type = "Federated" |
| 76 | + identifiers = [local.eks_oidc_provider_arn] |
| 77 | + } |
| 78 | + |
| 79 | + condition { |
| 80 | + test = "StringEquals" |
| 81 | + variable = "${local.eks_oidc_provider_arn}:sub" |
| 82 | + values = ["system:serviceaccount:${module.gha_runner_scale_set_controller_namespace[0].name}:${local.service_account_name}"] |
| 83 | + } |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +resource "aws_iam_role_policy" "github_actions_runner_policy" { |
| 88 | + count = local.gha_runner_scale_set.enabled ? 1 : 0 |
| 89 | + name = "${local.gha_runner_scale_set.name}-policy" |
| 90 | + role = aws_iam_role.github_actions_runner_role[0].id |
| 91 | + |
| 92 | + policy = data.aws_iam_policy_document.github_actions_runner_policy.json |
| 93 | +} |
| 94 | + |
| 95 | +data "aws_iam_policy_document" "github_actions_runner_policy" { |
| 96 | + statement { |
| 97 | + actions = [ |
| 98 | + "ecr:GetDownloadUrlForLayer", |
| 99 | + "ecr:BatchGetImage", |
| 100 | + "ecr:BatchCheckLayerAvailability", |
| 101 | + "ecr:PutImage", |
| 102 | + "ecr:InitiateLayerUpload", |
| 103 | + "ecr:UploadLayerPart", |
| 104 | + "ecr:CompleteLayerUpload", |
| 105 | + "ecr:GetAuthorizationToken", |
| 106 | + "ecr:ListImages" |
| 107 | + ] |
| 108 | + resources = ["*"] |
| 109 | + } |
| 110 | +} |
| 111 | + |
0 commit comments