-
Notifications
You must be signed in to change notification settings - Fork 30
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
policy: improve args and env variables validation #308
base: msft-main
Are you sure you want to change the base?
Conversation
1ab8fa6
to
05b6c7b
Compare
@@ -219,6 +219,8 @@ | |||
"dns_label": "[a-zA-Z0-9_\\.\\-]+", |
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.
We may want to refine this regex. Per https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names , a dns label name does not allows upper case, nor .
, and we could limit it to 63 characters
@@ -55,12 +55,125 @@ default AllowRequestsFailingPolicy := false | |||
S_NAME_KEY = "io.kubernetes.cri.sandbox-name" | |||
S_NAMESPACE_KEY = "io.kubernetes.cri.sandbox-namespace" | |||
BUNDLE_ID = "[a-z0-9]{64}" | |||
# from https://github.com/kubernetes/kubernetes/blob/8294abc599696e0d1b5aa734afa7ae1e4f5059a0/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L177 | |||
SUBDOMAIN_NAME = "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | |||
ALWAYS_ALLOWED = ["$(resource-field)", "$(todo-annotation)"] |
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.
todo: double check we are not allowing the execution of args that include these vars that are always allowed. Before, these placeholders where replaced in the policy and there wasn't a special rule to allow these for args, like there was for node-name.
allow_env_map_entry(key, i_val, p_env_map) { | ||
p_val := p_env_map[key] | ||
p_val == "$(node-name)" | ||
regex.match(policy_data.common.dns_subdomain , i_val) |
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.
node-name most match a dns subdomain format
allow_env_map_entry(key, i_val, p_env_map) { | ||
p_val := p_env_map[key] | ||
p_val == "$(host-name)" | ||
regex.match(policy_data.common.dns_label , i_val) |
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.
host-name most match a dns label format
allow_env_map_entry(key, i_val, p_env_map) { | ||
p_val := p_env_map[key] | ||
p_val == "$(pod-uid)" | ||
regex.match(policy_data.common.pod_uid , i_val) |
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.
pod-uid most match a UUID format
f486a3f
to
45ce34f
Compare
PolicyCreateContainerRequest will be a wrapper to CreateContainerRequest and will allow the agent to transform the input such that is easier to validate in the policy. Signed-off-by: Saul Paredes <[email protected]>
- Add environment variable map to the engine on the agent - Add environment variable map to the policy on genpolicy - Validate this environemnt variable map on the rules - Restrain some environment variable values that we expect to look like a subdomain and use a regex to validate them Signed-off-by: Saul Paredes <[email protected]>
45ce34f
to
22d11d2
Compare
Add a new rule that validates args by substituting env variables received from the input. This new rule ensures that the args received from the input are the same as the args received from the policy. Signed-off-by: Saul Paredes <[email protected]>
22d11d2
to
d3303fd
Compare
Merge Checklist
upstream/missing
label (orupstream/not-needed
) has been set on the PR.Summary
policy: improve args and env variables validation. See commits for details
Test Methodology
Passing all fork samples