Skip to content

Commit 286e206

Browse files
authored
Merge branch 'distribution:main' into main
2 parents afb1fd1 + 63d3892 commit 286e206

File tree

13 files changed

+167
-25
lines changed

13 files changed

+167
-25
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
fail-fast: false
3434
matrix:
3535
go:
36-
- 1.22.8
37-
- 1.23.4
36+
- 1.22.12
37+
- 1.23.6
3838
target:
3939
- test-coverage
4040
- test-cloud-storage

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG GO_VERSION=1.23.4
3+
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
55
ARG XX_VERSION=1.6.1
66

dockerfiles/docs.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG GO_VERSION=1.23.4
3+
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
55

66
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base

dockerfiles/git.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG GO_VERSION=1.23.4
3+
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
55

66
FROM alpine:${ALPINE_VERSION} AS base

dockerfiles/lint.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG GO_VERSION=1.23.4
3+
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
55
ARG GOLANGCI_LINT_VERSION=v1.61.0
66
ARG BUILDTAGS=""

dockerfiles/vendor.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
ARG GO_VERSION=1.23.4
3+
ARG GO_VERSION=1.23.6
44
ARG ALPINE_VERSION=3.21
55
ARG MODOUTDATED_VERSION=v0.8.0
66

docs/content/about/garbage-collection.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ This type of garbage collection is known as stop-the-world garbage collection.
9090

9191
Garbage collection can be run as follows
9292

93-
`bin/registry garbage-collect [--dry-run] /path/to/config.yml`
93+
`bin/registry garbage-collect [--dry-run] [--delete-untagged] [--quiet] /path/to/config.yml`
9494

9595
The garbage-collect command accepts a `--dry-run` parameter, which prints the progress
9696
of the mark and sweep phases without removing any data. Running with a log level of `info`
@@ -122,3 +122,8 @@ blob eligible for deletion: sha256:87192bdbe00f8f2a62527f36bb4c7c7f4eaf9307e4b87
122122
blob eligible for deletion: sha256:b549a9959a664038fc35c155a95742cf12297672ca0ae35735ec027d55bf4e97
123123
blob eligible for deletion: sha256:f251d679a7c61455f06d793e43c06786d7766c88b8c24edf242b2c08e3c3f599
124124
```
125+
126+
The `--delete-untagged` option can be used to delete manifests that are not currently referenced by a tag.
127+
128+
The `--quiet` option suppresses any output from being printed.
129+

registry/auth/token/token.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,18 @@ func verifyCertChain(header jose.Header, roots *x509.CertPool) (signingKey crypt
212212
return
213213
}
214214

215-
func verifyJWK(header jose.Header, verifyOpts VerifyOptions) (signingKey crypto.PublicKey, err error) {
215+
func verifyJWK(header jose.Header, verifyOpts VerifyOptions) (crypto.PublicKey, error) {
216216
jwk := header.JSONWebKey
217-
signingKey = jwk.Key
218217

219218
// Check to see if the key includes a certificate chain.
220219
if len(jwk.Certificates) == 0 {
221220
// The JWK should be one of the trusted root keys.
222-
if _, trusted := verifyOpts.TrustedKeys[jwk.KeyID]; !trusted {
221+
key, trusted := verifyOpts.TrustedKeys[jwk.KeyID]
222+
if !trusted {
223223
return nil, errors.New("untrusted JWK with no certificate chain")
224224
}
225225
// The JWK is one of the trusted keys.
226-
return
226+
return key, nil
227227
}
228228

229229
opts := x509.VerifyOptions{
@@ -245,9 +245,8 @@ func verifyJWK(header jose.Header, verifyOpts VerifyOptions) (signingKey crypto.
245245
if err != nil {
246246
return nil, err
247247
}
248-
signingKey = getCertPubKey(chains)
249248

250-
return
249+
return getCertPubKey(chains), nil
251250
}
252251

253252
func getCertPubKey(chains [][]*x509.Certificate) crypto.PublicKey {

registry/auth/token/token_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,3 +646,57 @@ func TestNewAccessControllerPemBlock(t *testing.T) {
646646
t.Fatal("accessController has the wrong number of certificates")
647647
}
648648
}
649+
650+
// This test makes sure the untrusted key can not be used in token verification.
651+
func TestVerifyJWKWithTrustedKey(t *testing.T) {
652+
// Generate a test key pair
653+
privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
654+
if err != nil {
655+
t.Fatal(err)
656+
}
657+
pubKey := privKey.Public()
658+
659+
// Create a JWK with no certificates
660+
jwk := &jose.JSONWebKey{
661+
Key: privKey,
662+
KeyID: "test-key-id",
663+
Use: "sig",
664+
Algorithm: string(jose.ES256),
665+
}
666+
667+
// Create verify options with our public key as trusted
668+
verifyOpts := VerifyOptions{
669+
TrustedKeys: map[string]crypto.PublicKey{
670+
"test-key-id": pubKey,
671+
},
672+
}
673+
674+
// Create test header
675+
header := jose.Header{
676+
JSONWebKey: jwk,
677+
}
678+
679+
// Test the verifyJWK function
680+
returnedKey, err := verifyJWK(header, verifyOpts)
681+
if err != nil {
682+
t.Fatalf("Expected no error, got: %v", err)
683+
}
684+
685+
// Verify the returned key matches our trusted key
686+
if returnedKey != pubKey {
687+
t.Error("Returned key does not match the trusted key")
688+
}
689+
690+
// Test with untrusted key
691+
verifyOpts.TrustedKeys = map[string]crypto.PublicKey{
692+
"different-key-id": pubKey,
693+
}
694+
695+
_, err = verifyJWK(header, verifyOpts)
696+
if err == nil {
697+
t.Error("Expected error for untrusted key, got none")
698+
}
699+
if err.Error() != "untrusted JWK with no certificate chain" {
700+
t.Errorf("Expected 'untrusted JWK with no certificate chain' error, got: %v", err)
701+
}
702+
}

registry/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
RootCmd.AddCommand(GCCmd)
1919
GCCmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "do everything except remove the blobs")
2020
GCCmd.Flags().BoolVarP(&removeUntagged, "delete-untagged", "m", false, "delete manifests that are not currently referenced via tag")
21+
GCCmd.Flags().BoolVarP(&quiet, "quiet", "q", false, "silence output")
2122
RootCmd.Flags().BoolVarP(&showVersion, "version", "v", false, "show the version and exit")
2223
}
2324

@@ -39,6 +40,7 @@ var RootCmd = &cobra.Command{
3940
var (
4041
dryRun bool
4142
removeUntagged bool
43+
quiet bool
4244
)
4345

4446
// GCCmd is the cobra command that corresponds to the garbage-collect subcommand
@@ -77,6 +79,7 @@ var GCCmd = &cobra.Command{
7779
err = storage.MarkAndSweep(ctx, driver, registry, storage.GCOpts{
7880
DryRun: dryRun,
7981
RemoveUntagged: removeUntagged,
82+
Quiet: quiet,
8083
})
8184
if err != nil {
8285
fmt.Fprintf(os.Stderr, "failed to garbage collect: %v", err)

0 commit comments

Comments
 (0)