konflux-ci / build-definitions

Apache License 2.0
23 stars 133 forks source link

buildah: Use either openat2(RESOLVE_BENEATH) or don't follow links #1377

Open cgwalters opened 2 months ago

cgwalters commented 2 months ago

I came across this bit of code that runs after the just-built image is mounted (to be passed to scanners):

https://github.com/konflux-ci/build-definitions/blame/38c6cd3f4733ed1ee638ce43bacd1096e3e5076d/task/buildah-remote/0.2/buildah-remote.yaml#L487

What would be a lot less ugly than just blowing away all symbolic links is using Linux's openat2 system call has RESOLVE_IN_ROOT which allows a process to safely inspect a distinct root and resolve any symlinks as if they're in that root.

Or perhaps simpler often, just...don't follow symlinks in whatever is doing this scanning. (Why would it traverse symlinks?)

chmeliik commented 2 weeks ago

We delete the symlinks from the mounted container filesystem before running syft and/or the Java SBOM thingy on it https://github.com/konflux-ci/build-definitions/blob/421ee9faf056cc03900c196db50c203791be97e4/task/buildah/0.2/buildah.yaml#L519

For syft, the better solution would be to run it on an oci-archive: of the image rather than the exported filesystem. The Java thingy doesn't support that, but it's also pretty much dead code at this point, AFAIK nobody uses the Java support this way anymore. Once we get rid of that, we can change the task to run syft on an oci-archive: and this will become irrelevant

Until then, this is a minor issue and IMO not worth solving (it doesn't affect anything, the exported filesystem never leaves the buildah task pod)