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

docs: add example ValidatingAdmissionPolicy to block param interpolation #14045

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

MasonM
Copy link
Contributor

@MasonM MasonM commented Jan 2, 2025

Partial fix for #5114. After this is merged, I'll update Workflow Variables and Security to add warnings about this. Also, I'll fix the examples currently using interpolation in a shell script to stop doing so, since we shouldn't encourage this practice.

Motivation

As @crenshaw-dev explained in #5114, allowing string interpolation inside the command, args, and source fields can be dangerous in the presence of user input, since it can lead to command injection vulnerabilities. These vulnerabilities are ubiquitous with GitHub Actions, and barely a month goes by before another high-profile open-source project gets compromised (example).

For security-conscious organization, providing options to prevent these kind of vulnerabilities is important and would go a long way to distinguishing Argo Workflows from the competition in the CI space.

Modifications

@crenshaw-dev suggested adding a controller option to disable interpolation. That works and would be fairly easy to implement, but the problem is flexibility. It's likely some organizations would want to narrowly target the option, or provide an allowlist that bypasses validation, which is difficult to do with custom logic.

Validating admission policies are a new feature in Kubernetes v1.30 that allows highly flexible, in-process validation logic using CEL. The downside is the CRD needs to specify all fields that are being validated, which necessitates the changes in #14044.

This PR adds an example ValidatingAdmissionPolicy that rejects workflows that interpolate parameters in the command, args, and/or source fields. Initially, I included it in the release manifests under manifests/quick-start/, but then I realized we still support Kubernetes v1.29, which requires enabling a feature gate to use validating admission policies. Once we drop support for v1.29, then I think we should include this in the release manifests.

Initially, I added some automated tests for this, but it was getting a bit messy, so I entered #14094 to refactor how we handle testing examples.

Verification

Ran examples locally:

$ kubectl apply --server-side -f examples/validating-admission-policies/argo-dangerous-interpolation-vap.yaml 
validatingadmissionpolicy.admissionregistration.k8s.io/argo-dangerous-interpolation-vap serverside-applied

$ kubectl apply --server-side -f examples/validating-admission-policies/argo-dangerous-interpolation-vap
-binding.yaml 
validatingadmissionpolicybinding.admissionregistration.k8s.io/argo-dangerous-interpolation-vap-binding serverside-applied

$ kubectl create -f examples/validating-admission-policies/rejected-workflow.yaml 
The workflows "rejected-workflow-fvj4h" is invalid: : ValidatingAdmissionPolicy 'argo-dangerous-interpolation-vap' with binding 'argo-dangerous-interpolation-vap-binding' denied request: Dangerous interpolation detected

MasonM added a commit to MasonM/argo-workflows that referenced this pull request Jan 17, 2025
This rewrites `hack/test-examples.sh` in Go to make those tests easier
to debug and facilitate testing more complex scenarios, like the VAP
added in argoproj#14045

The new tests do strict validation, which caught a bug in
`examples/webhdfs-input-output-artifacts.yaml`:
```
$ kubectl apply -f examples/webhdfs-input-output-artifacts.yaml
Error from server (BadRequest): error when creating "examples/webhdfs-input-output-artifacts.yaml": Workflow in version "v1alpha1" cannot be handled as a Workflow: strict decoding error: unknown field "spec.templates[0].outputs.artifacts[0].overwrite"
```
$ make test-examples
<SNIP>
    examples_test.go:28: Error parsing ../../examples/webhdfs-input-output-artifacts.yaml: strict decoding error: unknown field "spec.templates[0].outputs.artifacts[0].overwrite"
=== FAIL: ExamplesSuite/TestExampleWorkflows
FAIL    github.com/argoproj/argo-workflows/v3/test/e2e  1.580s
FAIL
make: *** [Makefile:609: test-examples] Error 1
```

Signed-off-by: Mason Malone <[email protected]>
@MasonM MasonM changed the title feat: add example ValidatingAdmissionPolicy to block param interpolation. Fixes #5114 feat: add example ValidatingAdmissionPolicy to block param interpolation. Partial fix for #5114 Jan 17, 2025
@MasonM MasonM changed the title feat: add example ValidatingAdmissionPolicy to block param interpolation. Partial fix for #5114 docs: add example ValidatingAdmissionPolicy to block param interpolation Jan 17, 2025
@MasonM
Copy link
Contributor Author

MasonM commented Jan 17, 2025

/retest

@MasonM MasonM marked this pull request as ready for review January 17, 2025 06:51
@MasonM MasonM requested a review from crenshaw-dev January 17, 2025 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/templating Templating with `{{...}}` type/security Security related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant