Skip to content

Commit

Permalink
S3 irsa tag (#178)
Browse files Browse the repository at this point in the history
* management policies addition

* management policies removal from K8-provider

* load balancer controller addition

* updating policy to access global and local index

* Update dynamodb-write.yaml license

* adding tags

* adding tags object

* adding tags object fix

* adding tags object test

* s3-irsa tag definition correction

* s3-irsa tag parametrized
  • Loading branch information
7navyasa authored Mar 26, 2024
1 parent 8254235 commit 326bfb9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
14 changes: 3 additions & 11 deletions compositions/upbound-aws-provider/s3-irsa/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,9 @@ spec:
region:
type: string
tags:
items:
properties:
key:
type: string
value:
type: string
required:
- key
- value
type: object
type: array
additionalProperties:
type: string
type: object
required:
- providerConfigName
- region
Expand Down
13 changes: 13 additions & 0 deletions examples/gatekeeper/required-tags-s3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Prevent provisioning resources that do not have the required tags

This example covers a Gatekeeper policy that denies requests for provisioning
resources without the required tags

Examples and test cases are available under the `samples` directory.
Tests can be ran using the [gator cli](https://open-policy-agent.github.io/gatekeeper/website/docs/gator/).

To run tests for this example run:
```bash
cd examples/gatekeeper/required-tags/
gator verify . -v
```
11 changes: 11 additions & 0 deletions examples/gatekeeper/required-tags-s3/constraint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: AwsRequiredTags
metadata:
name: awsrequiredtags
spec:
match:
kinds:
- apiGroups: ["*"]
kinds: ["*"]
parameters:
tags: ["owner"]
38 changes: 38 additions & 0 deletions examples/gatekeeper/required-tags-s3/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: templates.gatekeeper.sh/v1
kind: ConstraintTemplate
metadata:
name: awsrequiredtags
spec:
crd:
spec:
names:
kind: AwsRequiredTags
validation:
# Schema for the `parameters` field
openAPIV3Schema:
type: object
properties:
tags:
type: array
items:
type: string
targets:
- target: admission.k8s.gatekeeper.sh
rego: |
package awsrequiredtags
import future.keywords.every
violation[{"msg": msg}] {
endswith(input.review.kind.group, "s3.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])
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ spec:
resourceConfig:
providerConfigName: aws-provider-config
region: us-east-1
{{- with .Values.s3irsa.tags }}
tags:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Default values for checkout.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

s3irsa:
enabled: true
tags:
owner: devops
environment: production

0 comments on commit 326bfb9

Please sign in to comment.