Secrets management
Secrets management gives Bruin one connection lookup model while allowing credentials to stay in a local config file or in an external secret service. A run selects one source, resolves a connection by name, checks its connection type and details, and passes the resulting typed connection to the asset that needs it. See Platform services for the wider service model.
Secrets source model
Connection lookup contract
The secrets abstraction presents every source as a connection provider. A provider returns a connection, its details, and its type by name; external providers also expose a resolver that can return the reason for a failed lookup instead of only a missing value. This keeps asset and connection code independent of where the credential is stored. pkg/…/manager.go• L179-200
References: pkg/…/manager.go• L179-200 pkg/…/secrets.go• L5-17
Backend selection
The --secrets-backend option selects the external source for a command. BRUIN_SECRETS_BACKEND can provide the same choice when the command runs in a managed environment. Supported values are vault, aws, azure, and doppler; when no value is set, Bruin uses the normal connection configuration from .bruin.yml. cmd/secrets_backend.go• L15-35
The selected backend replaces the connection provider for the run. It does not change the names used by pipeline assets, so a pipeline can refer to a connection by name while the run decides where Bruin obtains it. cmd/secrets_backend.go• L51-82
References: cmd/secrets_backend.go• L15-35 cmd/secrets_backend.go• L51-82 pkg/…/manager.go• L297-305
Connection secret shape
External backends describe a connection with two logical parts: type identifies a supported Bruin connection kind and details holds the fields for that kind. Bruin adds the requested name, validates the shape through the normal connection rules, and returns the same kind of typed connection that local configuration produces. pkg/…/aws_secretsmanager.go• L186-236
This shared shape lets one secret represent database access, an API credential, or another supported connection without adding backend-specific rules to each asset. It also covers source connections such as Odoo, where the connection details include the source endpoint and a sensitive API key. The details object must contain the fields required by its type; malformed JSON, a missing type, or an invalid details object stops resolution before the connection is used. pkg/…/azure_keyvault.go• L260-310 pkg/…/connections.go• L1050-1063
References: pkg/…/aws_secretsmanager.go• L186-236 pkg/…/azure_keyvault.go• L260-310 pkg/…/manager.go• L27-176 pkg/…/connections.go• L1050-1063
Secret resolution flow
The resolution flow turns a pipeline connection name into a typed connection without exposing storage differences to the asset executor. The command creates the selected provider before execution, and the provider fetches and validates a secret only when a connection is requested. cmd/run.go• L1193-1201
The diagram shows the path from run selection to connection use.
flowchart LR
A[Run selects backend] --> B[Create connection provider]
B --> C[Asset requests connection name]
C --> D[Fetch named secret]
D --> E[Read type and details]
E --> F[Validate with connection rules]
F --> G[Return typed connection]
G --> H[Asset or service uses connection]
Named connection resolution
A pipeline uses a connection name rather than a provider-specific key. The provider maps that name to one secret, builds a temporary connection configuration, and sends it through the existing connection manager. This preserves one validation and construction path for local and external credentials. pkg/…/vault.go• L465-535 pkg/…/vault.go• L538-594
Resolved connections and their details are cached in memory for the run. Repeated requests therefore reuse the resolved value instead of reading the same secret again. Vault also shares concurrent requests for the same name so one in-flight lookup supplies the result to all callers. pkg/…/vault.go• L357-423 pkg/…/vault.go• L465-508
References: cmd/run.go• L1193-1201 pkg/…/vault.go• L357-423 pkg/…/vault.go• L465-535 pkg/…/vault.go• L538-594 pkg/…/aws_secretsmanager.go• L101-157 pkg/…/vault_test.go• L350-425 pkg/…/vault_test.go• L571-598
Error and log protection
A resolver keeps lookup errors separate from a connection that does not exist. Each external backend marks a missing secret with one shared error type, so the caller can distinguish a wrong name from a service or access failure. pkg/…/manager.go• L193-200 pkg/…/connection_errors.go• L9-69 pkg/…/notfound.go• L10-31
Missing secrets are logged at debug level so the caller's clear connection-not-found message remains visible. Other lookup failures are logged at warn level without a stack trace, while backend initialization still fails early when required access settings are missing. pkg/…/notfound.go• L23-31 pkg/…/notfound_test.go• L19-42
When credential masking is enabled, the run gathers sensitive values from the connections it uses and installs a masking sink before execution logs are written. This limits masking work to used connections and keeps credential values out of normal terminal and log output when the feature is active. cmd/run.go• L1224-1232 cmd/run.go• L2767-2819
References: pkg/…/manager.go• L193-200 pkg/…/connection_errors.go• L9-69 pkg/…/notfound.go• L10-31 pkg/…/notfound_test.go• L19-42 cmd/run.go• L1224-1232 cmd/run.go• L2767-2819
External backends
Each external backend owns the work needed to authenticate to its service and convert that service's value into the common connection shape. The choice is about credential storage and access, not about a different connection type system.
HashiCorp Vault
Vault is the backend for a KV v2 secrets engine. Bruin authenticates with a Vault token or with a Kubernetes role, reads a secret below the configured mount and path, and expects the connection type and details fields in the returned data. pkg/…/vault.go• L51-113 pkg/…/vault.go• L287-340 pkg/…/vault.go• L465-535
The Vault backend can also list leaf secrets under its configured path and merge them into one connection configuration when a caller needs the full set. pkg/…/vault.go• L425-463 pkg/…/vault.go• L596-615
The Vault endpoint accepts HTTP(S) or Unix-socket addresses. For HTTP(S), a path prefix remains part of each API request, which supports Vault deployments behind a proxy or gateway. Requests use a bounded timeout and retry policy; retry delays honor a service-provided Retry-After value or use jitter to reduce synchronized retries. Errors report the service status without copying a response body into the error. pkg/…/vault.go• L161-186 pkg/…/vault.go• L208-230 pkg/…/vault.go• L233-285 pkg/…/vault.go• L617-628
Missing Vault secrets use the shared missing-secret error, which lets normal connection-not-found handling apply without treating an absent name as a service warning. pkg/…/vault.go• L553-560
References: pkg/…/vault.go• L51-113 pkg/…/vault.go• L161-186 pkg/…/vault.go• L208-340 pkg/…/vault.go• L425-463 pkg/…/vault.go• L465-615 pkg/…/vault.go• L617-628 pkg/…/vault_test.go• L69-242 pkg/…/vault_test.go• L427-804
AWS Secrets Manager
AWS Secrets Manager is the backend for teams that want AWS-managed secret storage and AWS identity control. Bruin reads a secret by the connection name, accepts its JSON string value, and converts the common type and details shape into a typed connection. pkg/…/aws_secretsmanager.go• L101-131 pkg/…/aws_secretsmanager.go• L167-236
Authentication follows the AWS SDK credential chain by default. A deployment can instead provide a complete Bruin-specific access key pair and region, with an optional session token for temporary credentials. pkg/…/aws_secretsmanager.go• L34-64
AWS marks a service response that names no such secret as a missing-secret result. Other read errors remain visible as backend failures. pkg/…/aws_secretsmanager.go• L167-180
References: pkg/…/aws_secretsmanager.go• L24-64 pkg/…/aws_secretsmanager.go• L101-131 pkg/…/aws_secretsmanager.go• L167-236
Azure Key Vault
Azure Key Vault is the backend for Azure-managed secret storage. Bruin reads the latest value for a secret named after the connection, parses the common JSON shape, and builds the matching typed connection. pkg/…/azure_keyvault.go• L176-207 pkg/…/azure_keyvault.go• L242-310
The backend supports client credentials, managed identity, Azure CLI credentials, and the default Azure credential chain. It requires an HTTPS URL for an Azure Key Vault resource, which prevents a non-Key Vault endpoint from being used by mistake. pkg/…/azure_keyvault.go• L36-76 pkg/…/azure_keyvault.go• L79-149 pkg/…/azure_keyvault.go• L151-159
An Azure not-found response becomes the shared missing-secret result. This keeps an absent secret distinct from authentication, network, and payload errors. pkg/…/azure_keyvault.go• L242-254
References: pkg/…/azure_keyvault.go• L36-76 pkg/…/azure_keyvault.go• L79-159 pkg/…/azure_keyvault.go• L176-310
Doppler
Doppler is the backend for teams that manage environment-specific values in a Doppler project and config. Bruin downloads the selected config, finds the entry with the requested connection name, parses that entry as JSON, and applies the same type and details rules as the other backends. pkg/…/doppler.go• L18-74 pkg/…/doppler.go• L185-245
The provider uses a Doppler service token together with a project and config. The config choice therefore controls which environment's connection values a run can resolve. A missing entry becomes the shared missing-secret result instead of a generic backend failure. pkg/…/doppler.go• L84-128 pkg/…/doppler.go• L53-73
References: pkg/…/doppler.go• L18-74 pkg/…/doppler.go• L53-73 pkg/…/doppler.go• L84-128 pkg/…/doppler.go• L131-183 pkg/…/doppler.go• L185-245
Operational relationships
Connection consumers
The resolved provider is passed to the operators that run assets. Python and R assets can use connection details for their secret mappings, while database and service operators use the same provider to create their clients. Source operators use the same typed connection model for connections such as Odoo. This makes secret storage a run concern rather than an asset concern. cmd/run.go• L1953-1991 pkg/…/operator.go• L140-160 pkg/…/operator.go• L126-147 pkg/…/connections.go• L1050-1063
The same connection name must be present in the selected source and must describe the fields required by its connection type. A provider can be correctly configured and still fail a run when a pipeline name or secret payload does not match those rules.
References: cmd/run.go• L1953-1991 pkg/…/operator.go• L140-160 pkg/…/operator.go• L126-147 pkg/…/connection.go• L300-330 pkg/…/connections.go• L1050-1063
Credential masking
Credential masking is a separate run safeguard from secret retrieval. It collects inline sensitive fields and the details of connections used by the pipeline, then redacts matching values before output reaches the terminal or a log file. Enable it when logs may be shared outside the trusted run environment. cmd/run.go• L1224-1232 cmd/run.go• L2767-2819
Masking cannot protect a value that the selected provider cannot read, and it is not active unless the run enables credential masking. The provider must still return valid connection details so the run can both use the connection and collect its sensitive values.
References: cmd/run.go• L1224-1232 cmd/run.go• L2767-2819
Related platform services
Secrets management supplies credentials to platform connections. Bruin Cloud describes the hosted platform connection context, while AI-assisted workflows and Inference operations describe services that may use provider-backed connections. Those pages explain the consuming services; this page explains how the credential source is selected and resolved.
References: cmd/secrets_backend.go• L51-82 cmd/run.go• L1193-1201
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the backend names in the command flag, environment variable, and initialization switch aligned.
- Keep the external secret payload contract aligned with every backend parser and with the connection type schema.
- Keep new connection types and their sensitive fields aligned with connection validation and credential masking.
- Keep missing-secret errors distinguishable from access, transport, and payload errors so operators can identify the cause of a failed lookup.
- Keep missing-secret logging quiet while keeping other backend failures visible.
- Keep resolved connection details available to credential masking when a new backend or connection path is added.
- Keep backend authentication changes compatible with the runtime identity model used by the target cloud or cluster.
- Keep Vault endpoint validation, request timeouts, and retry settings compatible with the deployed Vault address and service behavior.
- Keep Vault URL path-prefix handling aligned with any proxy or gateway that fronts the service.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
An unsupported --secrets-backend value is set | The connection provider cannot start and the run stops before asset execution | Use only vault, doppler, aws, or azure |
| A backend credential or required service setting is missing | Bruin fails while creating the provider | Supply the backend's required identity and endpoint settings before the run |
| A Vault host has an unsupported URL form or invalid timeout/retry settings | The Vault provider cannot start | Use an HTTP(S) or Unix-socket address and keep duration and retry bounds valid |
| A Vault deployment is behind a URL path but the host omits that path | Requests go to the wrong endpoint and secret resolution fails | Include the full HTTP(S) base path in the Vault host |
| A secret name does not match the pipeline connection name | The requested connection cannot be resolved | Use the exact same name in the pipeline and the external store |
| A backend cannot distinguish an absent secret from another lookup error | Operators receive the wrong failure signal or an unnecessary warning | Map provider-specific not-found responses to the shared missing-secret error |
A secret is not valid JSON or lacks a non-empty type and object details | Bruin cannot build a typed connection | Store the common connection payload and validate it against the connection type |
| A resolved connection has a field that its type does not accept | Connection construction fails before the asset uses it | Keep details aligned with the supported connection schema |
| A credential cannot be read while masking is enabled | Some values may remain unmasked in output | Treat masking warnings as a signal to fix the unreadable connection or file |
Key files
| File | Why to read it |
|---|---|
| cmd/secrets_backend.go | Shows how a run selects a backend and creates the provider. |
| pkg/…/manager.go | Defines the common connection lookup and resolution contracts. |
| pkg/…/connections.go | Defines supported connection shapes and marks sensitive fields for safe handling. |
| pkg/…/connection_errors.go | Shows how missing connections carry source and run context. |
| pkg/…/secrets.go | Confirms which backend clients implement the common contracts. |
| pkg/…/notfound.go | Defines shared missing-secret classification and log levels. |
| pkg/…/notfound_test.go | Shows the guarantee that missing lookups stay quiet while other failures remain visible. |
| pkg/…/vault.go | Explains Vault authentication, endpoint handling, request policy, caching, connection listing, and payload conversion. |
| pkg/…/vault_test.go | Shows the guarantees for Vault endpoint handling, retries, timeouts, response validation, caching, connection listing, and error redaction. |
| pkg/…/aws_secretsmanager.go | Explains AWS identity loading, missing-secret handling, and secret conversion. |
| pkg/…/azure_keyvault.go | Explains Azure identity choices, endpoint checks, missing-secret handling, and secret conversion. |
| pkg/…/doppler.go | Explains Doppler project/config selection, missing-secret handling, and payload conversion. |
| cmd/run.go | Shows when the provider is created and how resolved values are masked in run output. |