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

Policies for docker #371

Open
sadams-evi opened this issue Nov 8, 2022 · 0 comments
Open

Policies for docker #371

sadams-evi opened this issue Nov 8, 2022 · 0 comments

Comments

@sadams-evi
Copy link

Can I craft policies for docker images ?
I would like to implement the following policy in regula.
Is it possible for me to write a similar policy using regula, or will I need to build my own user libraries to implement this policy ?

package builtin.dockerfile.DS002

import data.lib.docker

# get_user returns all the usernames from
# the USER command.
get_user[username] {
	user := docker.user[_]
	username := user.Value[_]
}

# fail_user_count is true if there is no USER command.
fail_user_count {
	count(get_user) < 1
}

# fail_last_user_root is true if the last USER command
# value is "root"
fail_last_user_root[lastUser] {
	users := [user | user := docker.user[_]; true]
	lastUser := users[count(users) - 1]
	lastUser.Value[0] == "root"
}

deny[res] {
	fail_user_count
	msg := "Specify at least 1 USER command in Dockerfile with non-root user as argument"
	res := result.new(msg, {})
}

deny[res] {
	cmd := fail_last_user_root[_]
	msg := "Last USER command in Dockerfile should not be 'root'"
	res := result.new(msg, cmd)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant