Skip to content

source policy resolves image digest before matching #3911

@tianon

Description

@tianon

I was testing the new source policy support (#3332 + follow-ups for format changes) via buildx version 0.11.0-rc1 (docker/buildx#1628), and found it's got some interesting quirks that seem to make the instructions in https://github.com/moby/buildkit/blob/e4683730676f8788ae3ad108375f278dda148fad/docs/build-repro.md not actually do what is expected. 😅

In short, it appears that it resolves image references in a Dockerfile all the way to a full digest before matching against policy lines, so a tag-only selector will actually never match. 😬

Here's a policy I've been using against a Dockerfile of just FROM bash that shows the issue pretty clearly:

{
  "rules": [
    {
      "action": "DENY",
      "selector": {
        "identifier": "*"
      }
    },
    {
      "action": "ALLOW",
      "selector": {
        "identifier": "local://dockerfile"
      }
    },
    {
      "action": "CONVERT",
      "selector": {
        "identifier": "docker-image://docker.io/library/bash:latest"
      },
      "updates": {
        "identifier": "docker-image://docker.io/library/debian:bullseye-slim"
      }
    }
  ]
}
$ ./buildx create --name foo
$ printf 'FROM bash:latest' | EXPERIMENTAL_BUILDKIT_SOURCE_POLICY=<(jq -nc '{ rules: [ { action: "DENY", selector: { identifier: "*" } }, { action: "ALLOW", selector: { identifier: "local://dockerfile" } }, { action: "CONVERT", selector: { identifier: "docker-image://docker.io/library/bash:latest" }, updates: { identifier: "docker-image://docker.io/library/debian:bullseye-slim" } } ] }') ./buildx --builder foo build --progress=plain -
#0 building with "foo" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 53B done
#1 DONE 0.0s

#2 [auth] library/bash:pull token for registry-1.docker.io
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/bash:latest
#3 DONE 0.6s
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
ERROR: failed to solve: failed to load LLB: error evaluating the source policy: source "docker-image://docker.io/library/bash:latest@sha256:d6f71002f8b3cb7660d5bec2436a850564e79673c43be75f31908c250f808458" denied by policy: source denied by policy

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions