Skip to content

Commit 4069100

Browse files
committed
feat(on-approval): trigger on approval
1 parent 96bbcb8 commit 4069100

File tree

6 files changed

+337
-7
lines changed

6 files changed

+337
-7
lines changed

.github/setup/azure/main.tf

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ data "azurerm_client_config" "current" {}
101101
# principal_id = azuread_service_principal.github_actions.object_id
102102
# }
103103

104-
# Facing issues with the custom role definition, so using the built-in Contributor role instead. Figure it out later
104+
# Facing issues with the custom role definition, so using the built-in Contributor role instead. Because I cannot create custom role definitions.
105105
# For resource group creation/management (required by networking fixture)
106106
# Note: No specific "Resource Group Contributor" role exists - using generic Contributor
107107
# resource "azurerm_role_assignment" "github_actions_contributor" {
@@ -130,7 +130,7 @@ data "azurerm_client_config" "current" {}
130130
# ]
131131
# }
132132

133-
# # Assign the custom resource group role
133+
# # Assign the custom resource group role not able to perform this getting authz error
134134
# resource "azurerm_role_assignment" "github_actions_resource_group_manager" {
135135
# scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
136136
# role_definition_id = azurerm_role_definition.resource_group_manager.role_definition_resource_id
@@ -142,3 +142,40 @@ resource "azurerm_role_assignment" "github_actions_contributor" {
142142
role_definition_name = "Contributor"
143143
principal_id = azuread_service_principal.github_actions.object_id
144144
}
145+
146+
# RBAC Administrator role for AKS role assignments
147+
# AKS modules need to assign network roles to managed identities and subnets
148+
# Commented out due to ABAC restrictions - use more specific roles instead
149+
# Maybe make it more restrictive to only assing
150+
# ---> Network Contributor and Storage Blob Data Contributor since we only assign those in az modules
151+
resource "azurerm_role_assignment" "github_actions_rbac_admin" {
152+
scope = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
153+
role_definition_name = "Role Based Access Control Administrator"
154+
principal_id = azuread_service_principal.github_actions.object_id
155+
156+
# ABAC condition to block assignment of high-privilege roles
157+
# Allows assignment of any role EXCEPT: Owner, User Access Administrator, RBAC Administrator
158+
# Role GUIDs: 8e3af657... (Owner), 18d7d88d... (User Access Admin), f58310d9... (RBAC Admin)
159+
condition = <<-EOT
160+
(
161+
(!(ActionMatches{'Microsoft.Authorization/roleAssignments/write'}))
162+
OR
163+
(@Request[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAllValues:GuidNotEquals {
164+
8e3af657-a8ff-443c-a75c-2fe8c4bcb635,
165+
18d7d88d-d35e-4fb5-a5c3-7773c20a72d9,
166+
f58310d9-a9f6-439a-9e8d-f62e7b41a168
167+
})
168+
)
169+
AND
170+
(
171+
(!(ActionMatches{'Microsoft.Authorization/roleAssignments/delete'}))
172+
OR
173+
(@Resource[Microsoft.Authorization/roleAssignments:RoleDefinitionId] ForAnyOfAllValues:GuidNotEquals {
174+
8e3af657-a8ff-443c-a75c-2fe8c4bcb635,
175+
18d7d88d-d35e-4fb5-a5c3-7773c20a72d9,
176+
f58310d9-a9f6-439a-9e8d-f62e7b41a168
177+
})
178+
)
179+
EOT
180+
condition_version = "2.0"
181+
}

.github/workflows/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Infrastructure Testing Workflows
2+
3+
## 🛡️ **Approval-Gated Testing**
4+
5+
Infrastructure tests **require PR approval** to prevent accidental resource provisioning and manage costs.
6+
7+
### **How It Works**
8+
1. **Create PR** → No tests run initially
9+
2. **Get approval** → Tests run automatically
10+
3. **Push changes** → Tests re-run automatically (if PR approved)
11+
4. **Manual trigger** → Use `gh workflow run test-<cloud>.yml` if needed
12+
13+
14+
### **What Gets Tested**
15+
16+
| Path Changes | Tests Triggered |
17+
|-------------|----------------|
18+
| `*/modules/**/*.tf`, `kubernetes/modules/**/*.{tf,yaml,yml}` | ✅ Relevant cloud tests |
19+
| `test/aws/**/*.{go,tf}`, `test/gcp/**/*.{go,tf}`, `test/azure/**/*.{go,tf}` | ✅ Relevant cloud tests |
20+
| `test/utils/**`, `test/shared/**`, `test/*.go` |**All cloud tests** |
21+
| `*/examples/**`, `README.md`, `.env`, docs | ❌ No tests |
22+
23+
### **Features**
24+
-**Granular path filtering** - Only tests infrastructure changes (excludes docs/README)
25+
-**Smart cloud detection** - Tests only affected clouds, or all clouds for shared changes
26+
-**Race condition prevention** - One workflow per PR
27+
-**Parallel cloud testing** - AWS/GCP/Azure run simultaneously
28+
-**Auto-retest** - New pushes trigger tests if PR approved
29+
30+
## **Setup Requirements**
31+
32+
**Repository Secrets:**
33+
```
34+
MATERIALIZE_LICENSE_KEY
35+
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID
36+
GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT_EMAIL
37+
```
38+
39+
**Repository Variables:**
40+
```
41+
GA_AWS_IAM_ROLE
42+
TF_TEST_S3_BUCKET, TF_TEST_S3_REGION, TF_TEST_S3_PREFIX
43+
GOOGLE_PROJECT, AWS_REGION
44+
```
45+
46+
## **Manual Override**
47+
48+
```bash
49+
# Run tests without approval (requires repo access)
50+
gh workflow run test-aws.yml --ref your-branch
51+
gh workflow run test-gcp.yml --ref your-branch
52+
gh workflow run test-azure.yml --ref your-branch
53+
```

.github/workflows/test-aws.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: AWS Tests
22

33
on:
4-
# Manual trigger for testing
4+
# Only run via approval workflow or manual trigger
5+
# Removed pull_request trigger to prevent duplicate runs
6+
workflow_call: # Called by test-on-approval.yml
57
workflow_dispatch:
68
inputs:
79
test_stage:
@@ -25,6 +27,7 @@ jobs:
2527
test-aws:
2628
name: AWS Infrastructure Tests
2729
runs-on: ubuntu-latest
30+
# Note: Approval-gated tests now handled by test-on-approval.yml workflow
2831

2932
steps:
3033
- name: Checkout code

.github/workflows/test-azure.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Azure Tests
22

33
on:
4-
pull_request:
5-
branches: [main]
6-
# Manual trigger for testing
4+
# Only run via approval workflow or manual trigger
5+
# Removed pull_request trigger to prevent duplicate runs
6+
workflow_call: # Called by test-on-approval.yml
77
workflow_dispatch:
88
inputs:
99
test_stage:
@@ -27,6 +27,7 @@ jobs:
2727
test-azure:
2828
name: Azure Infrastructure Tests
2929
runs-on: ubuntu-latest
30+
# Note: Approval-gated tests now handled by test-on-approval.yml workflow
3031

3132
steps:
3233
- name: Checkout code

.github/workflows/test-gcp.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: GCP Tests
22

33
on:
4-
# Manual trigger for testing
4+
# Only run via approval workflow or manual trigger
5+
# Removed pull_request trigger to prevent duplicate runs
6+
workflow_call: # Called by test-on-approval.yml
57
workflow_dispatch:
68
inputs:
79
test_stage:
@@ -25,6 +27,7 @@ jobs:
2527
test-gcp:
2628
name: GCP Infrastructure Tests
2729
runs-on: ubuntu-latest
30+
# Note: Approval-gated tests now handled by test-on-approval.yml workflow
2831

2932
steps:
3033
- name: Checkout code

0 commit comments

Comments
 (0)