fix(clickhouse): keep the clickhouse-backup default region when none is configured

The environment the sidecar used to read had no S3_REGION when the
platform carried no region, which left clickhouse-backup on its own
us-east-1. Writing an empty region into the config file replaces that
default with an empty one, and requests are then signed for no region.

Assisted-by: LLM
Signed-off-by: Alexey Artamonov <aleksei.artamonov@aenix.io>
This commit is contained in:
Alexey Artamonov committed 2026-11-04 19:40:37 +03:00
1 parent 2e37aaec5f
commit 38b00730ff
2 files changed
+30 -1

No files matched your search

@@ -454,10 +454,14 @@ func buildClickHouseBackupConfig(creds parsedCreds, forcePathStyle string) ([]by
s3 := map[string]any{
"bucket": creds.bucket,
"endpoint": "https://" + creds.endpoint,
"region": creds.region,
"access_key": creds.accessKey,
"secret_key": creds.secretKey,
}
// An empty region in the file would override clickhouse-backup's own
// us-east-1 default instead of leaving it in place.
if creds.region != "" {
s3["region"] = creds.region
}
if forcePathStyle != "" {
pathStyle, err := strconv.ParseBool(forcePathStyle)
if err != nil {
@@ -721,6 +721,31 @@ func TestProject_WritesClickHouseBackupConfig(t *testing.T) {
}
}
// clickhouse-backup defaults the S3 region to us-east-1; an empty value in
// its config file would replace that default rather than fall back to it.
func TestProject_ClickHouseBackupConfigOmitsAnEmptyRegion(t *testing.T) {
c := newFakeClient(flatSourceSecret())
ctx := context.Background()
cfg := defaultCfg()
cfg.Region = ""
if err := ProjectBackupCredentials(ctx, c, cfg, "tenant-acme"); err != nil {
t.Fatalf("unexpected error: %v", err)
}
got := &corev1.Secret{}
if err := c.Get(ctx, types.NamespacedName{Namespace: "tenant-acme", Name: "cozy-backups-creds"}, got); err != nil {
t.Fatalf("projected Secret not found: %v", err)
}
var doc struct {
S3 map[string]any `json:"s3"`
}
if err := yaml.Unmarshal(got.Data[clickHouseBackupConfigKey], &doc); err != nil {
t.Fatalf("%s is not YAML: %v", clickHouseBackupConfigKey, err)
}
if region, set := doc.S3["region"]; set {
t.Errorf("s3.region = %q, want it left to the clickhouse-backup default", region)
}
}
func TestProject_RejectsMalformedForcePathStyle(t *testing.T) {
c := newFakeClient(flatSourceSecret())
cfg := defaultCfg()