Skip to content

Commit d61a505

Browse files
committed
fix(backups): refuse to probe a Redis snapshot behind a CA that is gone
The default strategy mounts the s3-ca volume only when the admin configured an endpoint CA, and the script then trusts that CA alone. When the volume yields no CA by the time the probe runs, because the Secret was deleted or emptied after the Job or the volume has another source, the probe used to fall back to the system roots, trusting more than the Job may have. It now leaves the artifact unset instead, with or without skip-verify. Assisted-by: LLM Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 43bed8f commit d61a505

2 files changed

Lines changed: 29 additions & 35 deletions

File tree

‎internal/backupcontroller/redis_artifact_size.go‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ const (
9090
// when neither exists does it honour S3_INSECURE_SKIP_VERIFY=true. Both are
9191
// read from the pod spec the backup Job ran with, but the Secret is read
9292
// now, so an s3-ca volume that yields no CA now - a Secret that is gone or
93-
// lacks the keys, or a source other than a Secret - never lets the probe
94-
// skip verification: the Job may have verified against it. Without
95-
// skip-verify such a volume leaves the system roots, as in the script,
96-
// which mounts it optionally.
93+
// lacks the keys, or a source other than a Secret - is refused: the Job may
94+
// have verified against a CA that is gone, and neither the system roots nor
95+
// skip-verify would trust as narrowly. The default strategy mounts s3-ca
96+
// only when the admin configured an endpoint CA.
9797
func (r *BackupJobReconciler) redisS3Trust(ctx context.Context, namespace string, podSpec *corev1.PodSpec) ([]byte, bool, error) {
9898
if podSpec == nil {
9999
return nil, false, nil
@@ -123,13 +123,10 @@ func (r *BackupJobReconciler) redisS3Trust(ctx context.Context, namespace string
123123
}
124124
caUnknown = true
125125
}
126-
if !redisSkipsVerify(podSpec.Containers) {
127-
return nil, false, nil
128-
}
129126
if caUnknown {
130-
return nil, false, fmt.Errorf("the %s volume yields no CA now; not skipping TLS verification in its place", redisS3CAVolume)
127+
return nil, false, fmt.Errorf("the %s volume yields no CA now", redisS3CAVolume)
131128
}
132-
return nil, true, nil
129+
return nil, redisSkipsVerify(podSpec.Containers), nil
133130
}
134131

135132
// redisSkipsVerify reports whether every container sets

‎internal/backupcontroller/redis_artifact_size_test.go‎

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ func TestRedisS3Trust(t *testing.T) {
218218
objs: []client.Object{caSecret(map[string]string{"bundle.pem": "MAPPED", "ca.crt": "UNMAPPED"})},
219219
wantCA: "MAPPED",
220220
},
221-
"missing CA Secret falls back to the system roots": {
222-
spec: redisPodSpec("s3-endpoint-ca", ""),
223-
},
224221
"skip-verify without a CA volume": {
225222
spec: redisPodSpec("", "true"),
226223
wantSkip: true,
@@ -256,31 +253,31 @@ func TestRedisS3Trust(t *testing.T) {
256253
{Name: "S3_INSECURE_SKIP_VERIFY", Value: "false"},
257254
}}}},
258255
},
259-
"an s3-ca volume of another source leaves the system roots": {
260-
spec: configMapS3CA(redisPodSpec("", "")),
261-
},
262256
}
263-
t.Run("an s3-ca volume of another source never turns into skip-verify", func(t *testing.T) {
264-
r := &BackupJobReconciler{Client: newMariaDBStrategyTestClient(t)}
265-
ca, skip, err := r.redisS3Trust(context.Background(), "tenant", configMapS3CA(redisPodSpec("", "true")))
266-
if err == nil || skip || ca != nil {
267-
t.Errorf("trust = (%q, %v, %v), want an error and no skip-verify", ca, skip, err)
268-
}
269-
})
270-
t.Run("a mounted CA Secret without CA keys never turns into skip-verify", func(t *testing.T) {
271-
r := &BackupJobReconciler{Client: newMariaDBStrategyTestClient(t, caSecret(map[string]string{"other": "x"}))}
272-
ca, skip, err := r.redisS3Trust(context.Background(), "tenant", redisPodSpec("s3-endpoint-ca", "true"))
273-
if err == nil || skip || ca != nil {
274-
t.Errorf("trust = (%q, %v, %v), want an error and no skip-verify", ca, skip, err)
275-
}
276-
})
277-
t.Run("a mounted CA Secret that is gone never turns into skip-verify", func(t *testing.T) {
278-
r := &BackupJobReconciler{Client: newMariaDBStrategyTestClient(t)}
279-
ca, skip, err := r.redisS3Trust(context.Background(), "tenant", redisPodSpec("s3-endpoint-ca", "true"))
280-
if err == nil || skip || ca != nil {
281-
t.Errorf("trust = (%q, %v, %v), want an error and no skip-verify", ca, skip, err)
257+
// Each s3-ca volume that yields no CA now is refused, with or without
258+
// skip-verify: the Job may have verified against a CA that is gone.
259+
refused := map[string]struct {
260+
spec func(skip string) *corev1.PodSpec
261+
objs []client.Object
262+
}{
263+
"a CA Secret that is gone": {spec: func(skip string) *corev1.PodSpec { return redisPodSpec("s3-endpoint-ca", skip) }},
264+
"a CA Secret without CA keys": {
265+
spec: func(skip string) *corev1.PodSpec { return redisPodSpec("s3-endpoint-ca", skip) },
266+
objs: []client.Object{caSecret(map[string]string{"other": "x"})},
267+
},
268+
"an s3-ca volume of another source": {spec: func(skip string) *corev1.PodSpec { return configMapS3CA(redisPodSpec("", skip)) }},
269+
}
270+
for name, tc := range refused {
271+
for _, skip := range []string{"", "true"} {
272+
t.Run(name+" is refused, skip="+skip, func(t *testing.T) {
273+
r := &BackupJobReconciler{Client: newMariaDBStrategyTestClient(t, tc.objs...)}
274+
ca, gotSkip, err := r.redisS3Trust(context.Background(), "tenant", tc.spec(skip))
275+
if err == nil || gotSkip || ca != nil {
276+
t.Errorf("trust = (%q, %v, %v), want an error, no CA and no skip-verify", ca, gotSkip, err)
277+
}
278+
})
282279
}
283-
})
280+
}
284281
for name, tc := range cases {
285282
t.Run(name, func(t *testing.T) {
286283
c := newMariaDBStrategyTestClient(t, tc.objs...)

0 commit comments

Comments
 (0)