-
Notifications
You must be signed in to change notification settings - Fork 0
Approval-Gated CI setup for self managed repo #91
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
70bfbad
83cf53f
0597184
e9bc59e
bb0306f
40e3904
53f9427
d5257c3
6fdf26e
c040b17
0e388fb
3fb5b45
24ab5ec
9f3ba15
f945867
9e41000
c619ed0
9a85cda
eb11ea9
e9b36f0
eb52ddf
96bbcb8
4069100
9e072cf
4ed6d66
be38f45
c3df554
f198476
8afdf04
891feb6
ae87474
fe1f160
23a0649
496aabf
eca07d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| backend "s3" { | ||
| bucket = "materialize-terraform-self-managed-state" | ||
| key = "github-setup/oidc/aws/terraform.tfstate" | ||
| region = "us-east-1" | ||
| encrypt = true | ||
| # profile = "" # Add your profile name here since backend block doesn't accept variables | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # IAM Role for GitHub Actions | ||
| resource "aws_iam_role" "github_actions" { | ||
| name = "mz-self-managed-github-actions-role" | ||
| max_session_duration = var.max_session_duration | ||
| assume_role_policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Action = "sts:AssumeRoleWithWebIdentity" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Federated = var.oidc_provider_arn | ||
| } | ||
| Condition = { | ||
| StringEquals = { | ||
| "token.actions.githubusercontent.com:aud" = "sts.amazonaws.com" | ||
| } | ||
| StringLike = { | ||
| "token.actions.githubusercontent.com:sub" = "repo:MaterializeInc/materialize-terraform-self-managed:*" | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
|
|
||
| tags = { | ||
| Name = "materialize-terraform-self-managed-github-actions-role" | ||
| } | ||
| } | ||
|
|
||
| # Admin policy for GitHub Actions (simplified for testing) | ||
| resource "aws_iam_role_policy_attachment" "github_actions_admin" { | ||
| role = aws_iam_role.github_actions.name | ||
| policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Outputs for GitHub Actions configuration | ||
| output "github_actions_role_arn" { | ||
| description = "ARN of the IAM role for GitHub Actions" | ||
| value = aws_iam_role.github_actions.arn | ||
| } | ||
|
|
||
| output "github_actions_role_name" { | ||
| description = "Name of the IAM role for GitHub Actions" | ||
| value = aws_iam_role.github_actions.name | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| variable "profile" { | ||
| description = "The AWS CLI profile to use for authentication" | ||
| type = string | ||
| default = "default" | ||
alex-hunt-materialize marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| variable "oidc_provider_arn" { | ||
| description = "The ARN of the OIDC provider for GitHub Actions" | ||
| type = string | ||
| } | ||
|
|
||
| variable "max_session_duration" { | ||
| description = "The maximum session duration for the IAM role" | ||
| type = number | ||
| default = 28800 # 8 hours | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = "~> 5.0" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "aws" { | ||
| profile = var.profile | ||
| region = "us-east-1" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||
| #!/usr/bin/env bash | ||||||||||||
|
|
||||||||||||
| # Exit early on error/unset var/pipe failure | ||||||||||||
| set -euo pipefail | ||||||||||||
|
|
||||||||||||
| # 1. Create a 4-hour token lifetime policy and capture the policy ID | ||||||||||||
|
Contributor
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
Please always include a shebang and set shell options to reduce risk of them continuing erroneously. |
||||||||||||
| POLICY_RESPONSE=$(az rest --method POST \ | ||||||||||||
| --url "https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies" \ | ||||||||||||
| --headers "Content-Type=application/json" \ | ||||||||||||
| --body '{ | ||||||||||||
| "definition": ["{\"TokenLifetimePolicy\":{\"Version\":1,\"AccessTokenLifetime\":\"04:00:00\"}}"], | ||||||||||||
| "displayName": "ExtendedAccessTokenPolicy", | ||||||||||||
| "isOrganizationDefault": false | ||||||||||||
| }') | ||||||||||||
|
|
||||||||||||
| # 2. Extract policy ID and get application ID | ||||||||||||
| POLICY_ID=$(echo $POLICY_RESPONSE | jq -r '.id') | ||||||||||||
| APP_ID=$(az ad app list --display-name "mz-self-managed-github-actions" --query "[0].id" -o tsv) | ||||||||||||
|
|
||||||||||||
| echo "Policy ID: $POLICY_ID" | ||||||||||||
| echo "Application ID: $APP_ID" | ||||||||||||
|
|
||||||||||||
| # 3. Assign policy to application | ||||||||||||
| az rest --method POST \ | ||||||||||||
| --url "https://graph.microsoft.com/v1.0/applications/${APP_ID}/tokenLifetimePolicies/\$ref" \ | ||||||||||||
| --headers "Content-Type=application/json" \ | ||||||||||||
| --body "{\"@odata.id\": \"https://graph.microsoft.com/v1.0/policies/tokenLifetimePolicies/${POLICY_ID}\"}" | ||||||||||||
|
|
||||||||||||
| echo "✅ Token lifetime policy applied successfully!" | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| terraform { | ||
| backend "s3" { | ||
| bucket = "materialize-terraform-self-managed-state" | ||
| key = "github-setup/oidc/azure/terraform.tfstate" | ||
| region = "us-east-1" | ||
| encrypt = true | ||
| # profile = "" # Add your profile name here since backend block doesn't accept variables | ||
| } | ||
| } |
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.
CC @jasonhernandez