Skip to content

fix(config): use stapel coreutils in pm snapshot command#182

Open
reyreavman wants to merge 4 commits into
mainfrom
fix/pm-snapshot-stapel-tool-paths
Open

fix(config): use stapel coreutils in pm snapshot command#182
reyreavman wants to merge 4 commits into
mainfrom
fix/pm-snapshot-stapel-tool-paths

Conversation

@reyreavman

Copy link
Copy Markdown
Collaborator

No description provided.

The packages stage snapshot command resolved build secrets with plain
cat and created the provenance dir with plain mkdir, both looked up via
PATH. On scratch/distroless base images these tools do not exist, the
cat failure was muted by || true, and the PACKAGES_VERSION guard failed
even though the secret file was mounted and non-empty. Invoke cat and
mkdir via the always-mounted /.werf/stapel/embedded/bin instead, the
same way the stage script interpreter is already invoked.

Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
Comment thread pkg/config/packages_commands.go Outdated

containerFactoryVersionSnapshotCmdTmpl = resolvePmEnvFromSecrets +
`; : "${PACKAGES_VERSION:?required by werf for pm SBOM provenance}" && mkdir -p %s && printf '%%s\n' "$PACKAGES_VERSION" > %s`
`; : "${PACKAGES_VERSION:?required by werf for pm SBOM provenance}" && ` + stapelEmbeddedBinDir + `/mkdir -p %s && printf '%%s\n' "$PACKAGES_VERSION" > %s`

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's use pkg/stapel:

func MkdirBinPath() string {

Expect(cmd).To(ContainSubstring(`/.werf/stapel/embedded/bin/mkdir -p `))
Expect(cmd).NotTo(MatchRegexp(`(^|[^/])\bcat /run/secrets/`))
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need e2e-tests with registry.werf.io/werf/scratch + secrets to cover this case

Replace the hardcoded stapel embedded bin dir in the snapshot command
with stapel.CatBinPath and stapel.MkdirBinPath so the paths stay in one
place alongside the other stapel tool path helpers.

Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
Build an image from registry.werf.io/werf/scratch with pm and CA certs
imported from a carrier image and PACKAGES_VERSION/REGISTRY provided
only as build secrets. The scratch base has no coreutils and no baked
pm env, so the test fails unless the snapshot command resolves secrets
via stapel-embedded tools. The containerfactoryversion purl qualifier
assertion proves the secret value reached the provenance file.

Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
The os-pm SBOM collector read pm.lock and container-factory-version by
running cat inside a throwaway container, which fails for scratch and
distroless images that ship no coreutils. Replace RunCommandInImage
with ReadFileFromImage: the docker backend creates a container without
starting it and streams the file via the copy API, the buildah backend
mounts the container root filesystem and reads the file directly.

Signed-off-by: Radmir Khurum <radmir.khurum@flant.com>
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.

2 participants