CI/CD identity escalation policy lab
Reproduce the owned CI/CD identity escalation experiment and inspect its implementation and evidence limits.
DevSecOps 1 min read
Implementation
main.tf Terraform · 124 lines
vulnerability-research/cicd-identity-escalation/lab/main.tf
1terraform {
2 required_version = ">= 1.7.0, < 2.0.0"
3 required_providers {
4 aws = {
5 source = "hashicorp/aws"
6 version = "6.20.0"
7 }
8 }
9}
10
11provider "aws" {
12 region = "ca-central-1"
13 allowed_account_ids = [var.account_id]
14}
15
16variable "account_id" {
17 type = string
18 description = "Disposable account; never a production account. No default."
19 validation {
20 condition = can(regex("^[0-9]{12}$", var.account_id))
21 error_message = "Supply the dedicated twelve-digit lab account ID."
22 }
23}
24
25variable "artifact_bucket" {
26 type = string
27 description = "Existing isolated artifact bucket; public access blocked, versioned, centrally audited."
28 validation {
29 condition = can(regex("^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$", var.artifact_bucket))
30 error_message = "Supply a plain bucket name without ARN, wildcards, or path."
31 }
32}
33
34variable "subjects" {
35 type = map(string)
36 description = "Exact observed GitHub subjects, including immutable IDs if applicable."
37 validation {
38 condition = (toset(keys(var.subjects)) == toset(["staging", "production"]) &&
39 alltrue([for env, subject in var.subjects :
40 can(regex("^repo:[^*?<> ]+/[^*?<> ]+:environment:${env}$", subject))]))
41 error_message = "Use two exact subjects ending in environment:staging and environment:production."
42 }
43}
44
45locals {
46 provider_arn = "arn:aws:iam::${var.account_id}:oidc-provider/token.actions.githubusercontent.com"
47 permissions = { for env in keys(var.subjects) : env => {
48 Version = "2012-10-17"
49 Statement = [{
50 Sid = "OnlyEnvironmentArtifacts"
51 Effect = "Allow"
52 Action = ["s3:GetObject", "s3:PutObject"]
53 Resource = "arn:aws:s3:::${var.artifact_bucket}/${env}/*"
54 }]
55 } }
56 boundaries = { for env in keys(var.subjects) : env => {
57 Version = "2012-10-17"
58 Statement = concat(local.permissions[env].Statement, [
59 {
60 Sid = "DenyEveryOtherAPI"
61 Effect = "Deny"
62 NotAction = ["s3:GetObject", "s3:PutObject"]
63 Resource = "*"
64 },
65 {
66 Sid = "DenyOtherResources"
67 Effect = "Deny"
68 Action = "s3:*"
69 NotResource = "arn:aws:s3:::${var.artifact_bucket}/${env}/*"
70 }
71 ])
72 } }
73 trusts = { for env, subject in var.subjects : env => {
74 Version = "2012-10-17"
75 Statement = [{
76 Effect = "Allow"
77 Principal = { Federated = local.provider_arn }
78 Action = "sts:AssumeRoleWithWebIdentity"
79 Condition = { StringEquals = {
80 "token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
81 "token.actions.githubusercontent.com:sub" = subject
82 } }
83 }]
84 } }
85}
86
87# Bootstrap administrator owns these policies; the resulting runtime roles cannot
88# modify IAM, federation, their boundary, CloudTrail, KMS, or workflow repositories.
89resource "aws_iam_policy" "boundary" {
90 for_each = var.subjects
91 name = "research-${each.key}-boundary"
92 policy = jsonencode(local.boundaries[each.key])
93}
94
95resource "aws_iam_role" "deploy" {
96 for_each = var.subjects
97 name = "research-${each.key}-deploy"
98 max_session_duration = 3600
99 assume_role_policy = jsonencode(local.trusts[each.key])
100 permissions_boundary = aws_iam_policy.boundary[each.key].arn
101}
102
103resource "aws_iam_role_policy" "artifacts" {
104 for_each = var.subjects
105 name = "environment-artifacts"
106 role = aws_iam_role.deploy[each.key].id
107 policy = jsonencode(local.permissions[each.key])
108}
109
110output "policy_contract" {
111 description = "Pure policy documents consumed by offline behavioral tests. Not an STS result."
112 value = { for env in keys(var.subjects) : env => {
113 trust = local.trusts[env], identity = local.permissions[env], boundary = local.boundaries[env]
114 } }
115}
116
117output "audit_assumptions" {
118 value = [
119 "An independently administered organization trail records management events including global IAM/STS.",
120 "S3 object data events for the artifact prefixes must be selected separately.",
121 "Archive and alert routing are outside both deployment roles; test delivery and freshness.",
122 "The existing GitHub provider, bucket, KMS policy, SCPs, and resource policies require separate review."
123 ]
124}
Run it
bash vulnerability-research/cicd-identity-escalation/lab/validate.sh
The canonical setup and teardown contains prerequisites, isolation, complete code, commands, expected output and evidence collection. The research study contains the threat model, comparison matrix, limitations and consulted sources.
Run from repository root after reading that setup:
bash vulnerability-research/cicd-identity-escalation/lab/validate.sh
These are owned teaching targets. Cloud deployment is excluded. See the study's claim ledger before treating local model output as product enforcement evidence.