Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions docs/enterprise/externalsecrets/generators/postgresql.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: 'PostgreSQL User Generator'
description: 'Easily manage and rotate PostgreSQL Users in your setup'
---

<Note>
The External Secrets Enterprise product suite is a premium product.
It requires a specific subscription. Contact us for more information.
</Note>

<Tip>
In order to use the PostgreSQL User Generator, you must have the Enterprise Distribution of ESO available via [ESI Agent](../../esi-agent/quickstart.mdx).
</Tip>

## Introduction

The PostgreSQL User Generator for ESO allows you to dynamically create and rotate database users with native integration.

This is useful when providing applications with scoped credentials to PostgreSQL, reducing the operational overhead of manual user management and improving security posture.

## Output Keys and Values

| Key | Description |
| ---------- | --------------------------------- |
| `username` | The generated PostgreSQL username |
| `password` | The generated PostgreSQL password |

## Parameters

| Key | Default | Description |
| ------------------------- | ------------ | ----------- |
| `database` | `postgres` | The name of the PostgreSQL database to connect to. |
| `host` | **Required** | The hostname or IP of the PostgreSQL server. |

Check warning on line 33 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L33

Did you really mean 'hostname'?
| `port` | `5432` | The port used to connect to the PostgreSQL server. |
| `auth.username` | `postgres` | Admin username for authentication. |
| `auth.password.name` | **Required** | Kubernetes secret name containing the admin password. |
| `auth.password.key` | **Required** | Key in the secret that holds the admin password. |
| `user.username` | **Required** | The username to create. A random suffix will be appended. |
| `user.suffixSize` | `8` | Length of the random suffix appended to the username. If set to 0, no suffix is appended. |
| `user.attributes` | `[]` | List of PostgreSQL attributes to assign. Each item must be an object with a name field (e.g., `CREATEDBT`) and an optional value field for attributes that require a parameter (e.g.,`CONNECTION LIMIT`). |
| `user.roles` | `[]` | List of existing roles to grant to the user. Non-existent roles are created with no attributes. |
| `user.destructiveCleanup` | `false` | If `true`, all owned objects are dropped during cleanup. Otherwise, ownership is reassigned to the `reassignTo` user. |
| `user.reassignTo` | - | The name of the role to which all owned objects should be reassigned during cleanup. `auth.username` is used if not set. |

## Set up

### PostgreSQL Permissions

The admin user provided in the spec must have sufficient permissions to create and delete users in PostgreSQL. Typically, the built-in `postgres` admin account has the required permissions.

### Generator Config

<CodeGroup>
```yaml
apiVersion: generators.external-secrets.io/v1alpha1

Check warning on line 55 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L55

Did you really mean 'apiVersion'?
kind: PostgreSql
metadata:
name: postgres-generator
namespace: default

Check warning on line 59 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L59

Did you really mean 'namespace'?
spec:
host: postgres.default.svc.cluster.local
port: "5432"
database: postgres
auth:
username: postgres
password:
name: pg-admin-secret
key: password
user:
username: appuser

Check warning on line 70 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L70

Did you really mean 'appuser'?
suffixSize: 6

Check warning on line 71 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L71

Did you really mean 'suffixSize'?
attributes:
- name: CREATEDB
- name: "CONNECTION LIMIT"
value: "10"
roles:
- pg_read_all_data

Check warning on line 77 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L77

Did you really mean 'pg_read_all_data'?
- custom_role

Check warning on line 78 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L78

Did you really mean 'custom_role'?
destructiveCleanup: false

Check warning on line 79 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L79

Did you really mean 'destructiveCleanup'?
```
</CodeGroup>

### ExternalSecret Config

```yaml
apiVersion: external-secrets.io/v1
kind: ExternalSecret
metadata:
name: postgres-credentials
namespace: default
spec:
refreshInterval: 1h # Rotates every 1 hour
dataFrom:
- sourceRef:
generatorRef:
apiVersion: generators.external-secrets.io/v1alpha1
kind: PostgreSql
name: postgres-generator
```

### Using the Generated Secret

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: my-image:latest
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
```

### Notes and Considerations

* If destructiveCleanup is true, owned objects are dropped before dropping the user.

Check warning on line 137 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L137

Did you really mean 'destructiveCleanup'?
* If destructiveCleanup is false, ownership is reassigned to the user defined in user.reassignTo.

Check warning on line 138 in docs/enterprise/externalsecrets/generators/postgresql.mdx

View check run for this annotation

Mintlify / Mintlify Validation - vale-spellcheck

docs/enterprise/externalsecrets/generators/postgresql.mdx#L138

Did you really mean 'destructiveCleanup'?
* If user.reassignTo is not set, the admin user defined in auth.username is used for reassignment.
* If user.reassignTo does not exists, it will be created with no attributes or roles.
* Roles listed in user.roles are created if missing and assigned to the generated user.
* Only the standard PostgreSQL attributes (SUPERUSER, CREATEDB, CREATEROLE, REPLICATION) are supported.
3 changes: 2 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"group": "Generators",
"pages": [
"docs/enterprise/externalsecrets/generators/iam-keys",
"docs/enterprise/externalsecrets/generators/neo4j"
"docs/enterprise/externalsecrets/generators/neo4j",
"docs/enterprise/externalsecrets/generators/postgresql"
]
},
{
Expand Down
Loading