Skip to content

Policies fail even after file is updated #235

Discussion options

You must be logged in to vote

Hi @jeremyhager! I have not been involved in authoring that policy, but it seems to check for the securityContext only on the spec itself, an not the individual containers, i.e. input.spec.template.spec.securityContext.runAsNonRoot. I believe this is valid configuration, but if you'd rather want to check each container instead, perhaps in order to allow some containers without the setting, you could do something like:

deny[msg] {
	kubernetes.is_deployment
	container := input.spec.template.spec.containers[_]
        not container.securityContext.runAsNonRoot

	msg = sprintf("Container %s must not run as root in Deployment %s", [container.name, name])
}

(you might want to repeat the process…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jeremyhager
Comment options

Answer selected by jeremyhager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants