File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ help: ## This help message
44 @grep -E --no-filename ' ^[a-zA-Z-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-42s\033[0m %s\n", $$1, $$2}'
55
66.PHONY : Install
7- install : # # Run NPM install
7+ install : # # Run NPM install
88 cd ./infrastructure && npm install
99
1010# Formatting
@@ -33,3 +33,23 @@ init-bootstrap: ## Run Bootstrap terraform
3333.PHONY : apply-bootstrap
3434apply-bootstrap : # # Apply Bootstrap terraform
3535 cd ./bootstrap && terraform apply
36+
37+
38+ # Export current github role permissions
39+ # Pass in an aliases variable containing account IDs you need to mask.
40+ # e.g. make export-dev-github-role aliases="123456789012=account 555555555555=other_account"
41+ .PHONY : export-dev-github-role
42+ export-dev-github-role :
43+ python ./scripts/export_role_policies.py dev github-actions-dev-role ${aliases}
44+
45+ .PHONY : export-pre-prod-github-role
46+ export-pre-prod-github-role :
47+ python ./scripts/export_role_policies.py pre-prod Github-Actions-pre-prod-role ${aliases}
48+
49+ .PHONY : export-prod-github-role
50+ export-prod-github-role :
51+ python ./scripts/export_role_policies.py prod github-access-role ${aliases}
52+
53+ .PHONY : export-test-github-role
54+ export-test-github-role :
55+ python ./scripts/export_role_policies.py test github-action-role ${aliases}
Original file line number Diff line number Diff line change 77Sensitive account IDs can be found/replaced with aliases using the command line arguments.
88The replaced values will be in the format ${alias}.
99
10+ Prerequisite:
11+ You must be logged in to an active SSO session.
12+
1013Usage:
1114 scripts/python export_role_policies.py <environment> <role_name> [<find>=<replace> ...]
1215
2427
2528def list_role_policies (client , role_name : str ) -> list :
2629 inline_policies = []
27- paginator = client .get_paginator ('list_role_policies' )
28- for page in paginator .paginate (RoleName = role_name ):
29- inline_policies .extend (page ['PolicyNames' ])
30+ try :
31+ paginator = client .get_paginator ('list_role_policies' )
32+ for page in paginator .paginate (RoleName = role_name ):
33+ inline_policies .extend (page ['PolicyNames' ])
34+ except client .exceptions .UnauthorizedSSOTokenError as err :
35+ print (f"A valid SSO session is required.\n { err } \n " , file = sys .stderr )
36+ sys .exit (2 )
37+ except client .exceptions .NoSuchEntityException as err :
38+ print (f"{ err } \n Are you using the correct AWS Profile?" , file = sys .stderr )
39+ sys .exit (2 )
3040 return inline_policies
3141
3242
You can’t perform that action at this time.
0 commit comments