Skip to content

Commit 7ecce10

Browse files
jasonmkbrettstack
authored andcommitted
feat: add support for Permissions Boundary on Function (#782)
1 parent 7cf48bd commit 7ecce10

18 files changed

+191
-11
lines changed

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ coverage>=4.4.0
22
flake8>=3.3.0
33
tox>=2.2.1
44
pytest-cov>=2.4.0
5-
pylint>=1.7.2
5+
pylint>=1.7.2,<2.0
66
pyyaml>=4.2b1
77

88
# Test requirements

samtranslator/model/iam.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class IAMRole(Resource):
99
'AssumeRolePolicyDocument': PropertyType(True, is_type(dict)),
1010
'ManagedPolicyArns': PropertyType(False, is_type(list)),
1111
'Path': PropertyType(False, is_str()),
12-
'Policies': PropertyType(False, is_type(list))
12+
'Policies': PropertyType(False, is_type(list)),
13+
'PermissionsBoundary': PropertyType(False, is_str())
1314
}
1415

1516
runtime_attrs = {

samtranslator/model/s3_utils/uri_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def to_s3_uri(code_dict):
4343
raise TypeError("Code location should be a dictionary")
4444

4545
if version:
46-
uri += "?versionId=" + version
46+
uri += "?versionId=" + version
4747

4848
return uri
4949

samtranslator/model/sam_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class SamFunction(SamResourceMacro):
4242
'VpcConfig': PropertyType(False, is_type(dict)),
4343
'Role': PropertyType(False, is_str()),
4444
'Policies': PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
45+
'PermissionsBoundary': PropertyType(False, is_str()),
4546
'Environment': PropertyType(False, dict_of(is_str(), is_type(dict))),
4647
'Events': PropertyType(False, dict_of(is_str(), is_type(dict))),
4748
'Tags': PropertyType(False, is_type(dict)),
@@ -239,6 +240,7 @@ def _construct_role(self, managed_policy_map):
239240

240241
execution_role.ManagedPolicyArns = list(managed_policy_arns)
241242
execution_role.Policies = policy_documents or None
243+
execution_role.PermissionsBoundary = self.PermissionsBoundary
242244

243245
return execution_role
244246

samtranslator/plugins/globals/globals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class Globals(object):
2929
"KmsKeyArn",
3030
"AutoPublishAlias",
3131
"Layers",
32-
"DeploymentPreference"
32+
"DeploymentPreference",
33+
"PermissionsBoundary"
3334
],
3435

3536
# Everything except

samtranslator/translator/translator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def translate(self, sam_template, parameter_values):
110110
if 'Transform' in template:
111111
del template['Transform']
112112

113-
if len(document_errors) is 0:
113+
if len(document_errors) == 0:
114114
template = intrinsics_resolver.resolve_sam_resource_id_refs(template, changed_logical_ids)
115115
template = intrinsics_resolver.resolve_sam_resource_refs(template, supported_resource_refs)
116116
return template
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Resources:
2+
MinimalFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/hello.zip
6+
Handler: hello.handler
7+
Runtime: python2.7
8+
PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary
9+

tests/translator/input/globals_for_function.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Globals:
1616
tag1: value1
1717
Tracing: Active
1818
AutoPublishAlias: live
19+
PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary
1920
Layers:
2021
- !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer:1
2122

@@ -41,6 +42,7 @@ Resources:
4142
newtag1: newvalue1
4243
Tracing: PassThrough
4344
AutoPublishAlias: prod
45+
PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary
4446
Layers:
4547
- !Sub arn:${AWS:Partition}:lambda:${AWS:Region}:${AWS:AccountId}:layer:MyLayer2:2
4648

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"Resources": {
3+
"MinimalFunctionRole": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"ManagedPolicyArns": [
7+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
8+
],
9+
"PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary",
10+
"AssumeRolePolicyDocument": {
11+
"Version": "2012-10-17",
12+
"Statement": [
13+
{
14+
"Action": [
15+
"sts:AssumeRole"
16+
],
17+
"Effect": "Allow",
18+
"Principal": {
19+
"Service": [
20+
"lambda.amazonaws.com"
21+
]
22+
}
23+
}
24+
]
25+
}
26+
}
27+
},
28+
"MinimalFunction": {
29+
"Type": "AWS::Lambda::Function",
30+
"Properties": {
31+
"Handler": "hello.handler",
32+
"Code": {
33+
"S3Bucket": "sam-demo-bucket",
34+
"S3Key": "hello.zip"
35+
},
36+
"Role": {
37+
"Fn::GetAtt": [
38+
"MinimalFunctionRole",
39+
"Arn"
40+
]
41+
},
42+
"Runtime": "python2.7",
43+
"Tags": [
44+
{
45+
"Value": "SAM",
46+
"Key": "lambda:createdBy"
47+
}
48+
]
49+
}
50+
}
51+
}
52+
}

tests/translator/output/aws-cn/globals_for_function.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
88
"arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess"
99
],
10+
"PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary",
1011
"AssumeRolePolicyDocument": {
1112
"Version": "2012-10-17",
1213
"Statement": [
@@ -85,6 +86,7 @@
8586
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
8687
"arn:aws-cn:iam::aws:policy/AWSXrayWriteOnlyAccess"
8788
],
89+
"PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary",
8890
"AssumeRolePolicyDocument": {
8991
"Version": "2012-10-17",
9092
"Statement": [
@@ -198,4 +200,4 @@
198200
}
199201
}
200202
}
201-
}
203+
}

0 commit comments

Comments
 (0)