Skip to content

Commit fe8b741

Browse files
committed
chore: upgrade go-jose to v4 and update JWT serialization methods
Signed-off-by: Chiman Jain <chimanjain15@gmail.com>
1 parent 33676f0 commit fe8b741

19 files changed

Lines changed: 64 additions & 31 deletions

File tree

cmd/clairctl/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"os"
88
"runtime/debug"
99

10-
"github.com/go-jose/go-jose/v3/jwt"
10+
"github.com/go-jose/go-jose/v4/jwt"
1111
"github.com/quay/clair/config"
1212
_ "github.com/quay/claircore/updater/defaults"
1313
"github.com/urfave/cli/v2"

cmd/testdata/ComplexYAML/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ updaters:
1010
- alpine
1111
auth:
1212
psk:
13-
key: 'c2VjcmV0'
13+
key: 'c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U='
1414
iss:
1515
- quay
1616
- clairctl

cmd/testdata/ComplexYAML/want.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"auth": {
1212
"psk": {
13-
"key": "c2VjcmV0",
13+
"key": "c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U=",
1414
"iss": [
1515
"quay",
1616
"clairctl"

cmd/testdata/SimpleYAML/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ updaters:
1010
- alpine
1111
auth:
1212
psk:
13-
key: 'c2VjcmV0'
13+
key: 'c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U='
1414
iss:
1515
- quay
1616
- clairctl

cmd/testdata/SimpleYAML/want.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"auth": {
1414
"psk": {
15-
"key": "c2VjcmV0",
15+
"key": "c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U=",
1616
"iss": [
1717
"quay",
1818
"clairctl"

config/auth.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func (a *AuthPSK) validate(_ Mode) ([]Warning, error) {
8686
msg: "key is empty",
8787
}
8888
}
89+
if len(a.Key) < 32 {
90+
return nil, &Warning{
91+
msg: "key is too short: must be at least 32 bytes",
92+
}
93+
}
8994
if len(a.Issuer) == 0 {
9095
return nil, &Warning{
9196
path: ".iss",

config/config_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ func TestValidateFailure(t *testing.T) {
3939
}
4040
}
4141

42+
expectError := func(want string) func(*testing.T, *config.Config, error) {
43+
return func(t *testing.T, _ *config.Config, err error) {
44+
if err == nil {
45+
t.Fatal("unexpected success")
46+
}
47+
if got := err.Error(); got != want {
48+
t.Errorf("got error %q, want %q", got, want)
49+
}
50+
}
51+
}
52+
4253
// Tests on the base Config struct.
4354
tt := []ValidateTestcase{
4455
{
@@ -90,19 +101,32 @@ func TestValidateFailure(t *testing.T) {
90101
PSK: &config.AuthPSK{},
91102
},
92103
},
93-
Check: shouldFail,
104+
Check: expectError("key is empty (at )"),
105+
},
106+
{
107+
Name: "BadPSKKeyLen",
108+
Conf: config.Config{
109+
Mode: config.IndexerMode,
110+
Auth: config.Auth{
111+
PSK: &config.AuthPSK{
112+
Key: config.Base64([]byte{0xde, 0xad, 0xbe, 0xef}),
113+
Issuer: []string{"iss"},
114+
},
115+
},
116+
},
117+
Check: expectError("key is too short: must be at least 32 bytes (at )"),
94118
},
95119
{
96120
Name: "BadPSKIssuer",
97121
Conf: config.Config{
98122
Mode: config.IndexerMode,
99123
Auth: config.Auth{
100124
PSK: &config.AuthPSK{
101-
Key: config.Base64([]byte{0xde, 0xad, 0xbe, 0xef}),
125+
Key: config.Base64([]byte("deadbeefdeadbeefdeadbeefdeadbeef")),
102126
},
103127
},
104128
},
105-
Check: shouldFail,
129+
Check: expectError("no issuers defined (at .iss)"),
106130
},
107131
}
108132
for _, tc := range tt {

contrib/cmd/quaybackstop/clair.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/quay/clair/v4/cmd"
2323

24-
"github.com/go-jose/go-jose/v3"
24+
"github.com/go-jose/go-jose/v4"
2525
"github.com/jackc/pgx/v5"
2626
"github.com/jackc/pgx/v5/pgxpool"
2727
"github.com/quay/clair/config"

contrib/cmd/quaybackstop/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
"sync"
3535
"time"
3636

37-
"github.com/go-jose/go-jose/v3"
38-
"github.com/go-jose/go-jose/v3/jwt"
37+
"github.com/go-jose/go-jose/v4"
38+
"github.com/go-jose/go-jose/v4/jwt"
3939
"github.com/jackc/pgx/v5/pgxpool"
4040
"github.com/quay/clair/config"
4141
)
@@ -291,7 +291,7 @@ func (a *App) NewRequestWithContext(ctx context.Context, method string, url *url
291291
cl.NotBefore = jwt.NewNumericDate(now.Add(-jwt.DefaultLeeway))
292292
a.clairTokenResign = now.Add(15 * time.Minute)
293293
cl.Expiry = jwt.NewNumericDate(a.clairTokenResign)
294-
tok, err := jwt.Signed(a.jwtSigner).Claims(&cl).CompactSerialize()
294+
tok, err := jwt.Signed(a.jwtSigner).Claims(&cl).Serialize()
295295
if err != nil {
296296
return nil, fmt.Errorf("jwt construction: %w", err)
297297
}

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ services:
172172
- ./notifier/webhook/cmd/webhookd
173173
- -D
174174
- -key
175-
- c2VjcmV0
175+
- c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U=
176176
rabbitmq:
177177
# This provides STOMP and AMQP on the usual ports.
178178
# The web UI is available on /rabbitmq

0 commit comments

Comments
 (0)