Skip to content

Commit ae9cabf

Browse files
committed
chore: address review comments, add key length check, updates ut's
Signed-off-by: Chiman Jain <chimanjain15@gmail.com>
1 parent 0e7a4bb commit ae9cabf

9 files changed

Lines changed: 39 additions & 10 deletions

File tree

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 {

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

local-dev/clair/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ updaters:
1111
- osv
1212
auth:
1313
psk:
14-
key: 'c2VjcmV0'
14+
key: 'c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U='
1515
iss:
1616
- quay
1717
- clairctl

local-dev/quay/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ REPO_MIRROR_SERVER_HOSTNAME: null
4949
REPO_MIRROR_TLS_VERIFY: true
5050
SECURITY_SCANNER_V4_ENDPOINT: http://clair-traefik:6060
5151
SECURITY_SCANNER_ISSUER_NAME: quay
52-
SECURITY_SCANNER_V4_PSK: 'c2VjcmV0'
52+
SECURITY_SCANNER_V4_PSK: 'c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2VjcmV0c2U='
5353
SERVER_HOSTNAME: clair-quay:8080
5454
SETUP_COMPLETE: true
5555
SIGNING_ENGINE: gpg2

0 commit comments

Comments
 (0)