Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package apko for openSUSE:Factory checked in at 2026-12-03 13:57:57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/apko (Old) and /work/SRC/openSUSE:Factory/.apko.new.1340718 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "apko" Thu Dec 3 13:57:57 2026 rev:152 rq:1402583 version:1.5.5 Changes: -------- --- /work/SRC/openSUSE:Factory/apko/apko.changes 2026-12-02 17:07:58.320168802 +0100 +++ /work/SRC/openSUSE:Factory/.apko.new.1340718/apko.changes 2026-12-03 14:00:43.732930567 +0100 @@ -1,0 +2,23 @@ +Thu Dec 03 05:45:16 UTC 2026 - Johannes Kastl <[email protected]> + +- Update to version 1.5.5: + * apk: Refresh discovered repository keys after ten minutes + (#2714) + * fix(apk): allow an explicit opt-in for a plain-HTTP + repository's own JWKS (#2712) + * apk: track every selected version of an origin (#2688) + * build(deps): bump chainguard.dev/sdk from 0.3.8 to 0.4.3 + (#2713) + * build(deps): bump chainguard.dev/sdk from 0.2.20 to 0.3.8 + (#2710) + * build(deps): bump google.golang.org/api from 0.316.0 to 0.317.0 + (#2711) + * build(deps): bump k8s.io/apimachinery from 0.37.2 to 0.37.3 + (#2709) + * build(deps): bump sigstore/cosign-installer from 4.1.3 to 4.1.4 + (#2708) + * build(deps): bump the codeql group with 2 updates (#2707) + * Resolve against in-memory repositories, not the repositories + file (#2702) + +------------------------------------------------------------------- Old: ---- apko-1.5.4.obscpio New: ---- apko-1.5.5.obscpio ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ apko.spec ++++++ --- /var/tmp/diff_new_pack.BGNBrT/_old 2026-12-03 14:00:45.122989566 +0100 +++ /var/tmp/diff_new_pack.BGNBrT/_new 2026-12-03 14:00:45.123989608 +0100 @@ -17,7 +17,7 @@ Name: apko -Version: 1.5.4 +Version: 1.5.5 Release: 0 Summary: Build OCI images from APK packages directly without Dockerfile License: Apache-2.0 ++++++ _service ++++++ --- /var/tmp/diff_new_pack.BGNBrT/_old 2026-12-03 14:00:45.156991009 +0100 +++ /var/tmp/diff_new_pack.BGNBrT/_new 2026-12-03 14:00:45.160991179 +0100 @@ -3,7 +3,7 @@ <param name="url">https://github.com/chainguard-dev/apko.git</param> <param name="scm">git</param> <param name="exclude">.git</param> - <param name="revision">refs/tags/v1.5.4</param> + <param name="revision">refs/tags/v1.5.5</param> <param name="versionformat">@PARENT_TAG@</param> <param name="versionrewrite-pattern">v(.*)</param> <param name="changesgenerate">enable</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.BGNBrT/_old 2026-12-03 14:00:45.180992028 +0100 +++ /var/tmp/diff_new_pack.BGNBrT/_new 2026-12-03 14:00:45.184992197 +0100 @@ -3,6 +3,6 @@ <param name="url">https://github.com/chainguard-dev/apko</param> <param name="changesrevision">861f83f69e6fa9114405a2f7bb5cf6585ad00421</param></service><service name="tar_scm"> <param name="url">https://github.com/chainguard-dev/apko.git</param> - <param name="changesrevision">0408833b19c8187e2d2329d7cb47e610356225cd</param></service></servicedata> + <param name="changesrevision">c3556e6b16584ac2fe90b6b8a63d1ad8f1a4d46c</param></service></servicedata> (No newline at EOF) ++++++ apko-1.5.4.obscpio -> apko-1.5.5.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/go.mod new/apko-1.5.5/go.mod --- old/apko-1.5.4/go.mod 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/go.mod 2026-12-02 05:58:56.000000000 +0100 @@ -3,7 +3,7 @@ go 1.27.0 require ( - chainguard.dev/sdk v0.2.20 + chainguard.dev/sdk v0.4.3 github.com/chainguard-dev/clog v1.8.1 github.com/charmbracelet/log v1.0.0 github.com/erofs/go-erofs v0.3.2 @@ -36,11 +36,11 @@ golang.org/x/sys v0.50.0 golang.org/x/term v0.48.0 golang.org/x/time v0.16.0 - google.golang.org/api v0.316.0 + google.golang.org/api v0.317.0 google.golang.org/protobuf v1.36.12 gopkg.in/ini.v1 v1.68.0 gopkg.in/yaml.v3 v3.0.1 - k8s.io/apimachinery v0.37.2 + k8s.io/apimachinery v0.37.3 sigs.k8s.io/release-utils v0.12.5 ) @@ -134,12 +134,12 @@ go.opentelemetry.io/proto/otlp v1.11.0 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect go.yaml.in/yaml/v4 v4.0.0-rc.6 // indirect - golang.org/x/crypto v0.58.0 // indirect + golang.org/x/crypto v0.59.0 // indirect golang.org/x/exp v0.0.0-20260727155853-b88d891fe743 // indirect - golang.org/x/net v0.62.0 // indirect - golang.org/x/text v0.43.0 // indirect + golang.org/x/net v0.63.0 // indirect + golang.org/x/text v0.44.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f // indirect google.golang.org/grpc v1.85.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/go.sum new/apko-1.5.5/go.sum --- old/apko-1.5.4/go.sum 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/go.sum 2026-12-02 05:58:56.000000000 +0100 @@ -2,8 +2,8 @@ chainguard.dev/go-grpc-kit v0.20.0/go.mod h1:ocuwyRX9tqRRvJkS3/ZkDYGMnl+6FLC4bvF0cm6DGsk= chainguard.dev/go-oidctest v0.4.0 h1:B9YTfoa1WtsrEg0wnFeSP7i9tth0LO+GICm2j8HOgWI= chainguard.dev/go-oidctest v0.4.0/go.mod h1:IIic4S3je1I7Acy3bqPtaSPefGEsQDzUp7NJF35MPV4= -chainguard.dev/sdk v0.2.20 h1:kMhlzXD0MZm8r/tXG+v5Z3jH5zTHpf/5GvXmYjQ6bgg= -chainguard.dev/sdk v0.2.20/go.mod h1:0v7DhL1zPZlNba24mEh/iwVNHGJTgY7hpvsE7q0Keb4= +chainguard.dev/sdk v0.4.3 h1:0zf+tNzIM3rJp4vWjfjEXaJyCOhPApnVN5yXouH1pLU= +chainguard.dev/sdk v0.4.3/go.mod h1:vzHFf7Kr4Do/keu2ukAQC3Ig/3flsy57YHOSUi6XZjs= cloud.google.com/go/auth v0.24.1-0.20261001053825-dbc26066f70a h1:jW1ZLFy9oa5ai8LOI40z6s+DL1cO/L1KSm9hVGnibn8= cloud.google.com/go/auth v0.24.1-0.20261001053825-dbc26066f70a/go.mod h1:1dmBXa9xfBvBr39ZnDUDkaaA91ccq9CcqENDgJA4d7c= cloud.google.com/go/auth/oauth2adapt v0.3.1 h1:BKLDdbWS7pafd820dsyFDF6fPEzIGqr7ny6hbTzCCgE= @@ -289,15 +289,15 @@ go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4= go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54= -golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w= +golang.org/x/crypto v0.59.0 h1:xS2jhqYbzNrpvkWP2YTDf4TJwBy3ykR03i8vFDxEc7c= +golang.org/x/crypto v0.59.0/go.mod h1:veDyUwATGs3c+vN3VfTbzViMGXeTBk3WyhBOkn+F/4U= golang.org/x/exp v0.0.0-20260727155853-b88d891fe743 h1:ex206bKw+v3K0dm3andkrIF+ijyQKJG1pLgwQ2PYdQM= golang.org/x/exp v0.0.0-20260727155853-b88d891fe743/go.mod h1:EdfpwwqSu+0Li0mzskwHU6FWDV3t9Q+RZDo3QMUtL3Q= golang.org/x/mod v0.43.0 h1:MFuq5J6s35W9D3IjkwyWc9vHh0nENOrt5K8Iof4ofmg= golang.org/x/mod v0.43.0/go.mod h1:4ec1JnuyBz5+FIVhg86UsA39YG8BpnrZdJYSNHmGzHY= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= -golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= +golang.org/x/net v0.63.0 h1:HCoTmNh9EpD1PpK8gBNFY4gcTY4N+KQEO8ylfIKqFJ0= +golang.org/x/net v0.63.0/go.mod h1:15JLg3IX1bLjHK264EZQEbIpTiR/KVLuo9CTRWd0pig= golang.org/x/oauth2 v0.38.0 h1:uW7XQbcu1eoiQS7uMJvLOjPMl04bTbmY1VeRPxvbspI= golang.org/x/oauth2 v0.38.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58= golang.org/x/sync v0.25.0 h1:dJnifr0nMV8/SBnBvdo4eSGGnrc3O4FFx6IqvtLcmRs= @@ -315,23 +315,23 @@ golang.org/x/term v0.48.0 h1:G6UU1eiSB8nl3DzeUGt7Mg+2SctI8tPS6Z5/mBt6cOk= golang.org/x/term v0.48.0/go.mod h1:BRDLHCZr2SUjIeBHHpRyQeC9xzSAVbzY2rvKgafnHf4= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= -golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= +golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= +golang.org/x/text v0.44.0/go.mod h1:S4FR1waQ9LbjQTls97SyRjDaUUVkaM+cXwwuG/G+MwY= golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE= golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI= -golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA= +golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs= +golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/api v0.316.0 h1:nwaBinxtopJcOPwNYkvuRo7JA2nKppWzzk1sSORUWp4= -google.golang.org/api v0.316.0/go.mod h1:kn5kd1IMbs2x4hq99GcaTOumC0fnMYMwLNAfFxzpISU= +google.golang.org/api v0.317.0 h1:FAf4nkScNr1Zz2ng17GJFT5Cv+eJCy03T2xGcn0PJ4g= +google.golang.org/api v0.317.0/go.mod h1:4uj+S38vspRU3wb5PSAGB/syOzQVKJ6LNMmuvlr6NII= google.golang.org/genproto v0.0.0-20261012220534-4341edf3f941 h1:CXq2XEi5aEyLjjPZIwqrmQH8ZY4ctUwK7uyAx3mjX/U= google.golang.org/genproto v0.0.0-20261012220534-4341edf3f941/go.mod h1:3gK0ehnhP0V7/x3ypGoLyT3d0n6TSi/EcsphIjHrcz4= google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941 h1:DS/w3N8rsfrwxwgGSj6WhMsPo7aNQGmDx74J81zd0NQ= google.golang.org/genproto/googleapis/api v0.0.0-20261012220534-4341edf3f941/go.mod h1:AuGAdi9KnXss7xbLxIKhCvk+Ro/SxpET/iS45DNYN+M= -google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab h1:8sYjjefPfQ+FZEh1ZwBAqK/NifJVhOxut8nRh3SJzZM= -google.golang.org/genproto/googleapis/rpc v0.0.0-20261104224025-d1e00e9f33ab/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f h1:aDW6Vb2T1K0xbAgW+ED8iz39WlgjjX/OKiNh6tXv/+g= +google.golang.org/genproto/googleapis/rpc v0.0.0-20261118221215-c8830f628b3f/go.mod h1:OaIUM3+LpYcK2GXM4FTmhWoIq371Owdr+Cc7/BsYHHc= google.golang.org/grpc v1.85.0 h1:BPBCfuVRQ1qvBhKDOq9uvQllMvO59rKsYhXpp7Dd8vw= google.golang.org/grpc v1.85.0/go.mod h1:0rQrOD58yjal/0EaVbGBANindixsCZNQPDV3VKtaKuQ= google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= @@ -351,8 +351,8 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= -k8s.io/apimachinery v0.37.2 h1:G4t9RGoPDbQML38hz/kQQiltttgd3egg2ODCR8aIc2o= -k8s.io/apimachinery v0.37.2/go.mod h1:qaAvSNvgU2x07wRM95MSHSJTPQ/ob/LeNAGbeDgqQJg= +k8s.io/apimachinery v0.37.3 h1:0fC5KINyhJo/QZBIkJ2IeqdWtrI+0WGNAFMnTE8HIjI= +k8s.io/apimachinery v0.37.3/go.mod h1:OsyLAd4Zzn4L724/ZEQPnH0a6Kn282D6B4LEh8RZ7EM= pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= sigs.k8s.io/release-utils v0.12.5 h1:/Ybntn/M7sK+6XjaH88y3pfx3tpJod3WKiItxoS4igg= diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/internal/cli/jwks_origins.go new/apko-1.5.5/internal/cli/jwks_origins.go --- old/apko-1.5.4/internal/cli/jwks_origins.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/internal/cli/jwks_origins.go 2026-12-02 05:58:56.000000000 +0100 @@ -18,5 +18,6 @@ func addJWKSAllowedOriginFlag(cmd *cobra.Command, origins *[]string) { cmd.Flags().StringSliceVar(origins, "jwks-allowed-origin", nil, - "additional trusted HTTPS origin for repository JWKS discovery (may be repeated)") + "additional trusted origin for repository JWKS discovery: an https:// origin may serve JWKS for any repository; "+ + "an http:// origin lets only a repository on that same origin serve its JWKS over plain HTTP (may be repeated)") } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/cache.go new/apko-1.5.5/pkg/apk/apk/cache.go --- old/apko-1.5.4/pkg/apk/apk/cache.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/cache.go 2026-12-02 05:58:56.000000000 +0100 @@ -25,6 +25,7 @@ "path/filepath" "strings" "sync" + "time" "github.com/hashicorp/golang-lru/v2/simplelru" "go.opentelemetry.io/otel" @@ -36,17 +37,33 @@ type flightCache[K comparable, V any] struct { mux sync.Mutex lru *simplelru.LRU[K, *flightLoad[V]] + + // ttl, when positive, is how long a completed call stays cached before + // the next caller for its key starts a new call. Zero keeps entries until + // they are evicted or forgotten. + ttl time.Duration + now func() time.Time } // flightLoad is one in-flight or completed call. Entries are pointers so a // caller can tell its own entry apart from a newer one for the same key. type flightLoad[V any] struct { load func() (V, error) + + // loadedAt is when load returned, or zero while it is still running. + // Guarded by the owning flightCache's mux. + loadedAt time.Time } func newFlightCache[K comparable, V any](maxEntries int) *flightCache[K, V] { + return newFlightCacheWithTTL[K, V](maxEntries, 0) +} + +func newFlightCacheWithTTL[K comparable, V any](maxEntries int, ttl time.Duration) *flightCache[K, V] { return &flightCache[K, V]{ lru: newLRU[K, *flightLoad[V]](maxEntries, nil), + ttl: ttl, + now: time.Now, } } @@ -63,9 +80,13 @@ // permanently failing for transient errors: the caller that ran the failing // call gets its error, while callers that only joined that in-flight call // retry once with their own call instead of all reporting the same transient -// error. The boolean result reports whether the key was already present, -// including an in-flight call; for a retried caller it describes the retry, -// so it is false when that caller ended up running its own call. +// error. With a TTL, a completed entry older than the TTL counts as missing, +// while an in-flight call is always shared. If the call that refreshes an +// expired entry fails, it returns the expired value without an error, and +// that value stays expired so the next caller tries again. The boolean +// result reports whether the key was already present, including an +// in-flight call; for a retried caller it describes the retry, so it is +// false when that caller ended up running its own call. func (f *flightCache[K, V]) Do(key K, fn func() (V, error)) (V, bool, error) { value, hit, err := f.do(key, fn) if err != nil && hit { @@ -77,8 +98,29 @@ func (f *flightCache[K, V]) do(key K, fn func() (V, error)) (V, bool, error) { f.mux.Lock() entry, hit := f.lru.Get(key) + var stale *flightLoad[V] + if hit && f.expired(entry) { + hit, stale = false, entry + } if !hit { - entry = &flightLoad[V]{load: sync.OnceValues(fn)} + entry = &flightLoad[V]{} + entry.load = sync.OnceValues(func() (V, error) { + value, err := fn() + fellBack := false + if err != nil && stale != nil { + if old, oldErr := stale.load(); oldErr == nil { + value, err, fellBack = old, nil, true + } + } + f.mux.Lock() + entry.loadedAt = f.now() + if fellBack { + // Keep the old value's age so the next caller tries again. + entry.loadedAt = stale.loadedAt + } + f.mux.Unlock() + return value, err + }) f.lru.Add(key, entry) } f.mux.Unlock() @@ -97,6 +139,12 @@ return value, hit, err } +// expired reports whether entry is a completed call older than the TTL. The +// caller must hold f.mux. +func (f *flightCache[K, V]) expired(entry *flightLoad[V]) bool { + return f.ttl > 0 && !entry.loadedAt.IsZero() && f.now().Sub(entry.loadedAt) >= f.ttl +} + // Forget removes the given key from the cache. func (f *flightCache[K, V]) Forget(key K) { f.mux.Lock() @@ -125,6 +173,11 @@ const discoverKeysCacheMaxEntries = 64 +// discoverKeysCacheTTL bounds how long a repository's discovered keys are +// reused, so a long-running process picks up a changed key set without a +// restart. +const discoverKeysCacheTTL = 10 * time.Minute + // NewCache returns a new Cache, which allows us to persist the results of HEAD requests // for a given URL across multiple builds. This is generally desirable when building many images // all at once, since we can eliminate round trips to HEAD the same e.g. APKINDEX repeatedly. @@ -140,7 +193,7 @@ c := &Cache{ headFlight: &singleflight.Group{}, getFlight: &singleflight.Group{}, - discoverKeys: newFlightCache[string, []Key](discoverKeysCacheMaxEntries), + discoverKeys: newFlightCacheWithTTL[string, []Key](discoverKeysCacheMaxEntries, discoverKeysCacheTTL), } if etag { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/cache_test.go new/apko-1.5.5/pkg/apk/apk/cache_test.go --- old/apko-1.5.4/pkg/apk/apk/cache_test.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/cache_test.go 2026-12-02 05:58:56.000000000 +0100 @@ -276,3 +276,78 @@ require.Equal(t, 42, v) require.False(t, called) } + +// TestFlightCacheTTL checks that a completed entry is refetched once it is +// older than the TTL, while a call still in flight is shared however long it +// takes. +func TestFlightCacheTTL(t *testing.T) { + const ttl = time.Minute + s := newFlightCacheWithTTL[string, int](1, ttl) + var mux sync.Mutex + now := time.Unix(0, 0) + s.now = func() time.Time { + mux.Lock() + defer mux.Unlock() + return now + } + advance := func(d time.Duration) { + mux.Lock() + defer mux.Unlock() + now = now.Add(d) + } + + // A caller that arrives while the first call is in flight joins it, even + // after the clock has passed the TTL. + var called atomic.Int32 + started := make(chan struct{}) + release := make(chan struct{}) + first := make(chan int, 1) + go func() { + v, _, _ := s.Do("k", func() (int, error) { + called.Add(1) + close(started) + <-release + return 1, nil + }) + first <- v + }() + <-started + advance(2 * ttl) + joined := make(chan int, 1) + go func() { + v, _, _ := s.Do("k", func() (int, error) { + called.Add(1) + return 2, nil + }) + joined <- v + }() + time.Sleep(50 * time.Millisecond) // Let the second caller join the in-flight call. + close(release) + require.Equal(t, 1, <-first) + require.Equal(t, 1, <-joined) + require.EqualValues(t, 1, called.Load(), "the in-flight call is shared") + + // Within the TTL of the call completing, the result is reused. + advance(ttl - time.Second) + v, hit, err := s.Do("k", func() (int, error) { return 3, nil }) + require.NoError(t, err) + require.True(t, hit) + require.Equal(t, 1, v) + + // Once the result is older than the TTL, the next caller refetches. + advance(time.Second) + v, hit, err = s.Do("k", func() (int, error) { return 4, nil }) + require.NoError(t, err) + require.False(t, hit) + require.Equal(t, 4, v) + + // A failed refresh returns the expired value without an error and leaves + // it expired, so the next caller refreshes again. + advance(ttl) + v, _, err = s.Do("k", func() (int, error) { return 0, assert.AnError }) + require.NoError(t, err) + require.Equal(t, 4, v) + v, _, err = s.Do("k", func() (int, error) { return 5, nil }) + require.NoError(t, err) + require.Equal(t, 5, v) +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/implementation.go new/apko-1.5.5/pkg/apk/apk/implementation.go --- old/apko-1.5.4/pkg/apk/apk/implementation.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/implementation.go 2026-12-02 05:58:56.000000000 +0100 @@ -95,6 +95,11 @@ // This is a map of arch to apk.APK for every arch in a mult-arch situation. // It's stuffed here to avoid plumbing it across every method, but it's optional. ByArch map[string]*APK + + // repos is the repository list set by SetRepositories, which this APK + // resolves against. Sibling arches in ByArch read it concurrently. + reposMu sync.RWMutex + repos []string } // apkIndexDecompressedMaxSize returns the configured max decompressed APK index size or 0 for default. @@ -1304,23 +1309,16 @@ return b, nil } -// normalizeJWKSOrigin validates and canonicalizes an explicitly trusted HTTPS -// origin. Paths other than the root are not part of an origin and are rejected. +// normalizeJWKSOrigin validates and canonicalizes an explicitly trusted origin. +// Paths other than the root are not part of an origin and are rejected. func normalizeJWKSOrigin(raw string) (string, error) { u, err := url.Parse(raw) if err != nil { return "", err } - if u.Scheme != "https" || u.Host == "" || u.User != nil || u.Opaque != "" || + if (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" || u.User != nil || u.Opaque != "" || (u.Path != "" && u.Path != "/") || u.RawQuery != "" || u.Fragment != "" { - return "", fmt.Errorf("must be an HTTPS origin without user info, path, query, or fragment") - } - return httpsOrigin(u) -} - -func httpsOrigin(u *url.URL) (string, error) { - if u == nil || u.Scheme != "https" || u.Host == "" || u.Hostname() == "" { - return "", fmt.Errorf("must have an HTTPS scheme and host") + return "", fmt.Errorf("must be an HTTP(S) origin without user info, path, query, or fragment") } return canonicalHTTPOrigin(u) } @@ -1350,22 +1348,31 @@ return u.Scheme + "://" + net.JoinHostPort(host, port), nil } +// validateJWKSURI accepts an HTTPS jwks_uri on the repository's own origin or +// on an explicitly allowed origin. A plain-HTTP jwks_uri is accepted only on +// the repository's own origin, and only when that origin is explicitly +// allowed: keys fetched over plain HTTP are not protected in transit, so an +// on-path attacker could replace both them and the index they verify. func validateJWKSURI(raw string, repositoryURL *url.URL, allowedOrigins map[string]struct{}) (*url.URL, error) { u, err := url.Parse(raw) if err != nil { return nil, fmt.Errorf("failed to parse jwks_uri: %w", err) } - if u.Scheme != "https" || !u.IsAbs() || u.Host == "" || u.Hostname() == "" || u.User != nil || u.Opaque != "" || u.Fragment != "" { - return nil, fmt.Errorf("jwks_uri must be an absolute HTTPS URL without user info or fragment") - } - targetOrigin, err := httpsOrigin(u) + targetOrigin, err := canonicalHTTPOrigin(u) if err != nil { - return nil, fmt.Errorf("invalid jwks_uri origin: %w", err) + return nil, fmt.Errorf("invalid jwks_uri: %w", err) } - if repositoryOrigin, err := httpsOrigin(repositoryURL); err == nil && targetOrigin == repositoryOrigin { - return u, nil + _, allowed := allowedOrigins[targetOrigin] + if repositoryOrigin, err := canonicalHTTPOrigin(repositoryURL); err == nil && targetOrigin == repositoryOrigin { + if u.Scheme == "https" || allowed { + return u, nil + } + return nil, fmt.Errorf("plain-HTTP jwks_uri on repository origin %q requires explicitly allowing that origin", targetOrigin) + } + if u.Scheme != "https" { + return nil, fmt.Errorf("jwks_uri must be HTTPS unless it is on the repository origin") } - if _, ok := allowedOrigins[targetOrigin]; ok { + if allowed { return u, nil } return nil, fmt.Errorf("jwks_uri origin %q is not the repository origin or an explicitly allowed JWKS origin", targetOrigin) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/implementation_test.go new/apko-1.5.5/pkg/apk/apk/implementation_test.go --- old/apko-1.5.4/pkg/apk/apk/implementation_test.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/implementation_test.go 2026-12-02 05:58:56.000000000 +0100 @@ -1145,6 +1145,114 @@ require.Equal(t, "rsa-test.rsa.pub", keys[0].ID) } +func TestDiscoverKeysPlainHTTPRepository(t *testing.T) { + rsaKey, err := rsa.GenerateKey(rand.Reader, 2048) + require.NoError(t, err) + jwksBody, err := json.Marshal(jose.JSONWebKeySet{Keys: []jose.JSONWebKey{{Key: &rsaKey.PublicKey, KeyID: "rsa-test"}}}) + require.NoError(t, err) + + tests := []struct { + name string + repository string + jwksURI string + allowed []string + wantErr string + }{ + { + name: "same origin without opt-in", + jwksURI: "http://repo.example/repo/jwks", + wantErr: `plain-HTTP jwks_uri on repository origin "http://repo.example:80" requires explicitly allowing that origin`, + }, + {name: "same origin with opt-in", jwksURI: "http://repo.example/repo/jwks", allowed: []string{"http://repo.example"}}, + {name: "opt-in matches canonical origin", jwksURI: "http://Repo.Example.:80/repo/jwks", allowed: []string{"http://REPO.example:80/"}}, + { + name: "opted-in repository, other port", + jwksURI: "http://repo.example:8080/repo/jwks", + allowed: []string{"http://repo.example", "http://repo.example:8080"}, + wantErr: "jwks_uri must be HTTPS unless it is on the repository origin", + }, + { + name: "allowed HTTP origin is not a JWKS host for other repositories", + jwksURI: "http://keys.example/repo/jwks", + allowed: []string{"http://repo.example", "http://keys.example"}, + wantErr: "jwks_uri must be HTTPS unless it is on the repository origin", + }, + { + name: "HTTPS repository cannot use an allowed HTTP origin", + repository: "https://repo.example/repo", + jwksURI: "http://repo.example/repo/jwks", + allowed: []string{"http://repo.example"}, + wantErr: "jwks_uri must be HTTPS unless it is on the repository origin", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + repository := tt.repository + if repository == "" { + repository = "http://repo.example/repo" + } + jwksCalls := 0 + transport := discoverKeysRoundTripper(func(req *http.Request) (*http.Response, error) { + if req.URL.Path == "/repo/apk-configuration" { + return discoveryHTTPResponse(req, http.StatusOK, fmt.Sprintf(`{"jwks_uri":%q}`, tt.jwksURI), nil), nil + } + jwksCalls++ + return discoveryHTTPResponse(req, http.StatusOK, string(jwksBody), nil), nil + }) + + keys, err := DiscoverKeys(t.Context(), &http.Client{Transport: transport}, auth.StaticAuth("", "", ""), repository, tt.allowed...) + if tt.wantErr != "" { + require.ErrorContains(t, err, tt.wantErr) + require.Zero(t, jwksCalls, "a rejected plain-HTTP jwks_uri must not be requested") + return + } + require.NoError(t, err) + require.Len(t, keys, 1) + require.Equal(t, "rsa-test.rsa.pub", keys[0].ID) + }) + } +} + +func TestDiscoverKeysPlainHTTPRedirectRequiresOptIn(t *testing.T) { + tests := []struct { + name string + allowed []string + wantErr bool + }{ + {name: "without opt-in", allowed: []string{"https://keys.example"}, wantErr: true}, + {name: "with opt-in", allowed: []string{"https://keys.example", "http://repo.example"}}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + targetCalls := 0 + transport := discoverKeysRoundTripper(func(req *http.Request) (*http.Response, error) { + switch req.URL.String() { + case "http://repo.example/repo/apk-configuration": + return discoveryHTTPResponse(req, http.StatusOK, `{"jwks_uri":"https://keys.example/jwks"}`, nil), nil + case "https://keys.example/jwks": + return discoveryHTTPResponse(req, http.StatusFound, "", http.Header{"Location": []string{"http://repo.example/keys"}}), nil + case "http://repo.example/keys": + targetCalls++ + return discoveryHTTPResponse(req, http.StatusOK, `{"keys":[]}`, nil), nil + default: + return nil, fmt.Errorf("unexpected request to %s", req.URL) + } + }) + + _, err := DiscoverKeys(t.Context(), &http.Client{Transport: transport}, auth.StaticAuth("", "", ""), "http://repo.example/repo", tt.allowed...) + if tt.wantErr { + require.ErrorContains(t, err, "requires explicitly allowing that origin") + require.Zero(t, targetCalls, "an HTTPS JWKS must not redirect to plain HTTP without opt-in") + return + } + require.NoError(t, err) + require.Equal(t, 1, targetCalls) + }) + } +} + type discoverKeysRoundTripper func(*http.Request) (*http.Response, error) func (rt discoverKeysRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { @@ -1295,7 +1403,7 @@ name string origin string }{ - {name: "HTTP scheme", origin: "http://keys.example"}, + {name: "unsupported scheme", origin: "ftp://keys.example"}, {name: "userinfo", origin: "https://user:[email protected]"}, {name: "path", origin: "https://keys.example/jwks"}, {name: "query", origin: "https://keys.example?token=secret"}, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/options.go new/apko-1.5.5/pkg/apk/apk/options.go --- old/apko-1.5.4/pkg/apk/apk/options.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/options.go 2026-12-02 05:58:56.000000000 +0100 @@ -157,8 +157,11 @@ } // WithJWKSAllowedOrigins allows key discovery to fetch JWKS documents from -// HTTPS origins other than the repository origin. Origins must include the -// scheme and may not include a path, query, fragment, or user information. +// HTTPS origins other than the repository origin. An HTTP origin instead +// allows a plain-HTTP repository on that same origin to serve its own JWKS +// over plain HTTP; it never allows other repositories to use it. Origins must +// include the scheme and may not include a path, query, fragment, or user +// information. func WithJWKSAllowedOrigins(origins ...string) Option { return func(o *opts) error { for _, origin := range origins { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/repo.go new/apko-1.5.5/pkg/apk/apk/repo.go --- old/apko-1.5.4/pkg/apk/apk/repo.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/repo.go 2026-12-02 05:58:56.000000000 +0100 @@ -99,7 +99,8 @@ pinnedName string } -// SetRepositories sets the contents of /etc/apk/repositories file. +// SetRepositories sets the repositories this APK resolves against and writes +// them to /etc/apk/repositories. // The base directory of /etc/apk must already exist, i.e. this only works on an initialized APK database. func (a *APK) SetRepositories(ctx context.Context, repos []string) error { ctx, span := otel.Tracer("go-apk").Start(ctx, "SetRepositories") @@ -107,6 +108,29 @@ clog.DebugContextf(ctx, "setting apk repositories: %v", repos) + if err := a.writeRepositories(repos); err != nil { + return err + } + + a.reposMu.Lock() + defer a.reposMu.Unlock() + a.repos = slices.Clone(repos) + + return nil +} + +// WriteRuntimeRepositories writes repos to /etc/apk/repositories for the final +// image, without changing the repositories this APK resolves against. Sibling +// arches in ByArch may still be resolving against them. +func (a *APK) WriteRuntimeRepositories(ctx context.Context, repos []string) error { + ctx, span := otel.Tracer("go-apk").Start(ctx, "WriteRuntimeRepositories") + defer span.End() + + clog.DebugContextf(ctx, "writing runtime apk repositories: %v", repos) + return a.writeRepositories(repos) +} + +func (a *APK) writeRepositories(repos []string) error { if len(repos) == 0 { return fmt.Errorf("must provide at least one repository") } @@ -122,7 +146,17 @@ return nil } +// GetRepositories returns the repositories this APK resolves against: the ones +// set by SetRepositories, or the contents of /etc/apk/repositories if it wasn't +// called, e.g. when operating on an existing root. func (a *APK) GetRepositories() (repos []string, err error) { + a.reposMu.RLock() + repos = slices.Clone(a.repos) + a.reposMu.RUnlock() + if repos != nil { + return repos, nil + } + // get the repository URLs reposFile, err := a.fs.Open(reposFilePath) if err != nil { @@ -805,6 +839,32 @@ return toInstall, conflicts, nil } +// originVersions records every version of each origin that has been selected +// so far. One origin can be selected at more than one version, for example +// libicu78 and libicu79 from the icu origin during a soname transition, so a +// single version per origin would depend on which package was recorded last. +type originVersions map[string]map[string]struct{} + +func (o originVersions) add(origin, version string) { + if origin == "" { + return + } + versions, ok := o[origin] + if !ok { + versions = map[string]struct{}{} + o[origin] = versions + } + versions[version] = struct{}{} +} + +func (o originVersions) has(origin, version string) bool { + if origin == "" { + return false + } + _, ok := o[origin][version] + return ok +} + // GetPackageWithDependencies get all of the dependencies for a single package as well as looking // up the package itself and resolving its version, based on the indexes. // Requires the existing set because the logic for resolving dependencies between competing @@ -813,11 +873,11 @@ func (p *PkgResolver) GetPackageWithDependencies(ctx context.Context, pkgName string, existing map[string]*RepositoryPackage, dq map[*RepositoryPackage]string) (*RepositoryPackage, []*RepositoryPackage, []string, error) { parents := make(map[string]bool) localExisting := make(map[string]*RepositoryPackage, len(existing)) - existingOrigins := map[string]string{} + existingOrigins := originVersions{} for k, v := range existing { localExisting[k] = v - if v != nil && v.Origin != "" { - existingOrigins[v.Origin] = v.Version + if v != nil { + existingOrigins.add(v.Origin, v.Version) } } @@ -956,7 +1016,7 @@ // It might change the order of install. // In other words, this _should_ be a DAG (acyclical), but because the packages // are just listing dependencies in text, it might be cyclical. We need to be careful of that. -func (p *PkgResolver) getPackageDependencies(ctx context.Context, pkg *RepositoryPackage, allowPin string, parents map[string]bool, existing map[string]*RepositoryPackage, existingOrigins map[string]string, dq map[*RepositoryPackage]string) (dependencies []*RepositoryPackage, conflicts []string, err error) { +func (p *PkgResolver) getPackageDependencies(ctx context.Context, pkg *RepositoryPackage, allowPin string, parents map[string]bool, existing map[string]*RepositoryPackage, existingOrigins originVersions, dq map[*RepositoryPackage]string) (dependencies []*RepositoryPackage, conflicts []string, err error) { if err := ctx.Err(); err != nil { return nil, nil, context.Cause(ctx) } @@ -1146,9 +1206,7 @@ conflicts = append(conflicts, confs...) for _, dep := range subDeps { existing[dep.Name] = dep - if dep.Origin != "" { - existingOrigins[dep.Origin] = dep.Version - } + existingOrigins.add(dep.Origin, dep.Version) } } return dependencies, conflicts, nil @@ -1190,11 +1248,11 @@ // For example, if the original search was for package "a", then pkgs may contain some that // are named "a", but others that provided "a". In that case, we should look not at the // version of the package, but the version of "a" that the package provides. -func (p *PkgResolver) sortPackages(pkgs []*repositoryPackage, compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins map[string]string, pin string) { +func (p *PkgResolver) sortPackages(pkgs []*repositoryPackage, compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins originVersions, pin string) { slices.SortFunc(pkgs, p.comparePackages(compare, name, existing, existingOrigins, pin)) } -func (p *PkgResolver) comparePackages(compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins map[string]string, pin string) func(a, b *repositoryPackage) int { //nolint:gocyclo +func (p *PkgResolver) comparePackages(compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins originVersions, pin string) func(a, b *repositoryPackage) int { //nolint:gocyclo return func(a, b *repositoryPackage) int { // determine versions iVersionStr := p.getDepVersionForName(a, name) @@ -1240,8 +1298,8 @@ // the version we pulled in. Otherwise this heuristic would keep us on // an older version of an origin (e.g. when a package moves origins at // a newer version, or an old binary lingers in the index after rebuild). - iOriginMatched := a.Origin != "" && existingOrigins[a.Origin] == a.Version - jOriginMatched := b.Origin != "" && existingOrigins[b.Origin] == b.Version + iOriginMatched := existingOrigins.has(a.Origin, a.Version) + jOriginMatched := existingOrigins.has(b.Origin, b.Version) if iOriginMatched && !jOriginMatched { return -1 } @@ -1335,7 +1393,7 @@ } } -func (p *PkgResolver) bestPackage(pkgs []*repositoryPackage, compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins map[string]string, pin string) *repositoryPackage { +func (p *PkgResolver) bestPackage(pkgs []*repositoryPackage, compare *RepositoryPackage, name string, existing map[string]*RepositoryPackage, existingOrigins originVersions, pin string) *repositoryPackage { if len(pkgs) == 0 { return nil } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/repo_test.go new/apko-1.5.5/pkg/apk/apk/repo_test.go --- old/apko-1.5.4/pkg/apk/apk/repo_test.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/repo_test.go 2026-12-02 05:58:56.000000000 +0100 @@ -771,7 +771,7 @@ pkgs []*RepositoryPackage pkg *RepositoryPackage existing = map[string]*RepositoryPackage{} - existingOrigins = map[string]string{} + existingOrigins = originVersions{} ) for _, pkg := range tt.pkgs { // we cheat and use the InstalledSize for the preferred order, so that it gets carried around. @@ -785,7 +785,7 @@ } for _, pkg := range tt.existing { existing[pkg.pkg.Name] = NewRepositoryPackage(pkg.pkg, &RepositoryWithIndex{Repository: &Repository{URI: pkg.repo}}) - existingOrigins[pkg.pkg.Origin] = pkg.pkg.Version + existingOrigins.add(pkg.pkg.Origin, pkg.pkg.Version) } namedPkgs := testNamedPackageFromPackages(pkgs) pr := NewPkgResolver(context.Background(), []NamedIndex{}) @@ -1009,6 +1009,55 @@ require.NotContains(t, got, "py3.10-pybind11-2.13.6-r1.apk", "should not select the stale higher-priority build") } +// An origin can be selected at two versions at once, here icu 79.1 (via +// dotnet-runtime) and libicu78 from icu 78.3 (via libre2) during a soname +// transition. The same-origin heuristic must then accept either version +// instead of whichever was recorded last, or it picks icu-dev 78.3, which +// needs icu 78.3 and conflicts with the installed icu 79.1. +// https://github.com/chainguard-dev/apko/issues/2607 +func TestSameOriginSelectedAtTwoVersions(t *testing.T) { + repo := Repository{} + index := repo.WithIndex(&APKIndex{ + Packages: []*Package{ + {Name: "icu", Version: "79.1-r0", Origin: "icu", Provides: []string{"cmd:derb=79.1-r0"}, Dependencies: []string{"libicu79"}}, + {Name: "libicu79", Version: "79.1-r0", Origin: "icu", Provides: []string{"so:libicuuc.so.79=79"}}, + {Name: "icu-dev", Version: "79.1-r0", Origin: "icu", Dependencies: []string{"icu", "so:libicuuc.so.79"}}, + {Name: "icu", Version: "78.3-r4", Origin: "icu", Provides: []string{"cmd:derb=78.3-r4", "so:libicutest.so.78=78"}, Dependencies: []string{"libicu78"}}, + {Name: "libicu78", Version: "78.3-r4", Origin: "icu", Provides: []string{"so:libicuuc.so.78=78"}}, + {Name: "icu-dev", Version: "78.3-r4", Origin: "icu", Dependencies: []string{"icu", "so:libicutest.so.78"}}, + {Name: "dotnet-runtime", Version: "10.0-r0", Origin: "dotnet", Dependencies: []string{"icu"}}, + {Name: "libre2", Version: "1-r0", Origin: "re2", Dependencies: []string{"so:libicuuc.so.78"}}, + {Name: "re2-dev", Version: "1-r0", Origin: "re2", Dependencies: []string{"icu-dev", "libre2"}}, + }, + }) + for _, names := range [][]string{ + // existing holds icu 79.1 and libicu78 78.3 when re2-dev is resolved, + // so the recorded icu version depended on map iteration order. + {"dotnet-runtime", "libre2", "re2-dev"}, + // libre2 is resolved inside the re2-dev walk and recorded icu 78.3 + // last, so this failed every time. + {"dotnet-runtime", "re2-dev"}, + } { + t.Run(strings.Join(names, ","), func(t *testing.T) { + // The first case depends on map iteration order, so repeat it. + for range 50 { + resolver := NewPkgResolver(context.Background(), testNamedRepositoryFromIndexes([]*RepositoryWithIndex{index})) + pkgs, _, err := resolver.GetPackagesWithDependencies(context.Background(), names, nil) + require.NoError(t, err) + + got := make([]string, 0, len(pkgs)) + for _, p := range pkgs { + got = append(got, p.Filename()) + } + require.Contains(t, got, "icu-79.1-r0.apk") + require.Contains(t, got, "icu-dev-79.1-r0.apk") + require.Contains(t, got, "libicu78-78.3-r4.apk") + require.Contains(t, got, "libicu79-79.1-r0.apk") + } + }) + } +} + // Provider priority arbitrates between different packages providing the same // virtual name. It must not arbitrate between builds of the named package // itself: there, the higher version wins, regardless of what priority each diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/apk/apk/version_test.go new/apko-1.5.5/pkg/apk/apk/version_test.go --- old/apko-1.5.4/pkg/apk/apk/version_test.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/apk/apk/version_test.go 2026-12-02 05:58:56.000000000 +0100 @@ -910,10 +910,10 @@ found := filterPackages(pkgs, map[*RepositoryPackage]string{}, withVersion(tt.version, tt.compare), withPreferPin(tt.pin), withInstalledPackage(tt.installed)) // add the existing in, if any existing := make(map[string]*RepositoryPackage) - existingOrigins := make(map[string]string) + existingOrigins := originVersions{} if tt.installed != nil { existing[tt.installed.Name] = tt.installed - existingOrigins[tt.installed.Origin] = tt.installed.Version + existingOrigins.add(tt.installed.Origin, tt.installed.Version) } pkg := pr.bestPackage(found, nil, "", existing, existingOrigins, tt.pin) if tt.want == "" { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/build/apk.go new/apko-1.5.5/pkg/build/apk.go --- old/apko-1.5.4/pkg/build/apk.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/build/apk.go 2026-12-02 05:58:56.000000000 +0100 @@ -34,8 +34,8 @@ Insert(bc.ic.Contents.RuntimeOnlyRepositories...). Insert(bc.o.ExtraRepos...) runtimeRepos := sets.List(runtimeRepoSet) - if err := bc.apk.SetRepositories(ctx, runtimeRepos); err != nil { - return fmt.Errorf("failed to set apk repositories: %w", err) + if err := bc.apk.WriteRuntimeRepositories(ctx, runtimeRepos); err != nil { + return fmt.Errorf("failed to write apk repositories: %w", err) } regularRuntimeRepos := sets.List(sets.New(bc.ic.Contents.Repositories...).Insert(bc.o.ExtraRepos...)) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/build/multi_test.go new/apko-1.5.5/pkg/build/multi_test.go --- old/apko-1.5.4/pkg/build/multi_test.go 1970-01-01 01:00:00.000000000 +0100 +++ new/apko-1.5.5/pkg/build/multi_test.go 2026-12-02 05:58:56.000000000 +0100 @@ -0,0 +1,78 @@ +// Copyright 2026 Chainguard, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package build + +import ( + "io" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + + "chainguard.dev/apko/pkg/apk/apk" + "chainguard.dev/apko/pkg/build/types" +) + +// TestMultiArchSiblingFinishedFirst checks that an arch can still resolve +// packages that only exist in a build repository after a sibling arch has +// finished its build and rewritten its repositories file to the runtime +// repositories. +func TestMultiArchSiblingFinishedFirst(t *testing.T) { + ctx := t.Context() + + buildRepo, err := filepath.Abs("testdata/packages") + require.NoError(t, err) + + // A runtime repository that doesn't contain the requested package. + runtimeRepo := t.TempDir() + for _, arch := range []string{"x86_64", "aarch64"} { + archive, err := apk.ArchiveFromIndex(&apk.APKIndex{}) + require.NoError(t, err) + require.NoError(t, os.MkdirAll(filepath.Join(runtimeRepo, arch), 0o755)) + f, err := os.Create(filepath.Join(runtimeRepo, arch, "APKINDEX.tar.gz")) + require.NoError(t, err) + _, err = io.Copy(f, archive) + require.NoError(t, err) + require.NoError(t, f.Close()) + } + + archs := []types.Architecture{types.ParseArchitecture("amd64"), types.ParseArchitecture("arm64")} + ma, err := NewMultiArch(ctx, archs, + WithImageConfiguration(types.ImageConfiguration{ + Contents: types.ImageContents{ + BuildRepositories: []string{buildRepo}, + Repositories: []string{runtimeRepo}, + Packages: []string{"pretend-baselayout"}, + }, + }), + WithIgnoreSignatures(true), + WithoutDiskCache(), + ) + require.NoError(t, err) + + // Build the first arch to completion, so the second one resolves after + // its sibling rewrote the repositories file to the runtime repositories. + first := ma.Contexts[archs[0]] + _, _, err = first.BuildLayer(ctx) + require.NoError(t, err) + + repos, err := first.fs.ReadFile("etc/apk/repositories") + require.NoError(t, err) + require.Equal(t, runtimeRepo+"\n", string(repos)) + + _, _, err = ma.Contexts[archs[1]].BuildLayer(ctx) + require.NoError(t, err) +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/apko-1.5.4/pkg/build/options.go new/apko-1.5.5/pkg/build/options.go --- old/apko-1.5.4/pkg/build/options.go 2026-11-28 18:42:21.000000000 +0100 +++ new/apko-1.5.5/pkg/build/options.go 2026-12-02 05:58:56.000000000 +0100 @@ -316,8 +316,10 @@ } } -// WithJWKSAllowedOrigins trusts additional HTTPS origins for repository key -// discovery. Use this for mirrors that publish their JWKS on a separate host. +// WithJWKSAllowedOrigins trusts additional origins for repository key +// discovery. Use an HTTPS origin for mirrors that publish their JWKS on a +// separate host, or the repository's own HTTP origin to let a plain-HTTP +// repository serve its JWKS over plain HTTP. func WithJWKSAllowedOrigins(origins ...string) Option { return func(bc *Context) error { bc.o.JWKSAllowedOrigins = append(bc.o.JWKSAllowedOrigins, origins...) ++++++ apko.obsinfo ++++++ --- /var/tmp/diff_new_pack.BGNBrT/_old 2026-12-03 14:00:45.622010746 +0100 +++ /var/tmp/diff_new_pack.BGNBrT/_new 2026-12-03 14:00:45.626010916 +0100 @@ -1,5 +1,5 @@ name: apko -version: 1.5.4 -mtime: 1795887741 -commit: 0408833b19c8187e2d2329d7cb47e610356225cd +version: 1.5.5 +mtime: 1796187536 +commit: c3556e6b16584ac2fe90b6b8a63d1ad8f1a4d46c ++++++ vendor.tar.gz ++++++ /work/SRC/openSUSE:Factory/apko/vendor.tar.gz /work/SRC/openSUSE:Factory/.apko.new.1340718/vendor.tar.gz differ: char 135, line 1
