Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gatekeeper S3 Example API Upgrade #209

Merged
merged 18 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions examples/gatekeeper/duplicate-s3/samples/allowed-bucket.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
apiVersion: s3.aws.crossplane.io/v1beta1
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
annotations:
crossplane.io/external-create-pending: "2023-06-15T21:17:04Z"
crossplane.io/external-create-succeeded: "2023-06-15T21:17:05Z"
crossplane.io/external-name: my-bucket-456-$ACCOUNT_ID
upbound.io/external-create-pending: "2023-06-15T21:17:04Z"
upbound.io/external-create-succeeded: "2023-06-15T21:17:05Z"
upbound.io/external-name: my-bucket-456-$ACCOUNT_ID
labels:
crossplane.io/claim-name: standard-object-storage
crossplane.io/claim-namespace: default
crossplane.io/composite: standard-object-storage-xwghv
upbound.io/claim-name: standard-object-storage
upbound.io/claim-namespace: default
upbound.io/composite: standard-object-storage-xwghv
name: standard-object-storage-new
spec:
deletionPolicy: Delete
forProvider:
locationConstraint: us-west-2
objectOwnership: BucketOwnerEnforced
paymentConfiguration:
payer: BucketOwner
publicAccessBlockConfiguration:
blockPublicAcls: true
blockPublicPolicy: true
ignorePublicAcls: true
restrictPublicBuckets: true
region: us-west-2
providerConfigRef:
name: aws-provider-config
2 changes: 1 addition & 1 deletion examples/gatekeeper/duplicate-s3/samples/constraint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
kinds:
- apiGroups: ["awsblueprints.io"]
kinds: ["ObjectStorage"]
- apiGroups: ["s3.aws.crossplane.io"]
- apiGroups: ["s3.aws.upbound.io"]
kinds: ["Bucket"]
24 changes: 8 additions & 16 deletions examples/gatekeeper/duplicate-s3/samples/existing-buckets.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
apiVersion: s3.aws.crossplane.io/v1beta1
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
annotations:
crossplane.io/external-create-pending: "2023-06-15T21:17:04Z"
crossplane.io/external-create-succeeded: "2023-06-15T21:17:05Z"
crossplane.io/external-name: my-bucket-123-$ACCOUNT_ID
upbound.io/external-create-pending: "2023-06-15T21:17:04Z"
upbound.io/external-create-succeeded: "2023-06-15T21:17:05Z"
upbound.io/external-name: my-bucket-123-$ACCOUNT_ID
labels:
crossplane.io/claim-name: standard-object-storage
crossplane.io/claim-namespace: default
crossplane.io/composite: standard-object-storage-xwghv
upbound.io/claim-name: standard-object-storage
upbound.io/claim-namespace: default
upbound.io/composite: standard-object-storage-xwghv
name: standard-object-storage-exist
spec:
deletionPolicy: Delete
forProvider:
locationConstraint: us-west-2
objectOwnership: BucketOwnerEnforced
paymentConfiguration:
payer: BucketOwner
publicAccessBlockConfiguration:
blockPublicAcls: true
blockPublicPolicy: true
ignorePublicAcls: true
restrictPublicBuckets: true
region: us-west-2
providerConfigRef:
name: aws-provider-config
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
apiVersion: s3.aws.crossplane.io/v1beta1
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
annotations:
crossplane.io/external-create-pending: "2023-06-15T21:17:04Z"
crossplane.io/external-create-succeeded: "2023-06-15T21:17:05Z"
crossplane.io/external-name: my-bucket-123-$ACCOUNT_ID
upbound.io/external-create-pending: "2023-06-15T21:17:04Z"
upbound.io/external-create-succeeded: "2023-06-15T21:17:05Z"
upbound.io/external-name: my-bucket-123-$ACCOUNT_ID
labels:
crossplane.io/claim-name: standard-object-storage
crossplane.io/claim-namespace: default
crossplane.io/composite: standard-object-storage-xwghv
upbound.io/claim-name: standard-object-storage
upbound.io/claim-namespace: default
upbound.io/composite: standard-object-storage-xwghv
name: standard-object-storage-new
spec:
deletionPolicy: Delete
forProvider:
locationConstraint: us-west-2
objectOwnership: BucketOwnerEnforced
paymentConfiguration:
payer: BucketOwner
publicAccessBlockConfiguration:
blockPublicAcls: true
blockPublicPolicy: true
ignorePublicAcls: true
restrictPublicBuckets: true
region: us-west-2
providerConfigRef:
name: aws-provider-config
2 changes: 1 addition & 1 deletion examples/gatekeeper/duplicate-s3/syncset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ metadata:
name: s3-syncset
spec:
gvks:
- group: "s3.aws.crossplane.io"
- group: "s3.aws.upbound.io"
version: "v1beta1"
kind: "Bucket"
14 changes: 7 additions & 7 deletions examples/gatekeeper/duplicate-s3/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ spec:
#}

sameClaim(obj, review) {
obj.metadata.labels["crossplane.io/claim-namespace"] == review.object.metadata.namespace
obj.metadata.labels["crossplane.io/claim-name"] == review.object.metadata.name
obj.metadata.labels["upbound.io/claim-namespace"] == review.object.metadata.namespace
obj.metadata.labels["upbound.io/claim-name"] == review.object.metadata.name
}

sameBucketMR(obj, review) {
Expand All @@ -32,12 +32,12 @@ spec:
violation[{"msg": msg}] {
review := input.review
review.object.kind == "ObjectStorage"
obj := data.inventory.cluster["s3.aws.crossplane.io/v1beta1"].Bucket[_]
obj := data.inventory.cluster["s3.aws.upbound.io/v1beta1"].Bucket[_]
not sameClaim(obj, review)
claimName := review.object.metadata.name
claimNameSpace := review.object.metadata.namespace
bucket := review.object.spec.resourceConfig.name
bucket == obj.metadata.annotations["crossplane.io/external-name"]
bucket == obj.metadata.annotations["upbound.io/external-name"]

msg := sprintf(
"Claim %v in namespace %v requesting Bucket %v is already managed by Bucket MR %v",
Expand All @@ -48,10 +48,10 @@ spec:
violation[{"msg": msg}] {
review := input.review
review.object.kind == "Bucket"
obj := data.inventory.cluster["s3.aws.crossplane.io/v1beta1"].Bucket[_]
obj := data.inventory.cluster["s3.aws.upbound.io/v1beta1"].Bucket[_]
not sameBucketMR(obj, review)
newBucket := review.object.metadata.annotations["crossplane.io/external-name"]
existingBucket := obj.metadata.annotations["crossplane.io/external-name"]
newBucket := review.object.metadata.annotations["upbound.io/external-name"]
existingBucket := obj.metadata.annotations["upbound.io/external-name"]
newBucket == existingBucket

msg := sprintf(
Expand Down
Loading