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 upgrade #208

Merged
merged 15 commits into from
Jun 28, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
apiVersion: dynamodb.aws.crossplane.io/v1alpha1
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
meta.upbound.io/example-id: dynamodb/v1beta1/globaltable
name: sample-table
spec:
deletionPolicy: Delete
providerConfigRef:
name: aws-provider-config
forProvider:
attribute:
- name: myAttribute
type: S
hashKey: myAttribute
readCapacity: 1
writeCapacity: 1
region: eu-west-2
attributeDefinitions:
- attributeName: id
attributeType: S
keySchema:
- attributeName: id
keyType: HASH
billingMode: PROVISIONED
provisionedThroughput:
readCapacityUnits: 1
writeCapacityUnits: 1
tags:
- key: "owner"
value: "finance"
providerConfigRef:
name: aws-provider-config
owner: finance
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
apiVersion: dynamodb.aws.crossplane.io/v1alpha1
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
meta.upbound.io/example-id: dynamodb/v1beta1/globaltable
name: failing-table
spec:
deletionPolicy: Delete
providerConfigRef:
name: aws-provider-config
forProvider:
attribute:
- name: myAttribute
type: S
hashKey: myAttribute
readCapacity: 1
writeCapacity: 1
region: us-east-1
attributeDefinitions:
- attributeName: id
attributeType: S
keySchema:
- attributeName: id
keyType: HASH
billingMode: PROVISIONED
provisionedThroughput:
readCapacityUnits: 1
writeCapacityUnits: 1
tags:
- key: "owner"
value: "finance"

providerConfigRef:
name: aws-provider-config
owner: finance
4 changes: 2 additions & 2 deletions examples/gatekeeper/required-tags/samples/constraint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
spec:
match:
kinds:
- apiGroups: ["*"]
kinds: ["*"]
- apiGroups: ["dynamodb.aws.upbound.io"]
kinds: ["Table"]
parameters:
tags: ["owner"]
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
apiVersion: dynamodb.aws.crossplane.io/v1alpha1
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
meta.upbound.io/example-id: dynamodb/v1beta1/globaltable
name: dummy-table
spec:
deletionPolicy: Delete
providerConfigRef:
name: aws-provider-config
forProvider:
attribute:
- name: myAttribute
type: S
hashKey: myAttribute
readCapacity: 1
writeCapacity: 1
region: eu-west-2
attributeDefinitions:
- attributeName: id
attributeType: S
keySchema:
- attributeName: id
keyType: HASH
billingMode: PROVISIONED
provisionedThroughput:
readCapacityUnits: 1
writeCapacityUnits: 1
tags:
- key: "aaa"
value: "finance"
providerConfigRef:
name: aws-provider-config
aaa: finance
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
apiVersion: dynamodb.aws.crossplane.io/v1alpha1
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
meta.upbound.io/example-id: dynamodb/v1beta1/globaltable
name: dummy-table
spec:
deletionPolicy: Delete
forProvider:
region: eu-west-2
attributeDefinitions:
- attributeName: id
attributeType: S
keySchema:
- attributeName: id
keyType: HASH
billingMode: PROVISIONED
provisionedThroughput:
readCapacityUnits: 1
writeCapacityUnits: 1
providerConfigRef:
name: aws-provider-config
name: aws-provider-config
forProvider:
attribute:
- name: myAttribute
type: S
hashKey: myAttribute
readCapacity: 1
writeCapacity: 1
region: eu-west-2
28 changes: 12 additions & 16 deletions examples/gatekeeper/required-tags/samples/finance-table-pass.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
apiVersion: dynamodb.aws.crossplane.io/v1alpha1
apiVersion: dynamodb.aws.upbound.io/v1beta1
kind: Table
metadata:
annotations:
meta.upbound.io/example-id: dynamodb/v1beta1/globaltable
name: finance-table
spec:
deletionPolicy: Delete
providerConfigRef:
name: aws-provider-config
forProvider:
attribute:
- name: myAttribute
type: S
hashKey: myAttribute
readCapacity: 1
writeCapacity: 1
region: eu-west-2
attributeDefinitions:
- attributeName: id
attributeType: S
keySchema:
- attributeName: id
keyType: HASH
billingMode: PROVISIONED
provisionedThroughput:
readCapacityUnits: 1
writeCapacityUnits: 1
tags:
- key: "owner"
value: "finance"
providerConfigRef:
name: aws-provider-config
owner: finance
19 changes: 5 additions & 14 deletions examples/gatekeeper/required-tags/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ spec:
names:
kind: AwsRequiredTags
validation:
# Schema for the `parameters` field
openAPIV3Schema:
type: object
properties:
Expand All @@ -20,19 +19,11 @@ spec:
- target: admission.k8s.gatekeeper.sh
rego: |
package awsrequiredtags
import future.keywords.every
candonov marked this conversation as resolved.
Show resolved Hide resolved

violation[{"msg": msg}] {
endswith(input.review.kind.group, "aws.crossplane.io")
not startswith(input.review.kind.kind, "ProviderConfig")
not input.review.object.spec.forProvider.tags
msg := sprintf("Attempting to provision a resource without tags, the following tags are required '%v'", [input.parameters.tags])
}

violation[{"msg": msg}] {
some requested_tag in input.parameters.tags
every i in input.review.object.spec.forProvider.tags {
requested_tag != i.key
}
msg := sprintf("Attempting to provision a resource with the following tags '%v', one or more of the required tags '%v' is missing", [input.review.object.spec.forProvider.tags, input.parameters.tags])
input.review.kind.group == "dynamodb.aws.upbound.io"
some i
required_tag := input.parameters.tags[i]
not input.review.object.spec.forProvider.tags[required_tag]
msg := sprintf("Attempting to provision a resource without the required tag '%v'", [required_tag])
}
Loading