File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6767 - name : Compare permissions
6868 id : compare-permissions
6969 run : |
70- VERSION_ID=$(aws iam get-policy --policy-arn arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources --query 'Policy.DefaultVersionId' --output text)
71- DEPLOYED_POLICY=$(aws iam get-policy-version --policy-arn arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources --version-id $VERSION_ID --query 'PolicyVersion.Document' --output json)
72- echo "fetched deployed policy: $DEPLOYED_POLICY"
73- POLICY_DIFF=$(diff <(echo "$DEPLOYED_POLICY" | jq --sort-keys .) <(jq --sort-keys . ../resources/github_actions_policy.json))
74- echo "Policy diff: $POLICY_DIFF"
75- if [ -n "$POLICY_DIFF" ]; then
76- echo "Policy mismatch detected: $POLICY_DIFF"
77- echo "policy_mismatch=true" >> $GITHUB_OUTPUT
78- else
79- echo "No policy mismatch detected"
80- fi
70+ set -e
71+ ./../scripts/validate-github-actions-policy.sh arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json
8172
8273 update-permissions :
8374 name : Update permissions
@@ -100,13 +91,13 @@ jobs:
10091 - name : Update IAM policy
10192 run : |
10293 set -e
103- ./../scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.aws_role }}:policy/DeployMavisResources ../resources/github_actions_policy.json
94+ ./../scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json
10495
10596 plan :
10697 name : Terraform plan
10798 runs-on : ubuntu-latest
108- needs : update-permissions
109- if : always()
99+ needs : [validate-permissions, update-permissions]
100+ if : needs.update-permissions.result == 'success' || needs.validate-permissions.outputs.policy-mismatch == 'false'
110101 permissions :
111102 id-token : write
112103 steps :
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ if [ " $# " -ne 2 ]; then
4+ echo " Usage: $0 <policy-arn> <policy-file>"
5+ exit 1
6+ fi
7+
8+ POLICY_ARN=$1
9+ POLICY_FILE=$2
10+
11+ VERSION_ID=$( aws iam get-policy --policy-arn " $POLICY_ARN " --query ' Policy.DefaultVersionId' --output text)
12+ aws iam get-policy-version --policy-arn " $POLICY_ARN " --version-id " $VERSION_ID " --query ' PolicyVersion.Document' --output json > deployed_policy.json
13+ echo " fetched deployed policy: $( cat deployed_policy.json) "
14+
15+ jq -S . deployed_policy.json > deployed_policy_sorted.json
16+ jq -S . " $POLICY_FILE " > github_actions_policy_sorted.json
17+
18+ POLICY_DIFF=$( diff --unified deployed_policy_sorted.json github_actions_policy_sorted.json)
19+ echo " Policy diff: $POLICY_DIFF "
20+ if [ -n " $POLICY_DIFF " ]; then
21+ echo " Policy mismatch detected: $POLICY_DIFF "
22+ echo " policy_mismatch=true" >> " $GITHUB_OUTPUT "
23+ else
24+ echo " No policy mismatch detected"
25+ fi
You can’t perform that action at this time.
0 commit comments