Skip to content

Commit 8c2b466

Browse files
authored
add support for updating policy (#21)
The IAM Policy resource does not support direct updates. If you want to modify the policy's Document, you need to call the `CreatePolicyVersion` API call and set the new policy version as the policy's DefaultVersionID. Fairly straightforward, as far as non-updateable resources go. The trick with IAM Policies is that you cannot have more than 5 policy versions associated with a user-managed Policy. This means that if you attempt to make more than 4 calls to `CreatePolicyVersion`, you will get errors back from IAM. So, instead, you must call `DeletePolicyVersion` and delete one of the previous policy versions (not the one set as the default, though). Similarly, when attempting to delete a Policy, if there is more than a single PolicyVersion associated with the Policy, you must first delete all policy versions *except* the one that is the policy's DefaultVersion before calling `DeletePolicy`, which is the only way to delete the policy version that is the default for a policy. This patch adds support for the above update and delete code paths, combining all of the various calls to `ListPolicyVersions`, `GetPolicyVersion` (to get the policy's Document), `CreatePolicyVersion`, and `DeletePolicyVersion` APIs to make an IAM Policy resource behave in a "normal Kubernetes way" -- in other words, the Kubernetes user simply changes the desired state of the Policy (including the Policy's `Spec.PolicyDocument` field) and the controller takes care of actuating those changes. Closes Issue: aws-controllers-k8s/community#1124 Signed-off-by: Jay Pipes <[email protected]> By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3c5677a commit 8c2b466

File tree

12 files changed

+438
-44
lines changed

12 files changed

+438
-44
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2022-03-02T19:05:38Z"
3-
build_hash: ade2429bb444ab635916395ea5773d141ba135e1
4-
go_version: go1.17.5
2+
build_date: "2022-03-21T17:58:09Z"
3+
build_hash: 0b5dc38297ec74d54da4dd326a3988dc3de68b78
4+
go_version: go1.17
55
version: v0.17.2
66
api_directory_checksum: 7d8d584cdaec82ab61d867fc030cb9bb45ac706f
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.42.0
99
generator_config_info:
10-
file_checksum: 72469db1ef2738db804a8c42687c20305eadc2c1
10+
file_checksum: adee4dfc3bba2124bb0b30542295e33fa5387f20
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ resources:
3030
hooks:
3131
sdk_read_one_post_set_output:
3232
template_path: hooks/policy/sdk_read_one_post_set_output.go.tpl
33-
sdk_create_post_set_output:
34-
template_path: hooks/policy/sdk_create_post_set_output.go.tpl
33+
sdk_delete_pre_build_request:
34+
template_path: hooks/policy/sdk_delete_pre_build_request.go.tpl
3535
update_operation:
3636
# There is no `UpdatePolicy` API operation. The only way to update a
3737
# policy is to update the properties individually (only a few properties

config/controller/deployment.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ spec:
2828
args:
2929
- --aws-region
3030
- "$(AWS_REGION)"
31+
- --aws-endpoint-url
32+
- "$(AWS_ENDPOINT_URL)"
3133
- --enable-development-logging
3234
- "$(ACK_ENABLE_DEVELOPMENT_LOGGING)"
3335
- --log-level
@@ -53,6 +55,18 @@ spec:
5355
valueFrom:
5456
fieldRef:
5557
fieldPath: metadata.namespace
58+
- name: AWS_REGION
59+
value: ""
60+
- name: AWS_ENDPOINT_URL
61+
value: ""
62+
- name: ACK_WATCH_NAMESPACE
63+
value: ""
64+
- name: ACK_ENABLE_DEVELOPMENT_LOGGING
65+
value: "false"
66+
- name: ACK_LOG_LEVEL
67+
value: "info"
68+
- name: ACK_RESOURCE_TAGS
69+
value: "services.k8s.aws/managed=true,services.k8s.aws/created=%UTCNOW%,services.k8s.aws/namespace=%KUBERNETES_NAMESPACE%"
5670
securityContext:
5771
allowPrivilegeEscalation: false
5872
privileged: false

config/iam/recommended-inline-policy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
"iam:GetPolicy",
1313
"iam:CreatePolicy",
1414
"iam:DeletePolicy",
15+
"iam:GetPolicyVersion",
16+
"iam:CreatePolicyVersion",
17+
"iam:DeletePolicyVersion",
18+
"iam:ListPolicyVersions",
1519
"iam:ListAttachedRolePolicies",
1620
"iam:AttachRolePolicy",
1721
"iam:DetachRolePolicy",
1822
"iam:ListRoleTags",
23+
"iam:TagPolicy",
24+
"iam:UntagPolicy",
1925
"iam:TagRole",
2026
"iam:UntagRole"
2127
],

generator.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ resources:
3030
hooks:
3131
sdk_read_one_post_set_output:
3232
template_path: hooks/policy/sdk_read_one_post_set_output.go.tpl
33-
sdk_create_post_set_output:
34-
template_path: hooks/policy/sdk_create_post_set_output.go.tpl
33+
sdk_delete_pre_build_request:
34+
template_path: hooks/policy/sdk_delete_pre_build_request.go.tpl
3535
update_operation:
3636
# There is no `UpdatePolicy` API operation. The only way to update a
3737
# policy is to update the properties individually (only a few properties

0 commit comments

Comments
 (0)