Skip to content

fix(gcs): use a separate credentials file per secret key - #309

Merged
mnencia merged 2 commits into
mainfrom
dev/gcs-credentials-per-store
Oct 14, 2026
Merged

mnencia merged 2 commits into
mainfrom
dev/gcs-credentials-per-store

Conversation

@armru

@armru armru commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

A process can run barman-cloud commands for different object stores at the same time. For example, a replica cluster archives WAL to its own store and restores from the source one. All Google credentials went to one shared file, so a command could run with the identity of another store. A store using the GKE environment also emptied the file while other commands read it.

Each secret key now has its own file, /controller/.google-credentials/<secret>/<key>, and GOOGLE_APPLICATION_CREDENTIALS points to it. The GKE environment no longer writes any file. Writes are serialized because WriteFileAtomic names its temporary file after the current second.

Same problem as #284, for SSE-C keys.

@armru
armru requested a review from a team as a code owner September 30, 2026 13:37
@leonardoce
leonardoce force-pushed the dev/gcs-credentials-per-store branch from 24110fd to 120366b Compare October 2, 2026 08:15
@leonardoce

leonardoce commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

I opened cloudnative-pg/machinery#325 to fix the reason why we need googleCredentialsMutex.
When it is merged, we can remove it.

@mnencia mnencia changed the title fix: keep a separate Google credentials file for each secret key fix(gcs): keep a separate Google credentials file for each secret key Oct 14, 2026
A single process can run barman-cloud commands for different object
stores at the same time. A replica cluster, for instance, archives WAL to
its own object store while restoring it from the source one. The Google
application credentials were always written to the same file, so a
command could run with the credentials of another object store, and an
object store using the GKE environment emptied the file the other
commands were reading.

Write each credentials file to a path that depends on the referenced
secret and key, point GOOGLE_APPLICATION_CREDENTIALS at it, and serialize
the writes. The GKE environment no longer touches any file.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@mnencia
mnencia force-pushed the dev/gcs-credentials-per-store branch from 120366b to b03f9b9 Compare October 14, 2026 07:45
The mutex comment now says when to remove it.

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
@mnencia mnencia changed the title fix(gcs): keep a separate Google credentials file for each secret key fix(gcs): use a separate credentials file per secret key Oct 14, 2026
@mnencia
mnencia merged commit 6face7d into main Oct 14, 2026
6 checks passed
@mnencia
mnencia deleted the dev/gcs-credentials-per-store branch October 14, 2026 08:50
mnencia added a commit that referenced this pull request Oct 16, 2026
Remove `googleCredentialsMutex`. It serialized the writes of the GCS
credentials file because `WriteFileAtomic` named its temporary file
after the current second, so concurrent writes of the same file shared
it. machinery v0.6.1 uses a random suffix, which was the condition set
in #309 to drop the mutex (cloudnative-pg/machinery#325).

Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
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.

4 participants