-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add example ValidatingAdmissionPolicy to block param interpolat…
…ion. Fixes #5114 Signed-off-by: Mason Malone <[email protected]>
- Loading branch information
Showing
6 changed files
with
129 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# This admission policy (https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/) | ||
# can be used to block workflows that use string interpolation inside the fields "command", | ||
# "args", or "source". | ||
# | ||
# Interpolating untrusted user input into this fields can lead to command | ||
# injection vulnerabilities (https://owasp.org/www-community/attacks/Command_Injection). | ||
# | ||
# This policy will only work when using the full CRDs (https://argo-workflows.readthedocs.io/en/latest/installation/#full-crds). | ||
# You must create a ValidatingAdmissionPolicyBinding to use it. | ||
apiVersion: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicy | ||
metadata: | ||
name: "argo-dangerous-interpolation-vap" | ||
spec: | ||
failurePolicy: Fail | ||
matchConstraints: | ||
resourceRules: | ||
- apiGroups: ["argoproj.io"] | ||
apiVersions: ["v1alpha1"] | ||
operations: ["CREATE", "UPDATE"] | ||
resources: ["workflows"] | ||
validations: | ||
- expression: > | ||
!object.spec.templates.map( | ||
t, has(t.container) | ||
? ( | ||
(has(t.container.command) ? t.container.command : []) | ||
+ | ||
(has(t.container.args) ? t.container.args : []) | ||
) | ||
: ( | ||
has(t.script) | ||
? ( | ||
(has(t.script.command) ? t.script.command : []) | ||
+ | ||
(has(t.script.source) ? [t.script.source] : []) | ||
) | ||
: [] | ||
) | ||
).exists(values, values.exists(value, value.matches('\\{\\{[^\\}]*\\}\\}'))) | ||
message: "Dangerous interpolation detected" |
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
12 changes: 12 additions & 0 deletions
12
test/e2e/functional/argo-dangerous-interpolation-vap-binding.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: admissionregistration.k8s.io/v1 | ||
kind: ValidatingAdmissionPolicyBinding | ||
metadata: | ||
name: "argo-dangerous-interpolation-vap-binding" | ||
namespace: argo | ||
spec: | ||
policyName: "argo-dangerous-interpolation-vap" | ||
validationActions: [Deny] | ||
matchResources: | ||
objectSelector: | ||
matchLabels: | ||
workflows.argoproj.io/test: dangerous-interpolation |
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 @@ | ||
../../../examples/argo-dangerous-interpolation-vap.yaml |