For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

Cennso PostgreSQL User

Note

PostgreSQLUser only creates the user, applies the requested grants, and sets the database owner. It does not update or delete them. Deleting a PostgreSQLUser Custom Resource does not drop the user from PostgreSQL, and changing the password in the referenced Kubernetes Secret does not change the password of a user that already exists. To drop the existing user, use the DROP ROLEOpens in a new tab SQL statement.

Before provisioning a user, the target PostgreSQLInstance must be deployed, and its PgBouncerOpens in a new tab Kubernetes Service must be reachable from the provisioning Job. The Job connects to the PostgreSQL cluster through that Service and authenticates as the default database user with the credentials stored in the {POSTGRESQL-INSTANCE-NAME}-pguser-{POSTGRESQL-INSTANCE-NAME} Kubernetes Secret.

A Cennso PostgreSQL User is represented by the PostgreSQLUser Custom Resource (CR). Applying this CR to a Management Cluster creates a Kubernetes Job that provisions a PostgreSQL user on an existing Cennso PostgreSQL Instance and applies the requested GRANT statement. In PostgreSQL terms, a user is a roleOpens in a new tab with the LOGIN attribute.

The sections below provide information about configuration parameters that you can specify in the PostgreSQLUser CR. For more information on how to provision a new user with privileges, see the Create a PostgreSQL user document.

Kubernetes cluster secret reference

To deploy the Cennso PostgreSQL User to a Core Cluster, you must specify a reference to the Kubernetes secretOpens in a new tab so the Core Cluster is accessible. You can do this using the following configuration parameters:

yaml

Set spec.connectionSecretRef.name to the name of the Core Cluster that contains the PostgreSQL cluster where the user should be created. The spec.connectionSecretRef.namespace configuration parameter defines the Kubernetes Namespace on the Management Cluster where the Kubernetes secret to access this Core Cluster is stored.

If you want to deploy the Cennso PostgreSQL User to the Management Cluster, do not specify spec.connectionSecretRef. In both cases, the target cluster must be the same as the one of the Cennso PostgreSQL Operator that manages the namespace of the database instances.

Target PostgreSQL Instance reference

To select the PostgreSQL cluster where the user is created, you must specify the PostgreSQLInstance name and the Kubernetes Namespace where it is deployed:

yaml

The spec.namespace must match spec.namespace of the PostgreSQLInstance. The spec.dbInstanceName must match the metadata.name of an existing PostgreSQLInstance resource.

The user-provisioning Job connects to the {POSTGRESQL-INSTANCE-NAME}-pgbouncer.{POSTGRESQL-CLUSTER-NAMESPACE}.svc:5432 Kubernetes Service and uses the credentials from the {POSTGRESQL-INSTANCE-NAME}-pguser-{POSTGRESQL-INSTANCE-NAME} Kubernetes Secret.

User identity

To define the PostgreSQL user that should be created, use the following configuration parameter:

yaml

The spec.username must be a valid, unquoted PostgreSQL identifier: a letter or underscore, followed by letters, digits, or underscores, up to 63 characters.

Password secret reference

Important

The Kubernetes secret with the user's password must be provisioned before you apply the PostgreSQLUser CR on your Management Cluster.

The password for the new user is read from a Kubernetes Secret on the target cluster, in the same Kubernetes Namespace as the provisioning Job. You can configure it using the following parameters:

yaml

The spec.passwordSecretRef.name is the name of the Kubernetes Secret that holds the user's password.

The spec.passwordSecretRef.key is the key within the Secret whose value is used as the password. The default value of spec.passwordSecretRef.key is password.

Grants

To configure the privileges of the new user, use the following configuration options:

  • spec.privileges
  • spec.grantScope
  • spec.target

All three combine into a single GRANTOpens in a new tab statement:

yaml

The example above produces GRANT SELECT, INSERT, UPDATE ON TABLE my_table TO {USERNAME};.

The spec.privileges is the list of PostgreSQL privileges to grant. The privileges must be valid for the object kind set by spec.grantScope, otherwise the Job fails:

ALL PRIVILEGES grants every privilege that applies to the object kind. For the meaning of each privilege, see the PostgreSQL privileges documentationOpens in a new tab.

The spec.grantScope configures the kind of PostgreSQL object that spec.target identifies. The supported values are:

  • DATABASE
  • SCHEMA
  • TABLE

A SCHEMA or TABLE must be in the default database of the instance, because the provisioning Job connects to that database. To give the user its own database, use spec.databaseOwner instead.

The spec.target is the name of the PostgreSQL object the privileges are granted on. It must be a plain, unqualified identifier of up to 64 characters, built from letters, digits, or underscores. Schema-qualified targets such as myschema.mytable are not supported.

Both spec.grantScope and spec.target are required whenever spec.privileges is not empty, and the Kubernetes API server rejects a resource that sets privileges without them. If spec.privileges is empty or omitted, the user is created without any additional privileges.

Database ownership

To make the new user the owner of an existing logical database, use the following configuration option:

yaml

The owner has full control of the database, including its publicOpens in a new tab schema. For more information about the ownership, see the official documentationOpens in a new tab.

The spec.databaseOwner must be a plain identifier of up to 64 characters, built from letters, digits, or underscores.

Note

The database referenced by spec.databaseOwner or by a DATABASE-scoped grant must be created before you apply the PostgreSQLUser, for example with a Cennso PostgreSQL Schema. If the database does not exist when the Job runs, the Job fails.

Job retries, lifetime, and deadline

To control how the user-provisioning Kubernetes JobOpens in a new tab behaves on failure and after completion, use the following configuration parameters:

yaml

The spec.backoffLimit configures the number of retries before the Job is marked as failed. For more information, see the pod backoff failure policyOpens in a new tab documentation.

The spec.ttlSecondsAfterFinished configures how long a finished Job (either Complete or Failed) is retained before it is automatically cleaned up. If omitted, the Job is not deleted automatically. For more information, see the TTL mechanism for finished JobsOpens in a new tab documentation.

Note

The Job exists as long as the PostgreSQLUser exists. After spec.ttlSecondsAfterFinished expires, the Job is deleted and then created again. The new Job run does not change the user because it creates the user only if it does not already exist. However, it reapplies the grants and starts a new Pod. Leave spec.ttlSecondsAfterFinished unset to avoid this behavior.

The spec.activeDeadlineSeconds configures a wall-clock deadline, measured from the Job start time, after which the Job is terminated and marked as failed. The default value is 600 seconds.

The spec.restartPolicy configures the restart policy of the Job Pod. The supported values are OnFailure and Never. The default value is OnFailure. For more information, see the pod lifecycleOpens in a new tab documentation.

Readiness and failed Jobs

The PostgreSQLUser becomes Ready when the Job has completed. A PostgreSQLUser that stays not ready has a Job that is still running or has failed. You can use the following commands to check the Job and its Pod in spec.namespace on the target cluster:

bash

A failed Job is not restarted automatically. To run it again, delete the Job, and a new one will be created:

bash

The same applies after changing spec.image, spec.restartPolicy, spec.username, spec.privileges, spec.grantScope, spec.target, or spec.databaseOwner of an existing PostgreSQLUser. The Pod template of a Kubernetes Job cannot be changed, so the update is rejected until the existing Job is deleted.

Image and pull secret

You can configure the image of the user-provisioning Job and the Kubernetes Secret used to pull it with the following configuration options:

yaml

The spec.imagePullSecretRef.name refers to a Kubernetes Secret that must exist on the target cluster in the same Kubernetes Namespace as the Job.