Skip to content

Reference: DbUser CRD

A DbUser resource creates an additional user on a database that a Database resource manages. Each Database already has a primary user with full access. Use a DbUser when another workload needs its own credentials, for example a reporting job that only reads data. The operator creates the user, grants the access level you request and writes the credentials to a Secret in your namespace.

  • API version: kinda.rocks/v1beta1
  • Kind: DbUser
  • Scope: Namespaced

This page documents db-operator 2.45.1.

Example

The following manifest creates a read-only user on the my-application-db database and adds a connection string to the generated Secret.

apiVersion: kinda.rocks/v1beta1
kind: DbUser
metadata:
  name: my-application-db-reporting
  namespace: my-app
spec:
  databaseRef: my-application-db
  accessType: readOnly
  secretName: my-app-db-reporting-credentials
  credentials:
    templates:
      - name: CONNECTION_STRING
        secret: true
        template: "{{ .Protocol }}://{{ .Username }}:{{ .Password }}@{{ .Hostname }}:{{ .Port }}/{{ .Database }}"

Specification (spec)

Field Type Description
databaseRef string Required. Name of the Database resource that the user can access. The Database must be in the same namespace as the DbUser.
accessType string Required. Access level. Allowed values are readOnly (SELECT) and readWrite (SELECT, INSERT, UPDATE, DELETE).
secretName string Required. Name of the Secret that the operator creates to store the user's credentials. The DbUser does not get its own ConfigMap. It uses the ConfigMap of the referenced Database for the host and port.
cleanup boolean Optional. When true, the DbUser becomes the owner of the Secret it creates, so Kubernetes garbage collection deletes the Secret together with the DbUser. Defaults to false.
credentials object Optional. Extra entries and metadata for the generated Secret. See spec.credentials.
existingUser string Optional. Name of an existing database user to manage instead of creating a new user. The operator grants and revokes permissions for this user but does not create or delete it. The password key in the Secret is empty.
extraPrivileges []string Optional. Additional database roles to grant to the user. Every role must also be allowed by the DbInstance. ALL PRIVILEGES is rejected. Upstream marks this feature as experimental.
grantToAdmin boolean Optional. Grants the new user to the PostgreSQL administrator role. Upstream requires this when the operator's administrator is not a superuser. Defaults to true.

spec.credentials

Field Type Description
templates []object Optional. Additional entries that the operator renders and writes to the generated Secret. Unlike a Database, a DbUser gets no default CONNECTION_STRING entry. See spec.credentials.templates[].
metadata object Optional. Labels and annotations to add to the generated Secret. See spec.credentials.metadata.

spec.credentials.templates[]

Field Type Description
name string Required. Data key that the operator writes to the Secret. You cannot use the keys that the operator manages itself, such as POSTGRES_USER and POSTGRES_PASSWORD.
secret boolean Required. Must be true. A DbUser can only write entries to its Secret.
template string Required. A Go template. In a DbUser, {{ .Username }} and {{ .Password }} resolve to this user's credentials.

The template fields and functions are the same as for a Database. See spec.credentials.templates[] in the Database reference.

spec.credentials.metadata

Field Type Description
extraLabels map[string]string Optional. Labels to merge into the generated Secret. A key in this map replaces an existing label with the same key.
extraAnnotations map[string]string Optional. Annotations to merge into the generated Secret. A key in this map replaces an existing annotation with the same key.

Annotations

The operator reads the following annotation on a DbUser. Upstream marks it as experimental.

Annotation Description
kinda.rocks/allow-existing-user: "true" Lets the operator manage a user that already exists on the server. By default, the operator does not manage a user it did not create.

Status (status)

Field Type Description
status boolean true after the user reconciles successfully. Shown in the STATUS column of kubectl get dbuser.
created boolean true after the operator has created the user or started to manage an existing user.
database string Name of the database on the server.
user string Name of the user on the server.
operatorVersion string db-operator version that last completed reconciliation.

To check the state of a user, run:

kubectl get dbuser my-application-db-reporting -n my-app

Platform Notes

  • A DbUser runs on the same shared database server as the Database it references. You do not reference a DbInstance directly.
  • extraPrivileges only works for roles that the DbInstance allows.

Further Reading