Skip to content

Commit b574e21

Browse files
Andrey Kolkovclaude
andcommitted
fix(backups): cover Go-driven system-bucket ObjectStore + share the checksum helper
Address review on the S3 request-checksum fix: - Extend the fix to the platform-managed useSystemBucket=true flow, whose ObjectStore is built in Go by applyClusterPluginBackup (SSA-applied), not chart-rendered. Add InstanceSidecarConfiguration to cnpgtypes.ObjectStoreSpec and set AWS_REQUEST_CHECKSUM_CALCULATION=when_required on it via barmanSidecarConfiguration(). The platform's own default system bucket is SeaweedFS, a non-AWS S3 gateway of the same class as Ceph RGW. Unit test in cnpgstrategy_controller_test.go asserts the applied ObjectStore carries it. - Factor the duplicated instanceSidecarConfiguration block (3x across two charts) into a shared cozy-lib helper (cozy-lib.barman.checksumSidecarConfiguration). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 0c586b9 commit b574e21

7 files changed

Lines changed: 102 additions & 25 deletions

File tree

‎internal/backupcontroller/cnpgstrategy_controller.go‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,9 @@ func (r *BackupJobReconciler) applyClusterPluginBackup(ctx context.Context, name
436436
Controller: &controller,
437437
}}
438438
objStore.Spec = cnpgtypes.ObjectStoreSpec{
439-
Configuration: *buildBarmanObjectStore(t.BarmanObjectStore, ""),
440-
RetentionPolicy: t.BarmanObjectStore.RetentionPolicy,
439+
Configuration: *buildBarmanObjectStore(t.BarmanObjectStore, ""),
440+
RetentionPolicy: t.BarmanObjectStore.RetentionPolicy,
441+
InstanceSidecarConfiguration: barmanSidecarConfiguration(),
441442
}
442443
if err := r.Patch(ctx, objStore, client.Apply, client.FieldOwner(cnpgFieldManager), client.ForceOwnership); err != nil {
443444
return "", fmt.Errorf("apply ObjectStore %s/%s: %w", namespace, objStoreName, err)
@@ -1391,6 +1392,24 @@ func buildBarmanPlugin(objectStoreName, serverName string) cnpgtypes.PluginConfi
13911392
}
13921393
}
13931394

1395+
// barmanSidecarConfiguration pins the barman-cloud sidecar's boto3 request
1396+
// checksum policy to "when_required". Since botocore ~1.36 the default
1397+
// (when_supported) attaches a flexible checksum to every PutObject, which
1398+
// non-AWS S3-compatible backends (Ceph RGW, and the platform's own default
1399+
// SeaweedFS system bucket) reject with "x-amz-content-sha256 must be
1400+
// UNSIGNED-PAYLOAD, ...". Compute a checksum only when required; AWS S3
1401+
// accepts that too, so it is a safe default everywhere. This mirrors the same
1402+
// env set on the chart-rendered ObjectStores (packages/{apps/postgres,
1403+
// system/keycloak}/templates/db.yaml) and the etcd-operator fix (#342).
1404+
func barmanSidecarConfiguration() *cnpgtypes.InstanceSidecarConfiguration {
1405+
return &cnpgtypes.InstanceSidecarConfiguration{
1406+
Env: []cnpgtypes.EnvVar{{
1407+
Name: "AWS_REQUEST_CHECKSUM_CALCULATION",
1408+
Value: "when_required",
1409+
}},
1410+
}
1411+
}
1412+
13941413
// buildBarmanObjectStore translates the typed strategy template into the
13951414
// barman configuration shape shared by the deprecated
13961415
// spec.backup.barmanObjectStore and the plugin's ObjectStore.spec.configuration.

‎internal/backupcontroller/cnpgstrategy_controller_test.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,17 @@ func TestApplyClusterPluginBackup_PatchesExistingCluster(t *testing.T) {
14641464
if store.Spec.RetentionPolicy != "30d" {
14651465
t.Errorf("ObjectStore retentionPolicy: got %q", store.Spec.RetentionPolicy)
14661466
}
1467+
// The ObjectStore must pin the barman-cloud sidecar's S3 request-checksum
1468+
// policy to when_required, or uploads to non-AWS S3 gateways (Ceph RGW, the
1469+
// platform's own SeaweedFS system bucket) fail with an x-amz-content-sha256
1470+
// InvalidArgument. The chart does not render this ObjectStore in the
1471+
// platform-managed useSystemBucket=true flow, so this Go path is the only
1472+
// place that sets it there.
1473+
sc := store.Spec.InstanceSidecarConfiguration
1474+
if sc == nil || len(sc.Env) != 1 ||
1475+
sc.Env[0].Name != "AWS_REQUEST_CHECKSUM_CALCULATION" || sc.Env[0].Value != "when_required" {
1476+
t.Errorf("ObjectStore instanceSidecarConfiguration.env: got %+v, want [AWS_REQUEST_CHECKSUM_CALCULATION=when_required]", sc)
1477+
}
14671478
// The ObjectStore must be owner-referenced to the Cluster so Kubernetes GC
14681479
// removes it when the Cluster is deleted (no orphan in the platform flow,
14691480
// where the chart does not render this ObjectStore).

‎internal/backupcontroller/cnpgtypes/types.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ type ObjectStoreSpec struct {
208208
// RetentionPolicy is a barman retention expression validated by the plugin
209209
// CRD against ^[1-9][0-9]*[dwm]$ (e.g. "30d").
210210
RetentionPolicy string `json:"retentionPolicy,omitempty"`
211+
// InstanceSidecarConfiguration passes settings to the barman-cloud sidecar
212+
// that the plugin injects into the CNPG pods. Only the fields we set are
213+
// modelled (see the upstream ObjectStore CRD for the full type).
214+
InstanceSidecarConfiguration *InstanceSidecarConfiguration `json:"instanceSidecarConfiguration,omitempty"`
215+
}
216+
217+
// InstanceSidecarConfiguration is a minimal mirror of the barman-cloud
218+
// ObjectStore's spec.instanceSidecarConfiguration (only spec.env).
219+
type InstanceSidecarConfiguration struct {
220+
Env []EnvVar `json:"env,omitempty"`
221+
}
222+
223+
// EnvVar is a minimal corev1.EnvVar (name/value only) — enough to pass a
224+
// literal environment variable to the barman-cloud sidecar.
225+
type EnvVar struct {
226+
Name string `json:"name"`
227+
Value string `json:"value,omitempty"`
211228
}
212229

213230
type BackupStatus struct {

‎internal/backupcontroller/cnpgtypes/zz_generated.deepcopy.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,27 @@ func (in *ObjectStoreList) DeepCopyObject() runtime.Object {
239239
func (in *ObjectStoreSpec) DeepCopyInto(out *ObjectStoreSpec) {
240240
*out = *in
241241
in.Configuration.DeepCopyInto(&out.Configuration)
242+
if in.InstanceSidecarConfiguration != nil {
243+
out.InstanceSidecarConfiguration = new(InstanceSidecarConfiguration)
244+
in.InstanceSidecarConfiguration.DeepCopyInto(out.InstanceSidecarConfiguration)
245+
}
246+
}
247+
248+
func (in *InstanceSidecarConfiguration) DeepCopyInto(out *InstanceSidecarConfiguration) {
249+
*out = *in
250+
if in.Env != nil {
251+
out.Env = make([]EnvVar, len(in.Env))
252+
copy(out.Env, in.Env)
253+
}
254+
}
255+
256+
func (in *InstanceSidecarConfiguration) DeepCopy() *InstanceSidecarConfiguration {
257+
if in == nil {
258+
return nil
259+
}
260+
out := new(InstanceSidecarConfiguration)
261+
in.DeepCopyInto(out)
262+
return out
242263
}
243264

244265
func (in *Backup) DeepCopy() *Backup {

‎packages/apps/postgres/templates/db.yaml‎

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,9 @@ spec:
262262
{{- if .Values.backup.retentionPolicy }}
263263
retentionPolicy: {{ .Values.backup.retentionPolicy | quote }}
264264
{{- end }}
265-
# Ceph RGW and other non-AWS S3-compatible backends reject botocore's default
266-
# flexible request checksum (the x-amz-content-sha256 that barman-cloud's
267-
# boto3 sends on every upload) with "InvalidArgument: x-amz-content-sha256
268-
# must be UNSIGNED-PAYLOAD, ...". Compute a checksum only when the operation
269-
# requires one; AWS S3 accepts this too, so it is a safe default everywhere.
270-
instanceSidecarConfiguration:
271-
env:
272-
- name: AWS_REQUEST_CHECKSUM_CALCULATION
273-
value: when_required
265+
# Pin the barman-cloud sidecar's S3 request checksum to when_required
266+
# (rationale in cozy-lib.barman.checksumSidecarConfiguration).
267+
{{- include "cozy-lib.barman.checksumSidecarConfiguration" . | nindent 2 }}
274268
configuration:
275269
destinationPath: {{ $destinationPath }}
276270
endpointURL: {{ $endpointURL }}
@@ -297,11 +291,8 @@ kind: ObjectStore
297291
metadata:
298292
name: {{ .Release.Name }}-recovery
299293
spec:
300-
# Same non-AWS S3 request-checksum workaround as the backup ObjectStore above.
301-
instanceSidecarConfiguration:
302-
env:
303-
- name: AWS_REQUEST_CHECKSUM_CALCULATION
304-
value: when_required
294+
# Same S3 request-checksum pin as the backup ObjectStore above.
295+
{{- include "cozy-lib.barman.checksumSidecarConfiguration" . | nindent 2 }}
305296
configuration:
306297
destinationPath: {{ $destinationPath }}
307298
endpointURL: {{ $endpointURL }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{- /*
2+
cozy-lib.barman.checksumSidecarConfiguration renders a barman-cloud ObjectStore
3+
`spec.instanceSidecarConfiguration` that pins the sidecar's boto3 request-checksum
4+
policy to when_required.
5+
6+
Since botocore ~1.36 (early 2025) the default RequestChecksumCalculation is
7+
when_supported, which attaches a flexible checksum (the x-amz-content-sha256
8+
header) to every PutObject. Non-AWS S3-compatible backends (Ceph RADOS Gateway,
9+
the platform's own SeaweedFS system bucket, some MinIO/Cloudflare R2 builds)
10+
reject it with "InvalidArgument: x-amz-content-sha256 must be UNSIGNED-PAYLOAD,
11+
...", so every backup/WAL-archive upload fails against them. when_required
12+
computes a checksum only when the operation mandates one; AWS S3 accepts that on
13+
a plain PutObject too, so it is a safe default everywhere.
14+
15+
Emit under an ObjectStore `spec:` with `{{- include "cozy-lib.barman.checksumSidecarConfiguration" . | nindent 2 }}`.
16+
The Go-driven platform (useSystemBucket=true) ObjectStore sets the same env in
17+
internal/backupcontroller/cnpgstrategy_controller.go (barmanSidecarConfiguration).
18+
*/ -}}
19+
{{- define "cozy-lib.barman.checksumSidecarConfiguration" -}}
20+
instanceSidecarConfiguration:
21+
env:
22+
- name: AWS_REQUEST_CHECKSUM_CALCULATION
23+
value: when_required
24+
{{- end -}}

‎packages/system/keycloak/templates/db.yaml‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,9 @@ spec:
5151
{{- if .Values.backup.retentionPolicy }}
5252
retentionPolicy: {{ .Values.backup.retentionPolicy | quote }}
5353
{{- end }}
54-
# Ceph RGW and other non-AWS S3-compatible backends reject botocore's default
55-
# flexible request checksum (the x-amz-content-sha256 that barman-cloud's
56-
# boto3 sends on every upload) with "InvalidArgument: x-amz-content-sha256
57-
# must be UNSIGNED-PAYLOAD, ...". Compute a checksum only when the operation
58-
# requires one; AWS S3 accepts this too, so it is a safe default everywhere.
59-
instanceSidecarConfiguration:
60-
env:
61-
- name: AWS_REQUEST_CHECKSUM_CALCULATION
62-
value: when_required
54+
# Pin the barman-cloud sidecar's S3 request checksum to when_required
55+
# (rationale in cozy-lib.barman.checksumSidecarConfiguration).
56+
{{- include "cozy-lib.barman.checksumSidecarConfiguration" . | nindent 2 }}
6357
configuration:
6458
destinationPath: {{ .Values.backup.destinationPath | quote }}
6559
{{- with .Values.backup.endpointURL }}

0 commit comments

Comments
 (0)