Skip to content

Secrets Service

virtufin.SecretsService manages the platform secrets of a context: the keys of the deployment's worker secret, which workers reference by name (Worker Secrets). It lists the keys and when each was set, and sets and deletes keys. No method ever returns a value.

The WorkManager serves it next to virtufin.WorkManager, so the api gateway reaches it the same way: through the workmanager backend.

Methods

Method Kind Request Response
ListSecrets read (NO_SIDE_EFFECTS) {} secrets: [{key, set_at}], ordered by key
SetSecrets write values: map key -> value, one or more secrets: the keys set, with this write's set_at
DeleteSecrets write keys: one or more deleted: the keys that were there

set_at is RFC 3339 UTC (2026-11-27T10:30:00Z). It is empty for a key written some other way, such as the deployment's first values or kubectl.

SetSecrets adds or replaces the given keys and keeps every other key. DeleteSecrets skips a key that is not there. Each call is one write: all of its keys change, or none.

Calling it through the gateway

Like every WorkManager method, through Gateway.Invoke (typed protobuf) or Gateway.InvokeJson, with service workmanager:

from virtufin.workmanager import workmanager_pb2 as wm

# api: virtufin.api.ApiClient
request = wm.SetSecretsRequest(values={"alpaca-paper-key": key, "alpaca-paper-secret": secret})
raw = await api.gateway.invoke_raw_async("workmanager", "SetSecrets", request.SerializeToString())
response = wm.SetSecretsResponse.FromString(raw)  # keys and set_at, never a value
// Gateway.InvokeJson: service "workmanager", method "ListSecrets", request "{}"
{"secrets": [{"key": "alpaca-paper-key", "setAt": "2026-11-27T10:30:00Z"}]}

The generated stubs (SecretsServiceStub in Python, SecretsService in TypeScript, SecretsService.SecretsServiceClient in C#) carry the message types. The gateway caches a backend's descriptors (GrpcReflectionCacheTtlMinutes), so right after a WorkManager release that adds methods, JSON calls may not know them until the cache refreshes.

Who may call it

The WorkManager does not decide who may write. The clients' authorization does, from the gateway's method kinds: ListSecrets is a read; SetSecrets and DeleteSecrets are writes, so the web app's server and the TUI's write gate allow them to admins only, like every other write. Anyone who can call the gateway directly with an API key can write, as for every other WorkManager write.

Rules

What Rule
Key [A-Za-z0-9._-]{1,253}, the Kubernetes Secret key rule
Value Not empty
Request At least one value (SetSecrets) or key (DeleteSecrets)

A request that breaks a rule fails with INVALID_ARGUMENT, naming the key (never a value).

Errors

Status When
INVALID_ARGUMENT A rule above; or the Kubernetes API refused the write (for example the Secret's 1 MiB size limit)
FAILED_PRECONDITION The worker secret does not exist (the deployment creates it), no secret is configured (WORKER_SECRETS_NAME), or the WorkManager is not running in a cluster
PERMISSION_DENIED The WorkManager's service account may not get or patch the Secret (its Role is missing)
ABORTED The Secret kept changing during the write (another write at the same moment); try again
UNAVAILABLE The Kubernetes API failed or could not be reached

How it works

  • Writes go through the Kubernetes API, under the WorkManager's own service account (workmanager). The helm chart's Role allows it get and patch on exactly the worker Secret (resourceNames), nothing else: it cannot create, list or delete Secrets.
  • Each write is a conditional JSON merge patch. It carries the resource version the WorkManager read, so a concurrent change fails it with a conflict instead of being lost. The WorkManager then reads again and retries, up to 5 attempts, before it answers ABORTED.
  • When each key was set is kept on the Secret itself, in one annotation, virtufin.com/secrets-set-at: a JSON object key -> time. It is one annotation, not one per key, because a secret key is not always a valid annotation name. It is written in the same patch as the keys.
  • Every write is announced. After a write, the WorkManager publishes sys.workmanager.secrets.changed (ce-type com.virtufin.workmanager.secrets.changed, payload {"change": "set"|"delete", "keys": [...]}, keys only). Every Runtime follows that topic and drops its cached secrets, so running workers get the new value on their next event instead of after the periodic refresh (WORKER_SECRETS_TTL_SECONDS, which stays for changes made with kubectl).
  • Values are never logged. The WorkManager logs the keys it set or deleted.

Configuration

Setting Description Default
WORKER_SECRETS_NAME The worker Secret (the chart's workerSecrets.secretName; the Runtime reads the same variable) none: without it the service answers FAILED_PRECONDITION
WORKER_SECRETS_NAMESPACE Its namespace the pod's own

The Secret's name has no default in the WorkManager: it belongs to the deployment.

The Secret's owner

The deployment creates the worker Secret once, filled with its first values, and never overwrites it: from then on the Secrets service owns its keys. The helm chart creates it empty only when it is missing (Helm lookup, kept on upgrades and uninstall). See Manage worker secrets.