Repository navigation
fix(apk): accept a !name entry in the world - #2695
Conversation
astrojerms
left a comment
There was a problem hiding this comment.
🤖 Review summary
The resolver change works. A top-level !name disqualifies the providers of name, installs nothing for that entry, and reports name as a conflict, the same as a package-declared conflict. It reuses the exclusion constrain already does instead of adding a second mechanism.
The main gap is between the description and apko's build path. The description gives an image configuration as the use case, but apko build/publish still fail on !musl (SR001). The new test also doesn't exercise the exclusion itself (SR002).
Should address
| ID | Severity | File:Line | Issue | Suggestion |
|---|---|---|---|---|
| SR001 | Medium | pkg/apk/apk/repo.go:738-745 |
The resolver now accepts !name, but the image-configuration path the description cites still fails. LockImageConfiguration calls unify (pkg/build/lock.go:180-206), which adds !musl to the set of original packages. No resolved package matches it, so unify errors with unable to lock packages to a consistent version: map[!musl:[ (amd64)]] (lock.go:246-281). I reproduced this at the PR head. Every apko build/publish without a lockfile goes through this path. This isn't a regression, since the input failed before this PR too. |
Either (a) carry !-prefixed entries through the build path: skip them in unify's missing check, append them to each per-arch locked list, cover the lockfile branch (SR010), and add a TestUnify case. Or (b) if your caller uses the resolver directly, narrow the description to resolver-level callers and track build support separately. Which caller is the motivating one? |
| SR002 | Low | pkg/apk/apk/repo_test.go:830-853 |
TestWorldConflict doesn't show that !musl changes which provider gets picked. In this fixture, ["glibc"] alone already resolves to ld-linux. If a later change moved the new DeleteFunc ahead of constrain, the package assertions would still pass. The test does guard the new skip and the conflict report. |
Exclude the provider the solver picks by default. {"glibc","!ld-linux"} should give musl-1.23-r4.apk, glibc-2.38-r10.apk and conflicts {"ld-linux"}. |
| SR005 | Low | pkg/apk/apk/repo.go:739 |
A bare ! entry used to fail with nothing provides. It's now accepted silently and returns the conflict "", so a typo or templating bug in a config does nothing. |
Reject an empty name after CutPrefix, with an error that names the entry. |
If you go with SR001 option (a):
- SR010 (
pkg/apk/apk/repo.go:738): with an existing lockfile,Arch2LockedPackagesreturns onlyname=versionentries (pkg/lock/lock.go:91-96), and those replaceContents.Packages(pkg/build/lock.go:104).!muslnever reaches the image's/etc/apk/world, so a later runtimeapk addisn't constrained by it. Fixingunifyalone leaves this path broken. - Document the syntax in
docs/apko_file.mdonceapko buildaccepts it.
Optional:
- Add table cases for a world that both requests and excludes a name (
{"glibc","!musl","musl"}, which errors withexcluded by !musl) and for a versioned conflict (!musl>2.0). - Add a sentence to the
GetPackagesWithDependenciesdoc comment saying that a!nameentry installs nothing and comes back inconflicts.
CI: Enforce - Commit Signing fails because 48e428da is unsigned.
What's well done
pkg/apk/apk/repo.go:736-737: The comment explains why dropping the entry is only safe afterconstrainhas run, and ties it to apk world semantics. You can't tell that ordering from the deletion alone.pkg/apk/apk/repo.go:738-745: This reusesdisqualifyProvidersthroughconstraininstead of adding a second exclusion mechanism. World entries go through the sameconflicts/uniqifypath as dependency-declared!name, so duplicates are collapsed for free.pkg/apk/apk/repo_test.go:830-853: The test mirrorsTestExcludedDeps, which makes the world form and the dependency form easy to compare. It also puts therequire.Equalarguments in (expected, actual) order, which its neighbor gets backwards.- The description clearly states the old failure, the new semantics, and the test that covers them.
48e428d to
13561f2
Compare
tomgeorge
left a comment
There was a problem hiding this comment.
LGTM. The resolver change does what the description says; the remaining points from the earlier review are non-blocking.
Existing findings confirmed (from #2695 (review))
- SR001, still open, non-blocking:
apko buildwithout a lockfile still fails on!muslincontents.packages, becauseunifytreats!muslas a missing package (pkg/build/lock.go:180-206, error atlock.go:280). This failed before the PR too, and the current description no longer claims image-config support, so I'm reading this PR as resolver/world-file only. Worth saying so in the description, since "package list" reads likecontents.packagesto apko users. - SR002, still open, nit:
TestWorldConflictpasses without the exclusion doing anything. I ran{"glibc"}alone and it already resolves told-linux.{"glibc","!ld-linux"}givesmusl-1.23-r4.apk, glibc-2.38-r10.apkwith conflicts["ld-linux"], which would actually catch a regression. - SR005, still open, nit: a bare
!entry now resolves silently with conflict""(pkg/apk/apk/repo.go:739). Rejecting an empty name afterCutPrefixwould surface a templating mistake.
What I verified
constraindisqualifies the providers of a!nameentry before the newDeleteFuncremoves it (pkg/apk/apk/repo.go:732-744), sonextPackagenever sees!name.- The second loop skips
!entries (repo.go:770), soGetPackageWithDependenciesisn't called with!musl. - The conflict string is
namewith any version suffix kept, the same as for a dependency-declared!name(repo.go:984), anduniqifydedups the two. - Targeted run at 13561f2:
{"glibc","!musl","musl"}errors withexcluded by !musl,{"!musl"}returns no packages and conflictmusl, and!musl>2.0returns conflictmusl>2.0. FixateWorldchecks each conflict against the installed DB (pkg/apk/apk/implementation.go:942), so a world with!muslon a system that already has musl fails with "cannot install due to conflict with musl", as in apk.- CI is green at 13561f2 (
gh pr checks), including commit signing.
|
Does apk-tools support !pkg syntax in the world file? If yes, can we ensure to add it to the world file? This is to ensure that subsequent usage of "apk add" continues to respect the original negative package selection. If it doesn't support this, it would help to synthesise a package that is declared in the installed database with a depends on "!pkg" - as we know for sure that apk-tools respects this; as we use that to block installing musl today. |
tomgeorge
left a comment
There was a problem hiding this comment.
Re-reviewed after 7bbd192. LGTM, same non-blocking nits as before.
- SR001: addressed for builds without a lockfile.
unifynow keeps!namein every locked list (pkg/build/lock.go:183-187,:319,:338), and the newTestUnify"excluded package" case covers it. - SR010: still open, non-blocking. With a lockfile,
Arch2LockedPackagesonly emitsname=version(pkg/lock/lock.go:89-100), so!muslnever reaches/etc/apk/world. The image contents are still right, but a laterapk add muslinside the image isn't blocked. - SR002 (nit):
TestWorldConflictpasses even if the exclusion does nothing. Using{"glibc","!ld-linux"}would make it fail when the exclusion breaks. - SR005 (nit): a bare
!still resolves silently, with conflict"".
What I verified
- The resolver change in
pkg/apk/apk/repo.gohasn't changed since 13561f2. - A locked list like
["!bar", "foo=1.2.3"]goes back throughResolveWorld, which drops!barafterconstrain(pkg/apk/apk/repo.go:736-744).
I tested this locally with apk-tools 2.14.13 from wolfi-base and apko built from this branch. It works partly. A Where it passes:
Where it fails:
A package that depends on |
tomgeorge
left a comment
There was a problem hiding this comment.
Re-reviewed after 86edfa4 and dea6e18. LGTM, with one non-blocking edge case for base images (inline).
- SR010 (lockfile builds drop
!name): addressed.apko lockrecords!entries inContents.Excluded(internal/cli/lock.go:171-175), andArch2LockedPackagesappends them to each arch (pkg/lock/lock.go:103-105).TestArch2LockedPackagesExcludedcovers it. - xnox's runtime
apk addconcern: addressed byblockExcluded(pkg/build/build_implementation.go:571-602). - SR002, SR005: still open, nits as before.
Nits (non-blocking)
- With a base image built with
!entries, the derived image gets a second.apko-excludedrecord, and apk-tools then enforces neither one (pkg/build/build_implementation.go:596). .apko-excludedwill show up in the SPDX SBOM aspkg:apk/<os>/.apko-excluded@0-r0, sincesbom.go:109lists everything in the installed DB. Fine by me, but worth knowing.
What I verified
- I generated the record with
PackageToInstalledat dea6e18, appended it to a wolfi root's installed DB, and added!curland.apko-excluded=0-r0to the world. With apk-tools 2.14.13,apk add curlfails withbreaks: .apko-excluded-0-r0[!curl], and bothapk upgrade -aandapk fixkeep the package. - The checksum is derived from the sorted
!entries, so the record is the same on every build. blockExcludedruns after all three install paths (pre-resolved, lockfile,FixateWorld) (pkg/build/build_implementation.go:327).
| Dependencies: excluded, | ||
| Checksum: sum[:], | ||
| } | ||
| if _, err := bc.apk.AddInstalledPackage(pkg, nil); err != nil { |
There was a problem hiding this comment.
Optional: with a base image whose installed DB already has .apko-excluded (the base was built with a ! entry), this appends a second record with the same name and a different checksum. buildImage copies the base records in first, and the world also gets .apko-excluded=0-r0 twice. I tried that against apk-tools 2.14.13 with one record carrying D:!curl and the other D:!wget: apk add curl and apk add wget both succeeded, and apk upgrade -a replaced the package. So the derived image loses the base's block as well as its own. Merging the base record's ! dependencies into this one, and replacing that record rather than appending another, would fix it. baseimage is experimental, so I'm fine with this as a follow-up.
|
I added two commits for the world-file gap, as separate commits so either can be dropped.
I tested both by hand with apk-tools 2.14.13 on Wolfi, for builds from an image config and from a lockfile:
Two things to flag. |
A world entry of the form !name is a conflict in apk: the providers of name are disqualified and nothing is installed for the entry. constrain already disqualified the providers, but the install loop then looked for a package named !name and failed with "nothing provides". The loop now drops the entry after constrain and reports name as a conflict, as a !name dependency of a package already does. Signed-off-by: Dylan Uhryniuk <dylan.uhryniuk@chainguard.dev>
The lock step checked every entry of the package list for a locked version. A !name entry installs nothing, so the lock failed with "unable to lock packages to a consistent version". The lock now keeps the entry as is in every locked list. Signed-off-by: Dylan Uhryniuk <dylan.uhryniuk@chainguard.dev>
A lockfile held only name=version entries, so a build from a lockfile dropped the !name entries of the package list and wrote no exclusion to the apk world. The lockfile now records them under excluded, and a build from it adds them back to the package list of every architecture. Signed-off-by: Dylan Uhryniuk <dylan.uhryniuk@chainguard.dev>
…tabase A !name entry in the world keeps a package out when it is pulled in as a dependency, but an explicit apk add of the package replaces the entry. The build now records a package, .apko-excluded, that depends on each !name entry, as glibc depends on !musl, and pins it in the world. apk then refuses the package even on an explicit add. Signed-off-by: Dylan Uhryniuk <dylan.uhryniuk@chainguard.dev>
apk package checksums are SHA-1, so the import and the call are marked the same way as the other apk code. Signed-off-by: Dylan Uhryniuk <dylan.uhryniuk@chainguard.dev>
90857b1 to
2e37097
Compare
tomgeorge
left a comment
There was a problem hiding this comment.
Re-reviewed at 2e37097. The history was rewritten, but the tree only differs from 90857b1 in pkg/apk/apk/repo.go and its test. LGTM.
- SR002 (the test didn't exercise the exclusion): addressed.
TestWorldConflictnow excludesld-linux, the provider picked by default, and expectsmusl(pkg/apk/apk/repo_test.go:839-848). - SR005 (a bare
!was accepted silently): addressed. It's now rejected up front with an error naming the entry (pkg/apk/apk/repo.go:732-736), and the same test covers it. - Base-image duplicate
.apko-excludedrecord (pkg/build/build_implementation.go:596): still open, non-blocking. - Nit: as you said,
blockExcludedhas no unit test yet. One that checks the installed-DB record and the world entry would be enough.
What I verified
- The rejection runs before
constrain, so!never reachesdisqualifyProviders. blockExcluded, the lockfileexcludedfield, and theunifypassthrough are unchanged from dea6e18, which I checked against apk-tools 2.14.13.
What
A
!nameentry in the package list excludesname, as in an apk world file. Nothing is installed for the entry, andnameis reported as a conflict, the same as a!namedependency of a package.constrainalready disqualified the providers ofname. The install loop then looked for a package named!nameand failed withnothing provides "!name". The loop now drops the entry afterconstrain.LockImageConfigurationchecked every entry for a locked version and failed withunable to lock packages to a consistent version: map[!musl:...]. It now keeps a!nameentry as is in every locked list.name=versionentries, so a build from a lockfile dropped the exclusion. The lockfile now records!nameentries underexcluded, and a build from it adds them back.!nameentry in the world keepsnameout when it is pulled in as a dependency, but an explicitapk add namereplaces the entry. The build now records a package,.apko-excluded, that depends on each!nameentry, as glibc depends on!musl, and pins it in the world. apk then refusesnameeven on an explicit add.Why
A
!namedependency of a package works today. The same exclusion in the package list failed.TestWorldConflictresolvesglibcwith!ld-linux: without the exclusionglibcgetsld-linux, and with itglibcgetsmusl, withld-linuxas the conflict. A bare!names no package and fails. ATestUnifycase and a lockfile case cover the lock and the lockfile.Tested by hand with apk-tools 2.14.13 on Wolfi, for builds from an image config and from a lockfile: the world has the entry and the pinned
.apko-excluded,apk add gitpicks another libcurl provider, an explicitapk add libcurl-openssl4is refused, andapk fixkeeps the block.Notes
.apko-excludedappears in the image SBOM as a package. The installed-database commit has no unit test yet.