Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for new rootless password rotation workflow for DB Static Roles #28374

Merged
merged 10 commits into from
Oct 7, 2024
5 changes: 5 additions & 0 deletions website/content/api-docs/secret/databases/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ this in order to know the password.
- `username` `(string: <required>)` – Specifies the database username that this
Vault role corresponds to.

- `self_managed_password` `(string)` – <EnterpriseAlert product="vault" inline />
Copy link
Contributor

@fairclothjm fairclothjm Sep 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to keep nitpicking this PR, but given we don't have plans to add this to any other DBs anytime soon should we move this to the postgres API specific page?

We could do something similar to how we extend the connection config...

## Create static role

In addition to the parameters defined by the Database backend's
[Create static role](/vault/api-docs/secret/databases#create-static-role)
endpoint, this plugin has a number of parameters to further configure a static role.

- `self_managed_password` `(string)` – ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where we should document it depends on where it's defined, not how its use is limited.

  • If the field is part of the Vault API and recognized as a valid field in a request to the /database/static-roles/:name endpoint, we should define it here and note the limited use.

  • If the field is part of the PostgreSQL plugin API and recognized as a valid field in a request to the /database/config/<postgres_plugin_name> endpoint (or any other endpoint specific to the plugin), we should define it on the PostgreSQL page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification, @schavis! This field is part of the Vault API, so I opted to define it here and noted its limited use to select DBs.

The password corresponding to the username in the database. Required when using
the Rootless Password Rotation workflow for static roles. Only enabled for select
DB engines (Postgres).

- `db_name` `(string: <required>)` - The name of the database connection to use
for this role.

Expand Down
4 changes: 4 additions & 0 deletions website/content/api-docs/secret/databases/postgresql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ has a number of parameters to further configure a connection.

- `password` `(string: "")` - The root credential password used in the connection URL.

- `self_managed` `(boolean: "false")` - <EnterpriseAlert product="vault" inline /> If
set, allows onboarding static roles with a rootless connection configuration. Mutually
exclusive with `username` and `password`. If set, will force `verify_connection` to be false.

- `tls_ca` `(string: "")` - The x509 CA file for validating the certificate
presented by the PostgreSQL server. Must be PEM encoded.

Expand Down
70 changes: 67 additions & 3 deletions website/content/docs/secrets/databases/postgresql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ options, including SSL options, can be found in the [pgx][pgxlib] and

## Capabilities

| Plugin Name | Root Credential Rotation | Dynamic Roles | Static Roles | Username Customization |
| ---------------------------- | ------------------------ | ------------- | ------------ | ---------------------- |
| `postgresql-database-plugin` | Yes | Yes | Yes | Yes (1.7+) |
| Plugin Name | Root Credential Rotation | Dynamic Roles | Static Roles | Username Customization | Credential Types |
| ---------------------------- | ------------------------ | ------------- | ------------ | ---------------------- | ---------------------------- |
| `postgresql-database-plugin` | Yes | Yes | Yes | Yes (1.7+) | password, gcp_iam |

## Setup

Expand Down Expand Up @@ -84,6 +84,70 @@ the proper permission, it can generate credentials.
username v-vaultuse-my-role-x
```

## Rootless Configuration and Password Rotation for Static Roles
vinay-gopalan marked this conversation as resolved.
Show resolved Hide resolved

<EnterpriseAlert product="vault" />

The PostgreSQL secrets engine supports using Static Roles and its password rotation mechanisms with a Rootless
DB connection configuration. In this workflow, a static DB user can be onboarded onto Vault's static role rotation
mechanism without the need of privileged root accounts to configure the connection. Instead of using a single root
connection, multiple dedicated connections to the DB are made for each static role. This workflow does not support
dynamic roles/credentials.

~> Note: It is **highly recommended** that the DB users being onboarded as static roles
have the minimum set of privileges. Each static role will open a new connection into the DB.
Granting minimum privileges to the DB users being onboarded ensures that multiple
highly-privileged connections to an external system are not being made.

~> Note: Out-of-band password rotations will cause Vault to be out of sync with the state of
the DB user, and will require manually updating the user's password in the external PostgreSQL
DB in order to resolve any errors encountered during rotation.

1. Enable the database secrets engine if it is not already enabled:

```shell-session
$ vault secrets enable database
Success! Enabled the database secrets engine at: database/
```

By default, the secrets engine will enable at the name of the engine. To
enable the secrets engine at a different path, use the `-path` argument.

1. Configure connection to DB without root credentials and enable the rootless
workflow by setting the `self_managed` parameter:

```shell-session
$ vault write database/config/my-postgresql-database \
plugin_name="postgresql-database-plugin" \
allowed_roles="my-role" \
connection_url="postgresql://{{username}}:{{password}}@localhost:5432/database-name" \
self_managed=true
```

1. Configure a static role that creates a dedicated connection to a user in the DB with
the `self_managed_password` parameter:

```shell-session
$ vault write database/static-roles/my-static-role \
db_name="my-postgresql-database" \
username="staticuser" \
self_managed_password="password" \
rotation_period="1h"
```

1. Read static credentials:

```shell-session
$ vault read database/static-creds/static-test
Key Value
--- -----
last_vault_rotation 2024-09-11T14:15:13.764783-07:00
password XZY42BVc-UO5bMsbgxrW
rotation_period 1h
ttl 59m55s
username staticuser
```

## Client x509 certificate authentication

This plugin supports using PostgreSQl's [x509 Client-side Certificate Authentication](https://www.postgresql.org/docs/16/libpq-ssl.html#LIBPQ-SSL-CLIENTCERT).
Expand Down
Loading