Skip to content

Commit 4d8ba9a

Browse files
author
Arik Kfir
committed
Print full IAM policy bindings before updating (for reference).
Since IAM policy bindings are so sensitive, it's imperative that the user has full knowledge of what happened, and how to revert. This is a step in this direction, by printing the IAM policy before & after the update.
1 parent fbf86d7 commit 4d8ba9a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

resources/src/external_services.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,15 @@ def get_project_iam_policy(self, project_id: str):
227227
return service.projects().getIamPolicy(resource=project_id, body={}).execute()
228228

229229
def update_project_iam_policy(self, project_id: str, etag: str, bindings: Sequence[dict], verbose: bool = False):
230-
if verbose:
231-
print(f"Updating IAM policy for '{project_id}', using ETag '{etag}', to the following bindings:\n"
232-
f"{pformat(bindings)}",
233-
file=sys.stderr)
230+
existing_policy: dict = self.get_project_iam_policy(project_id=project_id)
231+
print(f"About to update IAM policy for project '{project_id}'.\n"
232+
f"For reference, due to the sensitivity of this operation, here is the current IAM policy bindings:\n"
233+
f"\n"
234+
f"{pformat(existing_policy['bindings'])}\n"
235+
f"\n"
236+
f"The new IAM policy bindings will be:\n"
237+
f"{pformat(bindings)}")
238+
234239
service = self._get_gcp_service('cloudresourcemanager', 'v1')
235240
service.projects().setIamPolicy(resource=project_id, body={
236241
'policy': {

resources/src/gcp_iam_policy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def update_policy(self, args):
107107

108108
self.svc.update_project_iam_policy(project_id=self.info.config['project_id'],
109109
etag=args.etag,
110-
bindings=final_bindings)
110+
bindings=final_bindings,
111+
verbose=self.info.verbose)
111112

112113

113114
def main():

0 commit comments

Comments
 (0)