You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A construct to apply a Permission Boundary, as described in aws/aws-cdk#3242. We've been using the following in projects that need deployment to GCC:
fromtypingimportUnionimportjsiifromaws_cdkimportaws_iam, corefromjsii._reference_mapimport_refsfromjsii._utilsimportSingleton@jsii.implements(core.IAspect)classPermissionBoundaryAspect:
""" This aspect finds all aws_iam.Role objects in a node (ie. CDK stack) and sets permission boundary to the given ARN. https://github.com/aws/aws-cdk/issues/3242#issuecomment-553815373 """def__init__(self, permission_boundary: Union[aws_iam.ManagedPolicy, str]) ->None:
""" :param permission_boundary: Either aws_iam.ManagedPolicy object or managed policy's ARN string """self.permission_boundary=permission_boundarydefvisit(self, construct_ref: core.IConstruct) ->None:
""" construct_ref only contains a string reference to an object. To get the actual object, we need to resolve it using JSII mapping. :param construct_ref: ObjRef object with string reference to the actual object. :return: None """ifisinstance(construct_ref, jsii._kernel.ObjRef) andhasattr(
construct_ref, "ref"
):
kernel=Singleton._instances[
jsii._kernel.Kernel
] # The same object is available as: jsii.kernelresolve=_refs.resolve(kernel, construct_ref)
else:
resolve=construct_refdef_walk(obj):
ifisinstance(obj, aws_iam.Role):
cfn_role=obj.node.find_child("Resource")
policy_arn= (
self.permission_boundaryifisinstance(self.permission_boundary, str)
elseself.permission_boundary.managed_policy_arn
)
cfn_role.add_property_override("PermissionsBoundary", policy_arn)
else:
ifhasattr(obj, "permissions_node"):
forcinobj.permissions_node.children:
_walk(c)
ifhasattr(obj, "node") andobj.node.children:
forcinobj.node.children:
_walk(c)
_walk(resolve)
The text was updated successfully, but these errors were encountered:
A construct to apply a Permission Boundary, as described in aws/aws-cdk#3242. We've been using the following in projects that need deployment to GCC:
The text was updated successfully, but these errors were encountered: