Skip to content

add example to test registry - #107

Open
larhauga wants to merge 1 commit into
open-policy-agent:mainfrom
larhauga:example-registries
Open

add example to test registry#107
larhauga wants to merge 1 commit into
open-policy-agent:mainfrom
larhauga:example-registries

Conversation

@larhauga

Copy link
Copy Markdown
Collaborator

add example of how to test image registries.
fixes #93

@larhauga
larhauga marked this pull request as draft April 14, 2025 05:12
@larhauga
larhauga force-pushed the example-registries branch 2 times, most recently from 4357fbb to 1ba5a54 Compare April 14, 2025 05:18
@larhauga
larhauga marked this pull request as ready for review April 14, 2025 05:20

@anderseknert anderseknert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! One issue to address, but besides that, awesome!

Comment thread example.rego Outdated

allowed_registries := [
"public.ecr.aws/",
"busybox",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This too should have a trailing /, or else there's always the risk that someone registers busyboxevilhacker and we'll consider it a an allowed registry.

@larhauga larhauga Apr 14, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since docker allows "busybox" as image I tested some more and changed the policy to allow if the image matches explicitly or has registry prefix.
@anderseknert do you think this is a ok solution, or do you have any tips on a better one? :) Thanks

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just Docker benefiting themselves by having "no registry in the image string" mean their registry, i.e. docker.io. I would probably do something like this:

image := input.Body.Image if {
	contains(input.Body.Image, "/")
} else := concat("/", ["docker.io", input.Body.Image])

And then using image everywhere in place of input.Body.Image you can work with the same logic for docker.io as any other registry in your policy (meaning it would have to be included in allowed_registries).

Let me know if I missed any details :)

Comment thread testdata/image_registries.rego Outdated
@larhauga
larhauga force-pushed the example-registries branch 2 times, most recently from f83e8b2 to e2fae5c Compare April 14, 2025 19:03
Signed-off-by: Lars Haugan <lars.haugan@sparebank1.no>
@larhauga
larhauga force-pushed the example-registries branch from e2fae5c to d3f944b Compare April 14, 2025 19:16
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

Successfully merging this pull request may close these issues.

Docker pull and push should be deny

2 participants