Skip to content

Commit 9b2168d

Browse files
Fix default canned ACL delta false positive (#80)
Fixes aws-controllers-k8s/community#1282 Description of changes: The custom ACL code was giving a false positive on the delta when comparing an empty `Spec.ACL` to the list of default ACL possibilities on a fresh bucket. This was causing the controller to always call `SyncACL`, throwing an error if the spec also defined properties which denied ACL use (such as `ObjectOwnership`). This pull request checks for the case where the `Spec.ACL` is nil and where the bucket has the default grants, and will ignore the delta, preventing the false positive. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 46e9abe commit 9b2168d

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

pkg/resource/bucket/acl_custom.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,25 @@ func formGrantHeader(grants []*svcsdk.Grant) string {
151151
return strings.Join(headers, ",")
152152
}
153153

154+
// isDefaultCannedACLPossibilities determines whether the list of joined ACL
155+
// possibilites is the default for a bucket.
156+
func isDefaultCannedACLPossibilities(joinedPossibilities string) bool {
157+
return matchPossibleCannedACL(CannedACLPrivate, joinedPossibilities) != nil
158+
}
159+
160+
// matchPossibleCannedACL attempts to find a canned ACL string in a joined
161+
// list of possibilities. If any of the possibilities matches, it will be
162+
// returned, otherwise nil.
163+
func matchPossibleCannedACL(search string, joinedPossibilities string) *string {
164+
splitPossibilities := strings.Split(joinedPossibilities, CannedACLJoinDelimiter)
165+
for _, possible := range splitPossibilities {
166+
if search == possible {
167+
return &possible
168+
}
169+
}
170+
return nil
171+
}
172+
154173
// GetHeadersFromGrants will return a list of grant headers from grants
155174
func GetHeadersFromGrants(
156175
resp *svcsdk.GetBucketAclOutput,

pkg/resource/bucket/hook.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ func customPreCompare(
519519
b.ko.Spec.ACL = matchPossibleCannedACL(*a.ko.Spec.ACL, *b.ko.Spec.ACL)
520520
}
521521
} else {
522+
// Ignore diff if possible canned ACLs are the default
523+
if b.ko.Spec.ACL != nil && isDefaultCannedACLPossibilities(*b.ko.Spec.ACL) {
524+
b.ko.Spec.ACL = nil
525+
}
526+
522527
// If we are sure the grants weren't set from the header strings
523528
if a.ko.Spec.GrantFullControl == nil &&
524529
a.ko.Spec.GrantRead == nil &&
@@ -677,19 +682,6 @@ func (rm *resourceManager) setResourceACL(
677682
ko.Spec.ACL = &joinedACLs
678683
}
679684

680-
// matchPossibleCannedACL attempts to find a canned ACL string in a joined
681-
// list of possibilities. If any of the possibilities matches, it will be
682-
// returned, otherwise nil.
683-
func matchPossibleCannedACL(search string, joinedPossibilities string) *string {
684-
splitPossibilities := strings.Split(joinedPossibilities, CannedACLJoinDelimiter)
685-
for _, possible := range splitPossibilities {
686-
if search == possible {
687-
return &possible
688-
}
689-
}
690-
return nil
691-
}
692-
693685
func (rm *resourceManager) newGetBucketACLPayload(
694686
r *resource,
695687
) *svcsdk.GetBucketAclInput {

0 commit comments

Comments
 (0)