Skip to content

Secrets engine resources · Kind catalogue · Examples

DatabaseRole

API version: secrets.openbaoconfig.io/v1alpha1
Scope: Namespaced
Resource: databaseroles.secrets.openbaoconfig.io
Categories: openbao

DatabaseRole manages a dynamic role of a database secrets engine at `<mount>/roles/<name>`: OpenBao creates a short-lived database user per request (`<mount>/creds/<name>`) with the creation statements.

Example:

spec:
  connectionRef:
    name: openbao
  mountPath: database
  name: billing-app
  dbName: billing-postgres
  defaultTTL: 1h
  creationStatements:
    - CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}';

Example

examples/secrets/databaserole.yaml
# A dynamic role that creates a read-only PostgreSQL user per request, valid for an hour, and drops it when the lease
# ends.
apiVersion: secrets.openbaoconfig.io/v1alpha1
kind: DatabaseRole
metadata:
  name: obco-app-ro
  namespace: openbao-config
spec:
  connectionRef:
    kind: OpenBaoConnection
    name: openbao
  creationPolicy: CreateOrAdopt
  deletionPolicy: Delete
  driftDetection: Enabled
  mountPath: database
  name: obco-app-ro
  dbName: postgres
  credentialType: password
  credentialConfig:
    password_policy: obco-db
  defaultTTL: 1h
  maxTTL: 24h
  creationStatements:
    - CREATE ROLE "{{name}}" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';
    - GRANT SELECT ON ALL TABLES IN SCHEMA public TO "{{name}}";
  revocationStatements:
    - REVOKE ALL ON ALL TABLES IN SCHEMA public FROM "{{name}}";
    - DROP ROLE IF EXISTS "{{name}}";
  rollbackStatements:
    - DROP ROLE IF EXISTS "{{name}}";
  renewStatements:
    - ALTER ROLE "{{name}}" VALID UNTIL '{{expiration}}';
---
apiVersion: v1
kind: Secret
metadata:
  name: obco-db-client-ca
  namespace: openbao-config
type: Opaque
stringData:
  key: fake-ca-private-key-not-real
---
apiVersion: secrets.openbaoconfig.io/v1alpha1
kind: DatabaseRole
metadata:
  name: obco-app-cert
  namespace: openbao-config
spec:
  connectionRef:
    kind: OpenBaoConnection
    name: openbao
  creationPolicy: CreateOrAdopt
  deletionPolicy: Delete
  driftDetection: Enabled
  mountPath: database
  name: obco-app-cert
  dbName: postgres
  credentialType: client_certificate
  credentialConfig:
    ca_cert: fake-ca-certificate-not-real
    common_name_template: "{{.DisplayName}}_{{.RoleName}}"
    key_type: ec
    key_bits: "256"
    signature_bits: "256"
  caPrivateKeySecretRef:
    name: obco-db-client-ca
    key: key
  defaultTTL: 1h
  maxTTL: 24h
  creationStatements:
    - CREATE ROLE "{{name}}" WITH LOGIN;
  revocationStatements:
    - DROP ROLE IF EXISTS "{{name}}";

On GitHub: databaserole.yaml, generated sample with every field.

Fields

Defaults below are CRD schema defaults. A blank cell does not imply zero, false or an empty value; see the field description for omission behaviour. Required fields inside an optional object apply only when that object is set.

FieldTypeRequiredDefaultDescriptionValidation
specobjectyesspec is the desired dynamic role of a database secrets engine at `<mountPath>/roles/<name>`.
ConstraintsCEL: self.mountPath == oldSelf.mountPath (mountPath is immutable)
CEL: has(self.name) == has(oldSelf.name) && (!has(self.name) || self.name == oldSelf.name) (name is immutable)
CEL: !has(self.credentialConfig) || !('ca_private_key' in self.credentialConfig) (credentialConfig must not set ca_private_key; use caPrivateKeySecretRef)
CEL: !has(self.caPrivateKeySecretRef) || (has(self.credentialType) && self.credentialType == 'client_certificate') (caPrivateKeySecretRef requires credentialType client_certificate)
CEL: has(self.__namespace__) == has(oldSelf.__namespace__) && (!has(self.__namespace__) || self.__namespace__ == oldSelf.__namespace__) (namespace is immutable)
CEL: self.connectionRef == oldSelf.connectionRef (connectionRef is immutable)
spec.caPrivateKeySecretRefobjectnocaPrivateKeySecretRef selects the Secret key holding the PEM private key of the CA set in credentialConfig ca_cert (`credential_config.ca_private_key`); client_certificate only. Read from a Secret key; never stored in status. Write-only: a change of the Secret is written again. Example: `{name: db-client-ca, key: tls.key}`.
spec.caPrivateKeySecretRef.keystringyesKey in the Secret's data whose value is used. Example: password
Constraintslength: >=1, <=253
spec.caPrivateKeySecretRef.namestringyesName of the Kubernetes Secret, in the same namespace as this resource. Example: openbao-credentials
Constraintslength: >=1, <=253
spec.connectionRefobjectyesConnection used to reach and log in to OpenBao. Immutable.
spec.connectionRef.kindstringno"OpenBaoConnection"Kind of the connection: OpenBaoConnection (in the same Kubernetes namespace as this resource) or ClusterOpenBaoConnection (cluster-scoped; its allowedNamespaces must select this namespace). Default: OpenBaoConnection.
Constraintsone of: OpenBaoConnection, ClusterOpenBaoConnection
spec.connectionRef.namestringyesName of the OpenBaoConnection or ClusterOpenBaoConnection. Example: openbao
Constraintslength: >=1, <=253
spec.creationPolicystringno"Create"How an object that already exists in OpenBao, and is not yet owned by this resource, is treated. Create (default): create the object; an existing one is refused with reason Conflict. Adopt: take over an existing object and never create one. CreateOrAdopt: create it, or take over an existing one. Settings that always exist in OpenBao (configuration singletons) need Adopt or CreateOrAdopt.
Constraintsone of: Create, Adopt, CreateOrAdopt
spec.creationStatements[]stringnocreationStatements are the database statements that create a user (`creation_statements`), with `{{name}}`, `{{password}}` and `{{expiration}}` templates. Up to 64. Example: `["CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}';"]`.
Constraintsitems: <=64
each item: length: >=1, <=8192
spec.credentialConfigmap[string]stringnocredentialConfig configures the generator of the credential type (`credential_config`), for example password_policy for password, or key_bits and format for rsa_private_key. Must not set ca_private_key. Up to 16. Example: `{password_policy: strong}`.
Constraintsproperties: <=16
spec.credentialTypestringnocredentialType is the kind of credential issued (`credential_type`). Allowed: password, rsa_private_key, client_certificate. Defaults to password.
Constraintsone of: password, rsa_private_key, client_certificate
spec.dbNamestringyesdbName is the name of the database connection the role uses (`db_name`); the connection must list the role in allowedRoles. Example: `billing-postgres`.
Constraintslength: >=1, <=128
spec.defaultTTLstringnodefaultTTL is the default lease duration of issued credentials (`default_ttl`), a duration. Defaults to the mount's default lease TTL. Example: `1h`.
Constraintspattern: ^(0|([0-9]+(\.[0-9]+)?(ns|us|ms|s|m|h))+)$
spec.deletionPolicystringno"Orphan"What happens in OpenBao when this resource is deleted. Orphan (default): the OpenBao object stays. Delete: the object is removed (a configuration singleton is reset to its defaults); data and key holders (mounts, namespaces, KV data, audit devices, endpoints, transit, PKI, SSH CA and TOTP keys, MFA methods, entities) are removed only while the resource carries the annotation openbaoconfig.io/allow-destructive-delete: "true". Kinds whose OpenBao object cannot be deleted reject Delete.
Constraintsone of: Delete, Orphan
spec.driftDetectionstringno"Enabled"Whether OpenBao is re-read periodically to detect and repair out-of-band changes. Enabled (default): re-read every driftInterval. Disabled: write only when the spec or a referenced Secret changes.
Constraintsone of: Enabled, Disabled
spec.driftIntervalstringnoHow often OpenBao is re-read for drift, as a duration of at least 30s. Default: the operator's interval for the kind (15m for kinds that grant access such as policies, auth mounts and roles, 1h for the rest), with jitter. Example: 30m
Constraintslength: <=32
CEL: duration(self) >= duration('30s') (driftInterval must be at least 30s)
spec.managementPolicystringno"Manage"Whether the operator writes to OpenBao. Manage (default): converge OpenBao to the spec, create and delete as the policies say. Observe: only read the object and report drift in the conditions; never write or delete.
Constraintsone of: Manage, Observe
spec.maxTTLstringnomaxTTL is the maximum lease duration of issued credentials (`max_ttl`), a duration. Defaults to the mount's max lease TTL. Example: `24h`.
Constraintspattern: ^(0|([0-9]+(\.[0-9]+)?(ns|us|ms|s|m|h))+)$
spec.mountPathstringyesmountPath is the path of the database secrets engine mount, without leading or trailing slashes. Immutable. Example: `database`.
Constraintspattern: ^[A-Za-z0-9_.-]+(/[A-Za-z0-9_.-]+)*$
length: >=1, <=128
spec.namestringnoname is the role name in OpenBao. Defaults to metadata.name. Immutable. Example: `billing-app`.
Constraintspattern: ^\w([\w.-]*\w)?$
length: >=1, <=128
spec.namespacestringnoOpenBao namespace of the object, relative to the connection's base namespace; empty means the connection namespace itself. Segments are separated by "/", without leading or trailing slash. Immutable: it cannot be added, changed or removed after creation. Example: team-a/apps
Constraintspattern: ^[A-Za-z0-9_-][A-Za-z0-9._-]*(/[A-Za-z0-9_-][A-Za-z0-9._-]*)*$
length: <=256
spec.renewStatements[]stringnorenewStatements are the database statements that extend the lifetime of a user (`renew_statements`). Up to 64.
Constraintsitems: <=64
each item: length: >=1, <=8192
spec.revocationStatements[]stringnorevocationStatements are the database statements that revoke a user (`revocation_statements`). Empty uses the plugin default. Up to 64. Example: `["DROP ROLE \"{{name}}\";"]`.
Constraintsitems: <=64
each item: length: >=1, <=8192
spec.rollbackStatements[]stringnorollbackStatements are the database statements that undo a failed user creation (`rollback_statements`). Up to 64.
Constraintsitems: <=64
each item: length: >=1, <=8192
statusobjectnostatus is the observed state of the database role.
status.acquiredstringnoHow the operator came to own the object: Created (it created it) or Adopted (it took over an existing one). Empty until owned.
status.conditions[]objectnoCurrent state as conditions: Ready (the OpenBao object matches the spec) and Synced (the last reconcile succeeded), each with a reason such as Available, Drifted, Conflict, ConnectionNotReady or PermissionDenied, and the generation it describes.
Constraintslist type: map (keys: type)
status.conditions[]objectnoCondition contains details for one aspect of the current state of this API Resource.
status.conditions[].lastTransitionTimestring (date-time)yeslastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
status.conditions[].messagestringyesmessage is a human readable message indicating details about the transition. This may be an empty string.
Constraintslength: <=32768
status.conditions[].observedGenerationinteger (int64)noobservedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
Constraintsvalue: >=0
status.conditions[].reasonstringyesreason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
Constraintspattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
length: >=1, <=1024
status.conditions[].statusstringyesstatus of the condition, one of True, False, Unknown.
Constraintsone of: True, False, Unknown
status.conditions[].typestringyestype of condition in CamelCase or in foo.example.com/CamelCase.
Constraintspattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
length: <=316
status.idstringnoIdentifier OpenBao generated for the object (an entity, group or alias ID, or a mount accessor), for kinds that have one; other resources reference it. Example: 6c9f3e0a-1b2c-4d5e-8f90-123456789abc
status.namespacestringnoAbsolute OpenBao namespace the object was written in; empty means the root namespace. If it later differs from the spec, reconciling stops with reason NamespaceChanged. Example: team-a/apps
status.observedGenerationinteger (int64)noThe metadata.generation of this resource that the operator last reconciled.
status.pathstringnoFull OpenBao API path of the object, including its namespace, as last written; deletion uses it even after the spec changed. Example: team-a/sys/policies/acl/app-read
status.rotationNoncestringnoValue of the resource's rotation nonce when one-time inputs, such as a root credential that OpenBao rotates afterwards, were last sent; changing the nonce in the spec sends them again.
status.serverIDstringnoCluster ID of the OpenBao server the object was acquired on. If the connection later reaches another server, reconciling stops with reason ServerChanged and nothing is written or deleted. Example: 80f7de92-c12e-e960-4754-255c32fc6b53
status.writeOnlyHashstringnoKeyed hash (HMAC-SHA256) of the write-only inputs, such as passwords read from Secrets; a change forces a write. It never contains or reveals the values.