Skip to content

feat: implement endpointCA certificate mounting for TLS verification - #141

Merged
Agalin merged 3 commits into
operasoftware:mainfrom
ThomasSauvage:feat/endpoint-ca-certificate-mounting
Aug 21, 2026
Merged

feat: implement endpointCA certificate mounting for TLS verification#141
Agalin merged 3 commits into
operasoftware:mainfrom
ThomasSauvage:feat/endpoint-ca-certificate-mounting

Conversation

@ThomasSauvage

Copy link
Copy Markdown
Contributor

Hello everyone! This is my first PR here! Please don't hesitate if you have any feedback.

The endpointCA field was defined in the CRD and the PGBACKREST_REPO<N>_HOST_CA_FILE env var was injected, but the CA certificate was never written to the file the env var pointed at, and the env var name was wrong (HOST_CA_FILE instead of STORAGE_CA_FILE). This left pgBackRest unable to verify self-signed S3 endpoints, failing with unable to get local issuer certificate.

Changes

  • writeEndpointCACertificate — new function in credentials.go that reads the EndpointCA Kubernetes Secret (via the existing extractValueFromSecret helper) and writes the CA cert to /controller/certificates/ before pgBackRest runs. Called from both EnvSetBackupCloudCredentials (backup + WAL archive paths) and EnvSetRestoreCloudCredentials (restore path), covering all code paths that invoke pgBackRest.
  • Fix env var name — changed HOST_CA_FILE to STORAGE_CA_FILE, the correct pgBackRest env var for S3 storage CA verification (maps to --repo<N>-storage-ca-file). The previous HOST_CA_FILE maps to --repo<N>-host-ca-file, which is for remote pgBackRest server TLS, not S3 storage.
  • Fix restore CA pathEnvSetRestoreCloudCredentials was using BarmanBackupEndpointCACertificateLocation (the backup path) instead of BarmanRestoreEndpointCACertificateLocation (the restore path). Now correct.
  • RBAC: include endpointCA Secret — new CollectSecretNamesFromRepositories in secrets.go collects EndpointCA and EncryptionKey Secret names from repository configs. BuildRole in role.go calls it alongside the existing CollectSecretNamesFromCredentials, adding the CA Secret name to the per-namespace Role's resourceNames so the sidecar's service account can read it.
  • Remove stale TODO — removed the // TODO: Properly mount/read and pass CA file for each pgbackrest repository. comment; it is now implemented.

Notes

  • Live-verified on a cluster with self-signed in-cluster RustFS S3 store: stanza created, base backup completed, WAL archiving succeeded (3 archived, 0 failed) with TLS verification against the distributed CA.
  • Multi-repo with different CAs per repository is not supported (all repos write to the same file path). This is a pre-existing limitation in the constant design, not a regression.

Comment thread internal/pgbackrest/credentials/credentials.go Outdated
Comment thread internal/pgbackrest/credentials/credentials.go
Comment thread internal/cnpgi/operator/specs/secrets.go
The endpointCA field was defined in the CRD and the PGBACKREST_REPO<N>_HOST_CA_FILE env var was injected, but the CA certificate was never written to the file the env var pointed at, and the env var name was wrong (HOST_CA_FILE instead of STORAGE_CA_FILE). This left pgBackRest unable to verify self-signed S3 endpoints, failing with 'unable to get local issuer certificate'.

Changes:

- writeEndpointCACertificate: new function in credentials.go that reads the EndpointCA Kubernetes Secret (via the existing extractValueFromSecret helper) and writes the CA cert to /controller/certificates/ before pgBackRest runs. Called from both EnvSetBackupCloudCredentials (backup + WAL archive paths) and EnvSetRestoreCloudCredentials (restore path), covering all code paths that invoke pgBackRest.
- Fix env var name: changed HOST_CA_FILE to STORAGE_CA_FILE, the correct pgBackRest env var for S3 storage CA verification (maps to --repo<N>-storage-ca-file). The previous HOST_CA_FILE maps to --repo<N>-host-ca-file, which is for remote pgBackRest server TLS, not S3 storage.
- Fix restore CA path: EnvSetRestoreCloudCredentials was using BarmanBackupEndpointCACertificateLocation (the backup path) instead of BarmanRestoreEndpointCACertificateLocation (the restore path). Now correct.
- RBAC: include endpointCA Secret: new CollectSecretNamesFromRepositories in secrets.go collects EndpointCA and EncryptionKey Secret names from repository configs. BuildRole in role.go calls it alongside the existing CollectSecretNamesFromCredentials, adding the CA Secret name to the per-namespace Role's resourceNames so the sidecar's service account can read it.
- Remove stale TODO: removed the 'TODO: Properly mount/read and pass CA file for each pgbackrest repository.' comment; it is now implemented.

Signed-off-by: Thomas Sauvage <thomas-commits@sauvage.pm>
…acy barman-cloud env vars

Replace single CA certificate file paths with per-repository paths so each repository gets its own CA file. Remove GetRestoreCABundleEnv and MergeEnv from common.go, which set AWS_CA_BUNDLE (a barman-cloud legacy env var that pgBackRest does not read). Fix WAL restore to use EnvSetRestoreCloudCredentials instead of EnvSetBackupCloudCredentials.

Signed-off-by: Thomas Sauvage <thomas-commits@sauvage.pm>
@ThomasSauvage
ThomasSauvage force-pushed the feat/endpoint-ca-certificate-mounting branch from b113cd8 to cf0b709 Compare August 21, 2026 09:47
Comment thread internal/cnpgi/common/common.go Outdated
Comment thread internal/pgbackrest/credentials/credentials.go
@Agalin

Agalin commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

golangci-lint returns some issues, please fix them to make CI pass.

…s.go

Remove the now-empty common.go file (addressing review feedback). Fix four line-length violations by extracting CA certificate paths into local variables.

Signed-off-by: Thomas Sauvage <thomas-commits@sauvage.pm>
@ThomasSauvage

Copy link
Copy Markdown
Contributor Author

golangci-lint returns some issues, please fix them to make CI pass.

It should be good now.

@Agalin

Agalin commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

FYI: Assuming tests pass I'm going to squash merge this one (to ensure proper changelog entries).

@Agalin
Agalin merged commit 37c20d0 into operasoftware:main Aug 21, 2026
1 check passed
@ThomasSauvage
ThomasSauvage deleted the feat/endpoint-ca-certificate-mounting branch August 21, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants