Secret Manager supports using entity tags (ETags) for optimistic concurrency control.
In some cases, two processes updating the same resource in parallel may interfere with one another, where the latter process overwrites the effort of the former one.
ETags provide a means for optimistic concurrency control by allowing processes to see if a resource has been modified before taking action on that resource.
Use ETags with Secret Manager
The following resource modification requests support ETags:
In a secrets.patch
request, the request ETag is embedded in the Secret
data. All other requests accept an optional etag
parameter.
If an ETag is provided and matches the current resource ETag, the request
succeeds; otherwise, it fails with a FAILED_PRECONDITION
error and an HTTP status code
400. If an ETag isn't provided, the request proceeds without checking the currently stored ETag value.
Resource ETags are generated at resource creation (projects.secrets.create, projects.secrets.addVersion) and updated for each of the above-listed modification requests. A modification request only updates the ETag of the resource to which it applies. That is, updating a secret version doesn't affect the secret ETag, and similarly, updating the ETag doesn't affect the secret version.
Even when an update doesn't change a resource's state, it still updates the resource ETag.
Consider the following example:
-
User 1 tries to enable a secret version unaware that it's already enabled. The system processes this, changing nothing but the version's ETag.
-
User 2, using the old ETag, tries to disable the version.
-
This fails because the system recognizes the newer ETag, which indicates a more recent intent to keep the version enabled.
Even seemingly minor updates matter due to ETag changes. This ensures data consistency, especially with multiple users or systems interacting with the same resource.
The resource etag
is returned in the response whenever a resource
(Secret or
SecretVersion)
is included.
Delete a secret with ETags
This section describes using ETags when deleting a secret. If the secret has been modified by another process, the delete operation fails.
Update a secret with ETags
This section describes using ETags when updating a secret. If the secret has been modified by another process, the update operation will fail.
Update a secret version with ETags
This section describes using ETags when updating a secret version. If the secret version has been modified by another process, the update operation will fail.
The code sample here describes disabling a secret version with ETags. You can also specify ETags during other secret mutation operations, such as when enabling disabled versions or destroying secret versions. Refer to the code samples for Secret Manager.
What's next
- Learn how to set up rotation schedules for secrets.
- Learn how to edit secrets.
- Learn how to set up notifications on a secret.