File tree Expand file tree Collapse file tree 2 files changed +32
-22
lines changed Expand file tree Collapse file tree 2 files changed +32
-22
lines changed Original file line number Diff line number Diff line change 52
52
runs-on : ubuntu-latest
53
53
permissions :
54
54
id-token : write
55
- outputs :
56
- policy-mismatch : ${{ steps.compare-permissions.outputs.policy_mismatch }}
57
55
steps :
58
56
- name : Checkout code
59
57
uses : actions/checkout@v4
@@ -67,13 +65,15 @@ jobs:
67
65
- name : Compare permissions
68
66
id : compare-permissions
69
67
run : |
70
- ../scripts/validate-github-actions-policy.sh arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json
68
+ source ../scripts/validate-github-actions-policy.sh
69
+ validate_policies arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json
70
+ exit $?
71
71
72
72
update-permissions :
73
73
name : Update permissions
74
74
runs-on : ubuntu-latest
75
75
needs : validate-permissions
76
- if : ( inputs.environment == 'production' || inputs.environment == 'preview') && needs.validate-permissions.outputs.policy-mismatch == 'true '
76
+ if : always() && ( inputs.environment == 'production' || inputs.environment == 'preview') && needs.validate-permissions.result == 'failure '
77
77
environment : ${{ inputs.environment }}
78
78
permissions :
79
79
id-token : write
95
95
name : Terraform plan
96
96
runs-on : ubuntu-latest
97
97
needs : [validate-permissions, update-permissions]
98
- if : always() && (needs.validate-permissions.outputs.policy-mismatch != 'true' || needs.update-permissions.result == 'success')
98
+ if : >
99
+ always() &&
100
+ (
101
+ (inputs.environment != 'production' && inputs.environment != 'preview') ||
102
+ needs.validate-permissions.result == 'success' ||
103
+ needs.update-permissions.result == 'success'
104
+ )
99
105
permissions :
100
106
id-token : write
101
107
steps :
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
- if [ " $# " -ne 2 ]; then
4
- echo " Usage: $0 <policy-arn> <policy-file>"
5
- exit 1
6
- fi
3
+ function validate_policies() {
4
+ exit 1
5
+ if [ " $# " -ne 2 ]; then
6
+ echo " Usage: $0 <policy-arn> <policy-file>"
7
+ exit 1
8
+ fi
7
9
8
- POLICY_ARN=$1
9
- POLICY_FILE=$2
10
+ POLICY_ARN=$1
11
+ POLICY_FILE=$2
10
12
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
+ VERSION_ID=$( aws iam get-policy --policy-arn " $POLICY_ARN " --query ' Policy.DefaultVersionId' --output text)
14
+ aws iam get-policy-version --policy-arn " $POLICY_ARN " --version-id " $VERSION_ID " --query ' PolicyVersion.Document' --output json > deployed_policy.json
13
15
14
- jq -S . deployed_policy.json > deployed_policy_sorted.json
15
- jq -S . " $POLICY_FILE " > github_actions_policy_sorted.json
16
+ jq -S . deployed_policy.json > deployed_policy_sorted.json
17
+ jq -S . " $POLICY_FILE " > github_actions_policy_sorted.json
16
18
17
- POLICY_DIFF=$( diff --unified deployed_policy_sorted.json github_actions_policy_sorted.json)
18
- if [ -n " $POLICY_DIFF " ]; then
19
- echo " Policy mismatch detected: $POLICY_DIFF "
20
- echo " policy_mismatch=true" >> " $GITHUB_OUTPUT "
21
- else
22
- echo " No policy mismatch detected"
23
- fi
19
+ POLICY_DIFF=$( diff --unified deployed_policy_sorted.json github_actions_policy_sorted.json)
20
+ if [ -n " $POLICY_DIFF " ]; then
21
+ echo " Policy mismatch detected: $POLICY_DIFF "
22
+ return 1
23
+ else
24
+ echo " No policy mismatch detected"
25
+ retrun 0
26
+ fi
27
+ }
You can’t perform that action at this time.
0 commit comments