-
Notifications
You must be signed in to change notification settings - Fork 321
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
ci: testing with cel policies #519
Merged
Merged
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c1b9241
testing with cel policies
JaydipGabani aa12045
--set enableK8sNativeValidation=false for rego engine
JaydipGabani 67b246f
fixing uploading artifacts in ci
JaydipGabani 1a4e6d1
removing blank line
JaydipGabani 120407b
adding engine rego
JaydipGabani be18548
adding engine rego
JaydipGabani bf316d9
correcting required label cel policy
JaydipGabani d560171
Merge branch 'master' into CEL-source
JaydipGabani 45e9b6a
removing CEL from policies
JaydipGabani f7b47b8
Using sed to modify gk.yml
JaydipGabani 18cd62a
adding required label policy and fixing deployment for gk
JaydipGabani a965f5a
fixing ci
JaydipGabani fbd06cc
adding not allowed label value example for required label policy
JaydipGabani 960614d
testing cel with 3.16+
JaydipGabani ad3ab1d
changing required label cel
JaydipGabani 77fc249
only testing rego for 3.15
JaydipGabani 58a9b57
fixing ci
JaydipGabani 466d8eb
fixing ci
JaydipGabani b9ab792
fixing examples
JaydipGabani f8a4a7e
fixing CEL code
JaydipGabani f07d100
fixing ci
JaydipGabani 823c3bb
fixing ci
JaydipGabani 6d917f7
Merge branch 'master' into CEL-source
JaydipGabani a4dce92
merging with master
JaydipGabani 89a2df0
merging in master and testing with gk 3.16.1
JaydipGabani 6fe0ef2
testing with gk 3.16.1
JaydipGabani bfb2e89
testing with gk 3.16.2
JaydipGabani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
artifacthub/library/general/requiredlabels/1.0.2/artifacthub-pkg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 1.0.2 | ||
name: k8srequiredlabels | ||
displayName: Required Labels | ||
createdAt: "2024-05-02T19:01:02Z" | ||
description: Requires resources to contain specified labels, with values matching provided regular expressions. | ||
digest: e41978589a21f07237a098331543f99ede07098acac8d80a4d44cc050a1ad618 | ||
license: Apache-2.0 | ||
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/requiredlabels | ||
keywords: | ||
- gatekeeper | ||
- open-policy-agent | ||
- policies | ||
readme: |- | ||
# Required Labels | ||
Requires resources to contain specified labels, with values matching provided regular expressions. | ||
install: |- | ||
### Usage | ||
```shell | ||
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/general/requiredlabels/1.0.2/template.yaml | ||
``` | ||
provider: | ||
name: Gatekeeper Library |
2 changes: 2 additions & 0 deletions
2
artifacthub/library/general/requiredlabels/1.0.2/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- template.yaml |
14 changes: 14 additions & 0 deletions
14
artifacthub/library/general/requiredlabels/1.0.2/samples/all-must-have-owner/constraint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: K8sRequiredLabels | ||
metadata: | ||
name: all-must-have-owner | ||
spec: | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Namespace"] | ||
parameters: | ||
message: "All namespaces must have an `owner` label that points to your company username" | ||
labels: | ||
- key: owner | ||
allowedRegex: "^[a-zA-Z]+.agilebank.demo$" |
6 changes: 6 additions & 0 deletions
6
...hub/library/general/requiredlabels/1.0.2/samples/all-must-have-owner/example_allowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: allowed-namespace | ||
labels: | ||
owner: user.agilebank.demo |
4 changes: 4 additions & 0 deletions
4
.../library/general/requiredlabels/1.0.2/samples/all-must-have-owner/example_disallowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: disallowed-namespace |
17 changes: 17 additions & 0 deletions
17
artifacthub/library/general/requiredlabels/1.0.2/suite.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
kind: Suite | ||
apiVersion: test.gatekeeper.sh/v1alpha1 | ||
metadata: | ||
name: requiredlabels | ||
tests: | ||
- name: must-have-owner | ||
template: template.yaml | ||
constraint: samples/all-must-have-owner/constraint.yaml | ||
cases: | ||
- name: example-allowed | ||
object: samples/all-must-have-owner/example_allowed.yaml | ||
assertions: | ||
- violations: no | ||
- name: example-disallowed | ||
object: samples/all-must-have-owner/example_disallowed.yaml | ||
assertions: | ||
- violations: yes |
76 changes: 76 additions & 0 deletions
76
artifacthub/library/general/requiredlabels/1.0.2/template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
apiVersion: templates.gatekeeper.sh/v1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
name: k8srequiredlabels | ||
annotations: | ||
metadata.gatekeeper.sh/title: "Required Labels" | ||
metadata.gatekeeper.sh/version: 1.0.2 | ||
description: >- | ||
Requires resources to contain specified labels, with values matching | ||
provided regular expressions. | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: K8sRequiredLabels | ||
validation: | ||
openAPIV3Schema: | ||
type: object | ||
properties: | ||
message: | ||
type: string | ||
labels: | ||
type: array | ||
description: >- | ||
A list of labels and values the object must specify. | ||
items: | ||
type: object | ||
properties: | ||
key: | ||
type: string | ||
description: >- | ||
The required label. | ||
allowedRegex: | ||
type: string | ||
description: >- | ||
If specified, a regular expression the annotation's value | ||
must match. The value must contain at least one match for | ||
the regular expression. | ||
targets: | ||
- target: admission.k8s.gatekeeper.sh | ||
code: | ||
- engine: K8sNativeValidation | ||
source: | ||
validations: | ||
- expression: '[object, oldObject].exists(obj, obj != null && has(obj.metadata) && variables.params.labels.all(entry, has(obj.metadata.labels) && entry.key in obj.metadata.labels))' | ||
messageExpression: '"missing required label, requires all of: " + variables.params.labels.map(entry, entry.key).join(", ")' | ||
- expression: '[object, oldObject].exists(obj, obj != null && !variables.params.labels.exists(entry, has(obj.metadata.labels) && entry.key in obj.metadata.labels && !string(obj.metadata.labels[entry.key]).matches(string(entry.allowedRegex))))' | ||
message: "regex mismatch" | ||
rego: | | ||
JaydipGabani marked this conversation as resolved.
Show resolved
Hide resolved
JaydipGabani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
package k8srequiredlabels | ||
|
||
get_message(parameters, _default) := _default { | ||
not parameters.message | ||
} | ||
|
||
get_message(parameters, _) := parameters.message | ||
|
||
violation[{"msg": msg, "details": {"missing_labels": missing}}] { | ||
provided := {label | input.review.object.metadata.labels[label]} | ||
required := {label | label := input.parameters.labels[_].key} | ||
missing := required - provided | ||
count(missing) > 0 | ||
def_msg := sprintf("you must provide labels: %v", [missing]) | ||
msg := get_message(input.parameters, def_msg) | ||
} | ||
|
||
violation[{"msg": msg}] { | ||
value := input.review.object.metadata.labels[key] | ||
expected := input.parameters.labels[_] | ||
expected.key == key | ||
# do not match if allowedRegex is not defined, or is an empty string | ||
expected.allowedRegex != "" | ||
not regex.match(expected.allowedRegex, value) | ||
def_msg := sprintf("Label <%v: %v> does not satisfy allowed regex: %v", [key, value, expected.allowedRegex]) | ||
msg := get_message(input.parameters, def_msg) | ||
} |
22 changes: 22 additions & 0 deletions
22
artifacthub/library/pod-security-policy/allow-privilege-escalation/1.0.2/artifacthub-pkg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: 1.0.2 | ||
name: k8spspallowprivilegeescalationcontainer | ||
displayName: Allow Privilege Escalation in Container | ||
createdAt: "2024-05-02T19:01:02Z" | ||
description: Controls restricting escalation to root privileges. Corresponds to the `allowPrivilegeEscalation` field in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privilege-escalation | ||
digest: 64107d0d609554fcc6740d2a2c45bd5d221c1eedaaaee3a409aec827aa196a64 | ||
license: Apache-2.0 | ||
homeURL: https://open-policy-agent.github.io/gatekeeper-library/website/allow-privilege-escalation | ||
keywords: | ||
- gatekeeper | ||
- open-policy-agent | ||
- policies | ||
readme: |- | ||
# Allow Privilege Escalation in Container | ||
Controls restricting escalation to root privileges. Corresponds to the `allowPrivilegeEscalation` field in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privilege-escalation | ||
install: |- | ||
### Usage | ||
```shell | ||
kubectl apply -f https://raw.githubusercontent.com/open-policy-agent/gatekeeper-library/master/artifacthub/library/pod-security-policy/allow-privilege-escalation/1.0.2/template.yaml | ||
``` | ||
provider: | ||
name: Gatekeeper Library |
2 changes: 2 additions & 0 deletions
2
artifacthub/library/pod-security-policy/allow-privilege-escalation/1.0.2/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- template.yaml |
9 changes: 9 additions & 0 deletions
9
...ivilege-escalation/1.0.2/samples/psp-allow-privilege-escalation-container/constraint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: K8sPSPAllowPrivilegeEscalationContainer | ||
metadata: | ||
name: psp-allow-privilege-escalation-container | ||
spec: | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Pod"] |
12 changes: 12 additions & 0 deletions
12
...calation/1.0.2/samples/psp-allow-privilege-escalation-container/disallowed_ephemeral.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-privilege-escalation-disallowed | ||
labels: | ||
app: nginx-privilege-escalation | ||
spec: | ||
ephemeralContainers: | ||
- name: nginx | ||
image: nginx | ||
securityContext: | ||
allowPrivilegeEscalation: true |
12 changes: 12 additions & 0 deletions
12
...ge-escalation/1.0.2/samples/psp-allow-privilege-escalation-container/example_allowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-privilege-escalation-allowed | ||
labels: | ||
app: nginx-privilege-escalation | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
securityContext: | ||
allowPrivilegeEscalation: false |
12 changes: 12 additions & 0 deletions
12
...escalation/1.0.2/samples/psp-allow-privilege-escalation-container/example_disallowed.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-privilege-escalation-disallowed | ||
labels: | ||
app: nginx-privilege-escalation | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
securityContext: | ||
allowPrivilegeEscalation: true |
17 changes: 17 additions & 0 deletions
17
...w-privilege-escalation/1.0.2/samples/psp-allow-privilege-escalation-container/update.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
kind: AdmissionReview | ||
apiVersion: admission.k8s.io/v1beta1 | ||
request: | ||
operation: "UPDATE" | ||
object: | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-privilege-escalation-disallowed | ||
labels: | ||
app: nginx-privilege-escalation | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx | ||
securityContext: | ||
allowPrivilegeEscalation: true |
25 changes: 25 additions & 0 deletions
25
artifacthub/library/pod-security-policy/allow-privilege-escalation/1.0.2/suite.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
kind: Suite | ||
apiVersion: test.gatekeeper.sh/v1alpha1 | ||
metadata: | ||
name: allow-privilege-escalation | ||
tests: | ||
- name: allow-privilege-escalation | ||
template: template.yaml | ||
constraint: samples/psp-allow-privilege-escalation-container/constraint.yaml | ||
cases: | ||
- name: example-allowed | ||
object: samples/psp-allow-privilege-escalation-container/example_allowed.yaml | ||
assertions: | ||
- violations: no | ||
- name: example-disallowed | ||
object: samples/psp-allow-privilege-escalation-container/example_disallowed.yaml | ||
assertions: | ||
- violations: yes | ||
- name: disallowed-ephemeral | ||
object: samples/psp-allow-privilege-escalation-container/disallowed_ephemeral.yaml | ||
assertions: | ||
- violations: yes | ||
- name: update | ||
object: samples/psp-allow-privilege-escalation-container/update.yaml | ||
assertions: | ||
- violations: no |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why do we prefer to use specific patch versions instead of the latest?
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.
AFAIK, we have always tested with past two release versions. I am fine with testing it with latest, unless others have any objections.
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.
using the branch instead of the tag ensures we are always testing against the latest patch version without having to push a PR to update it.
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.
AFAIK helm can only install specifi version, I am not sure if it can take a branch and install the latest patch on that branch. If we do not use helm, then we would need to use
sed
or something similar to modify the file and set the flag manually.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.
+1 to @JaydipGabani i think this is a better approach now since we previously installed from yaml directly
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.
ah I see. I'm ok with merging this as is. but it would be better to not having to bump the tag all the time. @JaydipGabani you can create an issue to do it as a follow up.
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.
Sure!
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.
I don't think we need to bump the patch version. We'll need to bump the minor version, which is same as today. I am not sure if there's a way we can automate that, but this can be a part of post GK release checklist