-
Notifications
You must be signed in to change notification settings - Fork 42
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
Policies #367
Policies #367
Conversation
Hi @ChiaraOggeri. Thanks for your PR. I am @kingmakerbot.
Make sure this PR appears in the CrownLabs changelog, adding one of the following labels:
|
1d8eaba
to
1e872e0
Compare
871966e
to
4c46914
Compare
54df605
to
d34a9dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thanks @ChiaraOggeri and @sofymunari for this. Looks very interesting to me.
A couple of generic comments (don't know if this PR is already ready for review or not):
- Please, use
opa fmt
to format the rego files. - The rego policy is replicated both in its own file (for testing) and in the gatekeeper constraint. This will soon lead to inconsistencies, since one file is updated and the other not. I would suggest trying to use konstraint to generate the gatekeeper constraints from the base rego policies.
policies/verify-instances-templates-reference/test/rego-rule.rego
Outdated
Show resolved
Hide resolved
apiVersion: templates.gatekeeper.sh/v1beta1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: crownlabsconstraint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: crownlabsconstraint | |
name: crownlabs-instance-template-reference |
I would suggest the same for the CRD name (in the correct case)
337814e
to
1a50b4f
Compare
0a22870
to
7e2d3aa
Compare
8f2ef7d
to
5d8afe7
Compare
58c94ad
to
a4043ba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks in a pretty good shape. A couple of minor additional comments inline.
I just have some concerns about the new policy, but I still have to understand which would be the best solution from the design point of view. We can discuss about that on slack
.github/workflows/test.yml
Outdated
@@ -1,6 +1,6 @@ | |||
name: Code testing | |||
on: | |||
pull_request_target: | |||
pull_request: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to avoid forgetting, this has to be reverted before merging
|
||
# @title crownlabs verify instance template reference | ||
|
||
package crownlabsinstancetemplatereference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package crownlabsinstancetemplatereference | |
package crownlabs_instance_template_reference |
I feel it clearer, in case this modification is possible
|
||
# @title crownlabs verify tenant patch | ||
|
||
package crownlabstenantconstraint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package crownlabstenantconstraint | |
package crownlabs_tenant_constraint |
As before
msg := sprintf("Namespace %v doesn't contain any template", [ns]) | ||
} | ||
|
||
violation[{"msg": msg, "details": {"missing_tempalte": [missing]}}] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
violation[{"msg": msg, "details": {"missing_tempalte": [missing]}}] { | |
violation[{"msg": msg, "details": {"missing_template": [missing]}}] { |
"managedFields": [ | ||
{ | ||
"operation": "Update", | ||
"time": "2020-12-20T11:14:59Z", | ||
"apiVersion": "crownlabs.polito.it/v1alpha1", | ||
"fieldsType": "FieldsV1", | ||
"fieldsV1": {"f:spec": {".": {}, "f:ID": {}, "f:createSandbox": {}, "f:name": {}, "f:publicKeys": {}, "f:surname": {}, "f:workspaces": {}}}, "manager": "kubectl-create", | ||
}, | ||
{ | ||
"fieldsType": "FieldsV1", "fieldsV1": {"f:spec": {"f:email": {}}}, | ||
"manager": "kubectl-patch", | ||
"operation": "Update", | ||
"time": "2020-12-20T11:30:12Z", | ||
"apiVersion": "crownlabs.polito.it/v1alpha1", | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the managedFields, to shorten this file. The same for all occurrences
## TESTS | ||
Tests are available in folder [policies](./policies). | ||
|
||
## HOW TO RUN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## HOW TO RUN | |
## HOW TO DEPLOY |
fc29a21
to
a0d2eb4
Compare
Co-authored-by: Sofia Munari <sofymunari@gmail.com>
13624dc
to
f0c2875
Compare
/merge |
Your staging environment has been correctly teared-down! |
Description
Created a policies folder that contains a OPA policy to verify the correct creation (or update) of a new instance.
In particular it checks if the instance referres to an existing template in the correct namespace.
Fixes # (issue)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also note any relevant details for your test configuration.