feat: Make runner trust policy extendable - #5275
Open
chris-griffin wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an input hook to extend the runner instance-role trust policy (assume-role policy) with additional IAM statements, addressing requests to parameterize/append trust relationships for cross-account use cases.
Changes:
- Introduces
runner_iam_role_additional_trust_policy_statementsat the root and runners module levels (and wires it throughmulti-runner). - Updates runner IAM role creation to append user-provided trust policy statements to the existing default trust policy.
- Adds a Terraform test verifying default behavior and appended-statement ordering, and updates module/root READMEs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| variables.tf | Adds new root input variable for additional runner trust policy statements. |
| main.tf | Passes the new variable into the runners module. |
| README.md | Documents the new root input. |
| modules/runners/variables.tf | Adds the corresponding runners-module input variable. |
| modules/runners/policies-runner.tf | Appends additional trust statements when rendering assume_role_policy. |
| modules/runners/tests/runner-trust-policy.tftest.hcl | Adds coverage for default and extended trust policy behavior. |
| modules/runners/README.md | Documents the new runners-module input. |
| modules/multi-runner/variables.tf | Extends multi_runner_config.runner_config schema to include the new option. |
| modules/multi-runner/runners.tf | Wires the new option through to the runners module. |
| modules/multi-runner/README.md | Updates multi-runner docs to include the new option. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+437
to
+446
| variable "runner_iam_role_additional_trust_policy_statements" { | ||
| description = "Additional statements appended to the trust policy (assume role policy) of the runner IAM role. Statements are in the IAM policy statement format. For example to allow the EC2 service to pass session tags add `[{ Effect = \"Allow\", Principal = { Service = \"ec2.amazonaws.com\" }, Action = \"sts:TagSession\" }]`." | ||
| type = any | ||
| default = [] | ||
|
|
||
| validation { | ||
| condition = can([for statement in var.runner_iam_role_additional_trust_policy_statements : statement]) | ||
| error_message = "The variable `runner_iam_role_additional_trust_policy_statements` must be a list of IAM policy statements." | ||
| } | ||
| } |
| assume_role_policy = jsonencode(merge(local.runner_role_trust_policy, { | ||
| Statement = concat( | ||
| local.runner_role_trust_policy.Statement, | ||
| var.runner_iam_role_additional_trust_policy_statements |
Comment on lines
+535
to
+544
| variable "runner_iam_role_additional_trust_policy_statements" { | ||
| description = "Additional statements appended to the trust policy (assume role policy) of the runner IAM role. Statements are in the IAM policy statement format. For example to allow the EC2 service to pass session tags add `[{ Effect = \"Allow\", Principal = { Service = \"ec2.amazonaws.com\" }, Action = \"sts:TagSession\" }]`." | ||
| type = any | ||
| default = [] | ||
|
|
||
| validation { | ||
| condition = can([for statement in var.runner_iam_role_additional_trust_policy_statements : statement]) | ||
| error_message = "The variable `runner_iam_role_additional_trust_policy_statements` must be a list of IAM policy statements." | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a configuration option so that the runner trust policy can be extended. Currently, it is hardcoded via
modules/runners/policies/instance-role-trust-policy.jsonTest Plan
terraform test,terraform validateandterraform fmt -checkall passedtflintpassed although it did raise a warning unrelated to this changeRelated Issues
Would address previously requested use cases like #4247 and #1315