Skip to content

Commit 80c851e

Browse files
committed
better validation for invalid Directory Bucket configuration
1 parent eb542a7 commit 80c851e

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

pkg/resource/bucket/hook.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,90 @@ const (
8080

8181
const ErrSyncingPutProperty = "Error syncing property '%s'"
8282

83+
// Returns a terminal error if unsupported fields are detected.
84+
func validateDirectoryBucketSpec(ko *svcapitypes.Bucket) error {
85+
if ko.Spec.Name == nil || !isDirectoryBucketName(*ko.Spec.Name) {
86+
return nil
87+
}
88+
89+
var unsupportedFields []string
90+
91+
if ko.Spec.Accelerate != nil {
92+
unsupportedFields = append(unsupportedFields, "Accelerate")
93+
}
94+
if len(ko.Spec.Analytics) > 0 {
95+
unsupportedFields = append(unsupportedFields, "Analytics")
96+
}
97+
if ko.Spec.ACL != nil {
98+
unsupportedFields = append(unsupportedFields, "ACL")
99+
}
100+
if ko.Spec.GrantFullControl != nil {
101+
unsupportedFields = append(unsupportedFields, "GrantFullControl")
102+
}
103+
if ko.Spec.GrantRead != nil {
104+
unsupportedFields = append(unsupportedFields, "GrantRead")
105+
}
106+
if ko.Spec.GrantReadACP != nil {
107+
unsupportedFields = append(unsupportedFields, "GrantReadACP")
108+
}
109+
if ko.Spec.GrantWrite != nil {
110+
unsupportedFields = append(unsupportedFields, "GrantWrite")
111+
}
112+
if ko.Spec.GrantWriteACP != nil {
113+
unsupportedFields = append(unsupportedFields, "GrantWriteACP")
114+
}
115+
if ko.Spec.CORS != nil {
116+
unsupportedFields = append(unsupportedFields, "CORS")
117+
}
118+
if len(ko.Spec.IntelligentTiering) > 0 {
119+
unsupportedFields = append(unsupportedFields, "IntelligentTiering")
120+
}
121+
if len(ko.Spec.Inventory) > 0 {
122+
unsupportedFields = append(unsupportedFields, "Inventory")
123+
}
124+
if ko.Spec.Lifecycle != nil {
125+
unsupportedFields = append(unsupportedFields, "Lifecycle")
126+
}
127+
if ko.Spec.Logging != nil {
128+
unsupportedFields = append(unsupportedFields, "Logging")
129+
}
130+
if len(ko.Spec.Metrics) > 0 {
131+
unsupportedFields = append(unsupportedFields, "Metrics")
132+
}
133+
if ko.Spec.Notification != nil {
134+
unsupportedFields = append(unsupportedFields, "Notification")
135+
}
136+
if ko.Spec.OwnershipControls != nil {
137+
unsupportedFields = append(unsupportedFields, "OwnershipControls")
138+
}
139+
if ko.Spec.PublicAccessBlock != nil {
140+
unsupportedFields = append(unsupportedFields, "PublicAccessBlock")
141+
}
142+
if ko.Spec.Replication != nil {
143+
unsupportedFields = append(unsupportedFields, "Replication")
144+
}
145+
if ko.Spec.RequestPayment != nil {
146+
unsupportedFields = append(unsupportedFields, "RequestPayment")
147+
}
148+
if ko.Spec.Versioning != nil {
149+
unsupportedFields = append(unsupportedFields, "Versioning")
150+
}
151+
if ko.Spec.Website != nil {
152+
unsupportedFields = append(unsupportedFields, "Website")
153+
}
154+
155+
if len(unsupportedFields) > 0 {
156+
return ackerr.NewTerminalError(fmt.Errorf(
157+
"directory buckets do not support the following fields: %s. "+
158+
"Please modify your bucket specification to valid Directory Bucket configurations. "+
159+
"See https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-express-differences.html",
160+
strings.Join(unsupportedFields, ", "),
161+
))
162+
}
163+
164+
return nil
165+
}
166+
83167
func (rm *resourceManager) createPutFields(
84168
ctx context.Context,
85169
r *resource,
@@ -211,6 +295,11 @@ func (rm *resourceManager) customUpdateBucket(
211295
exit := rlog.Trace("rm.customUpdateBucket")
212296
defer exit(err)
213297

298+
// Validate directory bucket configuration
299+
if err := validateDirectoryBucketSpec(desired.ko); err != nil {
300+
return nil, err
301+
}
302+
214303
// Merge in the information we read from the API call above to the copy of
215304
// the original Kubernetes object we passed to the function
216305
ko := desired.ko.DeepCopy()

templates/hooks/bucket/sdk_create_post_build_request.go.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Validate directory bucket configuration
2+
if err := validateDirectoryBucketSpec(desired.ko); err != nil {
3+
return nil, err
4+
}
15
// Set default region for general-purpose buckets only (not directory buckets)
26
// Directory buckets use Location/Bucket fields instead of LocationConstraint
37
isDirectoryBucket := input.CreateBucketConfiguration != nil &&

0 commit comments

Comments
 (0)