Skip to content

Commit 944e149

Browse files
authored
U-9288 Default the AI SRE role to its restricted setting, and review ReadOnlyAccess v192 (#23)
1 parent c09e32c commit 944e149

21 files changed

Lines changed: 1053 additions & 7763 deletions

‎.github/workflows/ai-sre-read-only-access-drift.yml‎

Lines changed: 0 additions & 79 deletions
This file was deleted.

‎.github/workflows/e2e-ai-sre.yml‎

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
name: "E2E AI SRE"
22

3-
# Deploys cloudformation/ai-sre/better-stack-ai-sre.yaml from the checkout the way a customer does, checks the role it
4-
# makes (name, version tag, description, two-statement trust), asserts every allowed read and every explicit deny with
5-
# IAM's policy simulator (cloudformation/ai-sre/test/simulate_policy.py), updates the stack in place to
6-
# AllowConfigurationValues=false, checks the role kept its ID and runs the simulator again, then deletes the stack.
3+
# The live checks of cloudformation/ai-sre/better-stack-ai-sre.yaml. Run it by hand (Actions, "Run workflow") on the
4+
# branch of any pull request that changes the template, and on main before a release. It does not run on pull
5+
# requests, pushes or a schedule, and a run that cannot deploy fails: it never reports success without deploying.
6+
#
7+
# "AI SRE stack round trip" deploys the template from the checkout the way a customer does, checks the role it makes
8+
# (name, version tag, description, two-statement trust), asserts every allowed read and every explicit deny with
9+
# IAM's policy simulator (cloudformation/ai-sre/test/simulate_policy.py) with the default, AllowConfigurationValues=false,
10+
# updates the stack in place to AllowConfigurationValues=true, checks the role kept its ID and runs the simulator
11+
# again, then deletes the stack.
712
# Nothing assumes the role: it trusts only Better Stack's account.
813
#
9-
# AWS: the job assumes the role in the repository secret AI_SRE_E2E_ROLE_ARN through GitHub OIDC. That role needs
14+
# "Restricted reads against AWS's service reference" needs no AWS account. It fails when a wildcard of the restricted
15+
# role matches an action cloudformation/ai-sre/restricted-reads.txt lacks (AWS added one: review it, then update the
16+
# list) or when an action name in the template matches nothing (see cloudformation/ai-sre/test/check_restricted_reads.py).
17+
#
18+
# AWS: the round trip assumes the role in the repository secret AI_SRE_E2E_ROLE_ARN through GitHub OIDC. That role needs
1019
# cloudformation:CreateStack, UpdateStack, DeleteStack, DescribeStacks, DescribeStackEvents and ListStacks on stacks
1120
# named e2e-ai-sre-*, iam:CreateRole, DeleteRole, GetRole, TagRole, UntagRole, UpdateRoleDescription,
1221
# PutRolePolicy, DeleteRolePolicy, GetRolePolicy, ListRolePolicies, ListAttachedRolePolicies, AttachRolePolicy and
1322
# DetachRolePolicy (for ReadOnlyAccess and the stack's own policies) on roles named better-stack-ai-sre-role-*,
1423
# iam:CreatePolicy, DeletePolicy, GetPolicy, GetPolicyVersion, CreatePolicyVersion, DeletePolicyVersion and
1524
# ListPolicyVersions on policies named better-stack-ai-sre-*, iam:SimulatePrincipalPolicy, and
16-
# cloudformation:ValidateTemplate. Without the secret the
17-
# job skips with a notice. Pull requests from forks are skipped: they get no OIDC token.
25+
# cloudformation:ValidateTemplate. Without the secret the round trip fails.
1826

1927
on:
20-
push:
21-
branches: [main]
22-
paths:
23-
- cloudformation/ai-sre/**
24-
- .github/workflows/e2e-ai-sre.yml
25-
pull_request:
26-
paths:
27-
- cloudformation/ai-sre/**
28-
- .github/workflows/e2e-ai-sre.yml
2928
workflow_dispatch:
3029

3130
permissions:
@@ -45,43 +44,31 @@ env:
4544
jobs:
4645
test:
4746
name: AI SRE stack round trip
48-
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
4947
runs-on: ubuntu-latest
5048
timeout-minutes: 30
5149

5250
steps:
53-
- name: "[Setup] Skip without AWS credentials"
54-
id: aws
51+
- name: "[Setup] The AWS role is configured"
5552
run: |
56-
if [ -z "$AWS_ROLE_ARN" ]; then
57-
echo "::notice::the repository secret AI_SRE_E2E_ROLE_ARN is not set, so the AI SRE stack was not deployed"
58-
echo "enabled=false" >> "$GITHUB_OUTPUT"
59-
else
60-
echo "enabled=true" >> "$GITHUB_OUTPUT"
61-
fi
53+
[ -n "$AWS_ROLE_ARN" ] || { echo "::error::the repository secret AI_SRE_E2E_ROLE_ARN is not set, so the AI SRE stack cannot be deployed"; exit 1; }
6254
6355
- name: "[Setup] Checkout code"
64-
if: ${{ steps.aws.outputs.enabled == 'true' }}
6556
uses: actions/checkout@v7
6657

6758
- uses: actions/setup-python@v7
68-
if: ${{ steps.aws.outputs.enabled == 'true' }}
6959
with:
7060
python-version: '3.12'
7161

7262
- name: "[Setup] Install boto3"
73-
if: ${{ steps.aws.outputs.enabled == 'true' }}
7463
run: pip install boto3
7564

7665
- name: "[Setup] AWS credentials (OIDC)"
77-
if: ${{ steps.aws.outputs.enabled == 'true' }}
7866
uses: aws-actions/configure-aws-credentials@v5
7967
with:
8068
role-to-assume: ${{ env.AWS_ROLE_ARN }}
8169
aws-region: ${{ env.AWS_REGION }}
8270

8371
- name: "[Setup] Stamp the template with the run's version, generate the external ID"
84-
if: ${{ steps.aws.outputs.enabled == 'true' }}
8572
run: |
8673
sed "s/^ Version: 0\.0\.0-dev$/ Version: $RUN_ID/" cloudformation/ai-sre/better-stack-ai-sre.yaml > template.yaml
8774
grep -q "^ Version: $RUN_ID$" template.yaml || { echo "::error::the template has no 'Version: 0.0.0-dev' line to stamp"; exit 1; }
@@ -99,7 +86,6 @@ jobs:
9986
10087
# A cancelled run can leave its stack behind.
10188
- name: "[Setup] Delete stacks left by earlier runs"
102-
if: ${{ steps.aws.outputs.enabled == 'true' }}
10389
run: |
10490
for stack in $(aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE CREATE_FAILED ROLLBACK_COMPLETE ROLLBACK_FAILED UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE UPDATE_ROLLBACK_FAILED DELETE_FAILED \
10591
--query "StackSummaries[?starts_with(StackName, 'e2e-ai-sre-')].StackName" --output text); do
@@ -109,7 +95,6 @@ jobs:
10995
done
11096
11197
- name: "[Test] Deploy the stack with the defaults"
112-
if: ${{ steps.aws.outputs.enabled == 'true' }}
11398
run: |
11499
aws cloudformation create-stack --stack-name "$STACK_NAME" --template-body file://template.yaml --capabilities CAPABILITY_NAMED_IAM \
115100
--parameters "ParameterKey=ExternalId,ParameterValue=$EXTERNAL_ID" "ParameterKey=BetterStackTeam,ParameterValue=E2E test ($RUN_ID)"
@@ -123,7 +108,6 @@ jobs:
123108
echo "deployed $ROLE_ARN"
124109
125110
- name: "[Test] The role has the contract's name, version tag, description and two-statement trust"
126-
if: ${{ steps.aws.outputs.enabled == 'true' }}
127111
run: |
128112
aws iam get-role --role-name "$EXPECTED_ROLE_NAME" --output json > role.json
129113
jq -r '.Role.RoleId' role.json > role-id.txt
@@ -142,16 +126,14 @@ jobs:
142126
|| fail "the trust does not pin the production callers"
143127
echo "role $EXPECTED_ROLE_NAME: version tag, description and trust as expected"
144128
145-
- name: "[Test] Policy simulator, AllowConfigurationValues=true"
146-
if: ${{ steps.aws.outputs.enabled == 'true' }}
147-
run: python3 cloudformation/ai-sre/test/simulate_policy.py --role-arn "$ROLE_ARN" --allow-configuration-values true --region "$AWS_REGION"
129+
- name: "[Test] Policy simulator, AllowConfigurationValues=false (the default)"
130+
run: python3 cloudformation/ai-sre/test/simulate_policy.py --role-arn "$ROLE_ARN" --allow-configuration-values false --region "$AWS_REGION"
148131

149-
- name: "[Test] Update the stack in place to AllowConfigurationValues=false"
150-
if: ${{ steps.aws.outputs.enabled == 'true' }}
132+
- name: "[Test] Update the stack in place to AllowConfigurationValues=true"
151133
run: |
152134
aws cloudformation update-stack --stack-name "$STACK_NAME" --use-previous-template --capabilities CAPABILITY_NAMED_IAM \
153135
--parameters ParameterKey=ExternalId,UsePreviousValue=true ParameterKey=BetterStackTeam,UsePreviousValue=true ParameterKey=BetterStackEnvironment,UsePreviousValue=true \
154-
ParameterKey=PermissionsBoundaryArn,UsePreviousValue=true ParameterKey=AllowConfigurationValues,ParameterValue=false
136+
ParameterKey=PermissionsBoundaryArn,UsePreviousValue=true ParameterKey=AllowConfigurationValues,ParameterValue=true
155137
if ! aws cloudformation wait stack-update-complete --stack-name "$STACK_NAME"; then
156138
echo "::error::stack update failed: $(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query 'Stacks[0].StackStatus' --output text)"
157139
aws cloudformation describe-stack-events --stack-name "$STACK_NAME" --query "StackEvents[?ends_with(ResourceStatus, 'FAILED')].[LogicalResourceId,ResourceStatus,ResourceStatusReason]" --output table
@@ -160,13 +142,30 @@ jobs:
160142
[ "$(aws iam get-role --role-name "$EXPECTED_ROLE_NAME" --query Role.RoleId --output text)" = "$(cat role-id.txt)" ] || { echo "::error::the update replaced the role"; exit 1; }
161143
echo "updated in place, the role kept its ID"
162144
163-
- name: "[Test] Policy simulator, AllowConfigurationValues=false"
164-
if: ${{ steps.aws.outputs.enabled == 'true' }}
165-
run: python3 cloudformation/ai-sre/test/simulate_policy.py --role-arn "$ROLE_ARN" --allow-configuration-values false --region "$AWS_REGION"
145+
- name: "[Test] Policy simulator, AllowConfigurationValues=true"
146+
run: python3 cloudformation/ai-sre/test/simulate_policy.py --role-arn "$ROLE_ARN" --allow-configuration-values true --region "$AWS_REGION"
166147

167148
- name: "[Cleanup] Delete the stack"
168-
if: ${{ always() && steps.aws.outputs.enabled == 'true' && env.STACK_NAME != '' }}
149+
if: ${{ always() && env.STACK_NAME != '' }}
169150
run: |
170151
aws cloudformation delete-stack --stack-name "$STACK_NAME"
171152
aws cloudformation wait stack-delete-complete --stack-name "$STACK_NAME" || { echo "::error::stack $STACK_NAME was not deleted"; exit 1; }
172153
echo "deleted $STACK_NAME"
154+
155+
restricted-reads:
156+
name: Restricted reads against AWS's service reference
157+
runs-on: ubuntu-latest
158+
timeout-minutes: 10
159+
steps:
160+
- uses: actions/checkout@v7
161+
162+
- uses: actions/setup-python@v7
163+
with:
164+
python-version: '3.12'
165+
166+
- name: Install PyYAML
167+
run: pip install pyyaml==6.0.3
168+
169+
- name: The restricted role's wildcards match what restricted-reads.txt records
170+
working-directory: cloudformation/ai-sre/test
171+
run: python check_restricted_reads.py

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ jobs:
5555
working-directory: cloudformation/ai-sre/test
5656
run: python check_contract.py
5757

58-
- name: Test the contract check, the policy simulator script and the ReadOnlyAccess review check
58+
- name: Test the contract check, the policy simulator's expectations and the restricted reads check
5959
working-directory: cloudformation/ai-sre/test
6060
run: python -m unittest -v
61-
62-
# The full drift check needs AWS credentials and runs in ai-sre-read-only-access-drift.yml.
63-
- name: The reviewed ReadOnlyAccess list is well formed and its denied lines are denied
64-
working-directory: cloudformation/ai-sre/test
65-
run: python check_read_only_access_review.py --static

0 commit comments

Comments
 (0)