Skip to content

Commit b55fa21

Browse files
authored
Allow Policies to be attached to a Role (#8)
Adds a new `Role.Spec.Policies` field, of type `[]*string` that contains zero or more Policy ARNs that should be attached to the Role. The controller uses custom code in a new `pkg/resource/role/hooks.go` file that evaluates which Policy ARNs to add or remove from a Policy and calls the IAM ListAttachedRolePolicies, AttachRolePolicy and DetachRolePolicy API calls. Signed-off-by: Jay Pipes <[email protected]> Issue aws-controllers-k8s/community#222 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3dc4d73 commit b55fa21

18 files changed

+258
-4
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2021-12-12T13:43:21Z"
2+
build_date: "2021-12-13T15:45:31Z"
33
build_hash: 285d87b66b62fbfb859986ddf74c9f9b6ae743fb
44
go_version: go1.17
55
version: v0.15.2
6-
api_directory_checksum: 2cb2270674b7b11376f9dd8bb8e421f381e929e2
6+
api_directory_checksum: 686100a0137cba404a403f0184c1870ca2cbac47
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.40.2
99
generator_config_info:
10-
file_checksum: 6ada881f79941709582e58538bf5ac4ef6144787
10+
file_checksum: 0a2481b5bcfedf9ae4233187571a15231f48b8aa
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,9 @@ resources:
8888
- from: PermissionsBoundary.PermissionsBoundaryArn
8989
Path:
9090
late_initialize: {}
91+
# In order to support attaching zero or more policies to a role, we use
92+
# custom update code path code that uses the Attach/DetachRolePolicy API
93+
# calls to manage the set of PolicyARNs attached to this Role.
94+
Policies:
95+
custom_field:
96+
list_of: AttachRolePolicyInput.PolicyArn

apis/v1alpha1/role.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/types.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/iam.services.k8s.aws_roles.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ spec:
9797
description: The ARN of the policy that is used to set the permissions
9898
boundary for the role.
9999
type: string
100+
policies:
101+
items:
102+
type: string
103+
type: array
100104
tags:
101105
description: "A list of tags that you want to attach to the new role.
102106
Each tag consists of a key name and an associated value. For more

config/iam/recommended-inline-policy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
"iam:UpdateRole".
1212
"iam:GetPolicy",
1313
"iam:CreatePolicy",
14-
"iam:DeletePolicy"
14+
"iam:DeletePolicy",
15+
"iam:ListAttachedRolePolicies",
16+
"iam:AttachRolePolicy",
17+
"iam:DetachRolePolicy"
1518
],
1619
"Resource": "*"
1720
}

generator.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ resources:
5757
late_initialize: {}
5858
Role:
5959
hooks:
60+
sdk_read_one_post_set_output:
61+
template_path: hooks/role/sdk_read_one_post_set_output.go.tpl
6062
sdk_create_post_set_output:
6163
template_path: hooks/role/sdk_create_post_set_output.go.tpl
6264
sdk_update_post_set_output:
@@ -88,3 +90,9 @@ resources:
8890
- from: PermissionsBoundary.PermissionsBoundaryArn
8991
Path:
9092
late_initialize: {}
93+
# In order to support attaching zero or more policies to a role, we use
94+
# custom update code path code that uses the Attach/DetachRolePolicy API
95+
# calls to manage the set of PolicyARNs attached to this Role.
96+
Policies:
97+
custom_field:
98+
list_of: AttachRolePolicyInput.PolicyArn

helm/crds/iam.services.k8s.aws_roles.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ spec:
9797
description: The ARN of the policy that is used to set the permissions
9898
boundary for the role.
9999
type: string
100+
policies:
101+
items:
102+
properties:
103+
policyARN:
104+
description: "The Amazon Resource Name (ARN). ARNs are unique
105+
identifiers for Amazon Web Services resources. \n For more
106+
information about ARNs, go to Amazon Resource Names (ARNs)
107+
(https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)
108+
in the Amazon Web Services General Reference."
109+
type: string
110+
roleName:
111+
type: string
112+
type: object
113+
type: array
100114
tags:
101115
description: "A list of tags that you want to attach to the new role.
102116
Each tag consists of a key name and an associated value. For more

pkg/resource/role/delta.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)