Skip to content

Rewrite container handling internals to drop graphdriver and gpgme dependencies [RHEL-56367] - #2607

Merged
supakeen merged 20 commits into
osbuild:mainfrom
achilleas-k:drop-dep/containers-image/part2
Sep 2, 2026
Merged

Rewrite container handling internals to drop graphdriver and gpgme dependencies [RHEL-56367]#2607
supakeen merged 20 commits into
osbuild:mainfrom
achilleas-k:drop-dep/containers-image/part2

Conversation

@achilleas-k

@achilleas-k achilleas-k commented Aug 20, 2026

Copy link
Copy Markdown
Member

This PR rewrites container-related things in order to drop our dependency on graphdrivers and gpgme. It finishes the work I started in #2346, where I changed the container resolver internals to use skopeo.

Changes in this PR, in order:

  1. Rewrite testregistry to use github.com/distribution/distribution. This simplifies the implementation of the internal container test registry significantly, offloading all the work to distribution/distribution. It also gives us a more fully-featured test registry, so we can test pushing containers as well.
  2. Test osbuild-upload-container with the new test registry. The upload code wasn't being tested at all before, so any testing here is an improvement.
  3. Rewrite osbuild-upload-container to use skopeo copy internally.

With these rewrites, we rely on skopeo for almost all of our interactions with container registries, which means we don't depend on any of the filesystem libraries or gpgme.

@achilleas-k
achilleas-k requested review from a team and thozza as code owners August 20, 2026 18:38
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image/part2 branch 7 times, most recently from 5bf4948 to 5236abc Compare August 20, 2026 19:05
@achilleas-k

This comment was marked as outdated.

@achilleas-k

This comment was marked as outdated.

@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image/part2 branch 6 times, most recently from 31d3292 to e7e82a8 Compare August 21, 2026 11:55
@achilleas-k

This comment was marked as outdated.

Comment thread pkg/container/client.go Outdated

var manifestDigest digest.Digest
if dockerAuth := cl.sysCtx.DockerAuthConfig; dockerAuth != nil {
cmd.Args = append(cmd.Args, fmt.Sprintf("--dest-creds=%s:%s", dockerAuth.Username, dockerAuth.Password))

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 leaks the credentials to any user running ps during a build. Is there no other way of passing these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had the same thought but the only reason we have the user:pass option is because the osbuild-upload-container supports --username and --password and in that case, the original call leaks them to begin with. Maybe we should get rid of that entirely and only support auth-file.

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.

Let's turn this into an issue here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to also cause a leak in the osbuild-composer workers when uploading container images. They call (*Client).UploadImage() at osbuild-composer/cmd/osbuild-worker/jobimpl-osbuild.go:1319 which results in the same argv leak under discussion here.

Given that this is a new leak affecting the library API we may want to reconsider deferring to the future. I think it would make sense to update this pull request to only support auth-file.

@achilleas-k achilleas-k Sep 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh we do use it! Ok then, I'll take care of it in this PR.

Comment thread pkg/container/client.go Outdated
Comment thread pkg/container/client.go
supakeen
supakeen previously approved these changes Aug 26, 2026
@achilleas-k
achilleas-k requested a review from avitova August 31, 2026 12:47

@lucasgarfield lucasgarfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks great!

Only thing I caught is that the skopeo argv leak is a bit worse than we thought. I'd request that we address that somehow (if we choose to defer, that's fine, but we should be intentional about it) before approval.

I would also be curious to hear why we decided to go with distribution/distribution for the registry. Did you consider google/go-containerregistry/pkg/registry? I have no strong opinion and can see good arguments for both, just curious about you decided. distribution/distribution has more features (which I'm not sure we're taking advantage of... yet?) but also more dependencies.

@achilleas-k

Copy link
Copy Markdown
Member Author

I would also be curious to hear why we decided to go with distribution/distribution for the registry. Did you consider google/go-containerregistry/pkg/registry? I have no strong opinion and can see good arguments for both, just curious about you decided. distribution/distribution has more features (which I'm not sure we're taking advantage of... yet?) but also more dependencies.

I didn't spend too much time looking into the two but it seemed like it was less work to get a minimal registry running with distribution/distribution. Looking a bit more deeply though, it looks like I was wrong and go-containerregistry is closer to what we want.

I'll play around with it a bit more.

@achilleas-k

Copy link
Copy Markdown
Member Author

Ok, moving everything to go-containerregistry is nicer actually. And it's a minimal change from what we have now. Pushing in a minute.

Add a method to the new registry that adds a manifest list with 4 random
images for testing.
Rewrite the resolver tests to use the new test registry functionality.
Return the image IDs that were created by the PopulateWithManifestList()
function alongside the digests for the new images.
Rewrite the container client tests to use the new test registry
functionality.
Rewrite the blocking resolver tests to use the new test registry
functionality.
Use the new testregistry to upload a container using
osbuild-upload-container and verify that it was uploaded successfully by
resolving the container using our own resolver.

The main() function of the osbuild-upload-resolver is split into an
upload() function that does the main work so it can be testable.  The
main() function now only handles command line flags and then calls into
the new function.
Test uploading a container with credentials (username and password).
Rewrite the container UploadImage() function to shell out to skopeo
copy.  It takes care of all the options we currently support by
converting them to command line options.  The functionality is tested by
the new osbuild-upload-container tests.
Drop the parseImageName() function and the policy property of the
client.  They're not needed anymore.
On RHEL and CentOS, the exclude_graphdriver_btrfs tag was needed to
compile without support for the btrfs driver from the containers/image
dependency.  That dependency is now gone and we don't need to specify
the tag anymore.
The same goes for the other graphdrivers: devicemapper and overlay.
Even though we could support those on the two distros, we sometimes
specified them to avoid needing the devel package dependency installed.
The containers/image pgp dependency is also gone.
Remove btrfs-progs-devel, device-mapper-devel, and gpgme-devel from the
dependency install script.
Remove mentions of btrfs-progs-devel and device-mapper-devel.

Also remove mentions of cmd/build.

This README should be replaced by the Image Builder readme soon.

See HMS-10586
Remove all mentions of:
- gpgme-devel
- btrfs-progs-devel
- device-mapper-devel
Specifically, skip tests that fail in containers because of the way they
access the host container storage.  These weren't an issue on CentOS
before, but now appear to be failing the same way they do in Fedora
containers.
We use systemd-escape to generate mount unit names.  On installations,
this is pulled in by osbuild itself, but tests will fail at build time
without it.
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image/part2 branch from be9d96a to ac9961c Compare September 1, 2026 16:28
@achilleas-k

achilleas-k commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

To make reviewing easier, I pushed a rebase on main first and then did a second force push with the changes addressing the reviews.

And another two to fix issues caught by the linter.

Instead of putting credentials in the arguments of the 'skopeo copy'
call (with --dest-creds) when uploading a container, write a temporary
auth file and use --authfile.  This prevents leaking credentials through
the shell call, which is visible to any user on the system.
Now that we have an auth file creation function, let's use it instead of
depending on 'skopeo login' to generate it.
@achilleas-k
achilleas-k force-pushed the drop-dep/containers-image/part2 branch from ac9961c to 73c0291 Compare September 2, 2026 09:05

@lucasgarfield lucasgarfield left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Leak is fixed and I'm happy you ended up liking go-containerregistry/pkg/registry... the main thing that made me interested in it is that I'm now always on the lookout to minimize transitive dependencies. 😄

@supakeen
supakeen enabled auto-merge September 2, 2026 18:47
@supakeen
supakeen added this pull request to the merge queue Sep 2, 2026
Merged via the queue into osbuild:main with commit 100fbe5 Sep 2, 2026
55 of 63 checks passed
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.

skopeo copy leaks the credentials to any user running ps during a build

3 participants