Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
faf8831
PBM-1268 Securely Store CLI Credentials using systemd
rasika-chivate Mar 19, 2026
b64558e
changed the filke name
rasika-chivate Mar 19, 2026
de45d28
fix code block formatting
rasika-chivate Mar 19, 2026
c65721d
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
97d4af4
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
0ceb2b8
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
77ab1b1
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
c9388cb
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
a61e122
crosslink for improving the docs
rasika-chivate Mar 19, 2026
1139738
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
db640c0
Update secure-credentials-systemd.md
rasika-chivate Mar 19, 2026
79184c1
Update docs/install/secure-credentials-systemd.md
rasika-chivate Mar 20, 2026
97075f7
Initial plan
Copilot Mar 20, 2026
bfe771b
Update docs/install/configure-authentication.md
rasika-chivate Mar 20, 2026
69131bb
Clarify Step 1 creates a PBM agent YAML config file, not a raw URI file
Copilot Mar 20, 2026
2de73dc
Merge pull request #349 from percona/copilot/sub-pr-348
rasika-chivate Mar 20, 2026
f085235
Update configure-authentication.md
rasika-chivate Mar 31, 2026
4790bcd
Update docs/install/secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
9ff2c65
Update docs/install/secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
e2242ff
Address PR review comments: use %d specifier, add OS list, soften war…
Copilot Apr 1, 2026
3c5b7b9
Update secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
c30b52c
Update secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
bd1b2ab
Update docs/install/secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
b5a6dc9
Update docs/install/secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
4bd9902
Narrow overview scope to pbm-agent mongodb-uri; note technique applie…
Copilot Apr 1, 2026
7edfaed
Update secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
f902c6c
Merge branch 'PBM-1268-Securely-Store-CLI-Credentials-using-systemd' …
rasika-chivate Apr 1, 2026
46db4f5
Fix Step 4: mention ExecStart update and remove broken section reference
Copilot Apr 1, 2026
5bf1ba4
Update secure-credentials-systemd.md
rasika-chivate Apr 1, 2026
19bc213
Merge branch 'PBM-1268-Securely-Store-CLI-Credentials-using-systemd' …
rasika-chivate Apr 1, 2026
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
4 changes: 4 additions & 0 deletions docs/install/configure-authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

The `pbm-agent.service` systemd unit file includes the location of the environment file. You set the MongoDB URI connection string for the `PBM_MONGODB_URI` variable within the environment file for every `pbm-agent`.

!!! warning "Security recommendation"
Avoid storing credentials (such as `PBM_MONGODB_URI`) in plaintext environment variables or service files. Instead, use `systemd` credentials for secure, encrypted, runtime-only access. For step-by-step instructions, see [Secure credentials with systemd](secure-credentials-systemd.md).

Check warning on line 66 in docs/install/configure-authentication.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/configure-authentication.md#L66

[Vale.Spelling] Did you really mean 'plaintext'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'plaintext'?", "location": {"path": "docs/install/configure-authentication.md", "range": {"start": {"line": 66, "column": 62}}}, "severity": "WARNING"}

Check warning on line 66 in docs/install/configure-authentication.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/configure-authentication.md#L66

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/configure-authentication.md", "range": {"start": {"line": 66, "column": 251}}}, "severity": "WARNING"}


??? tip "How to find the environment file"

In Ubuntu and Debian, the pbm-agent.service systemd unit file is at the path `/lib/systemd/system/pbm-agent.service`.
Expand Down
97 changes: 97 additions & 0 deletions docs/install/secure-credentials-systemd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Secure credential management with systemd

Check warning on line 1 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L1

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 1, "column": 37}}}, "severity": "WARNING"}

## Overview

Percona Backup for MongoDB (PBM) requires access to sensitive credentials such as:

- **MongoDB connection URI** (`PBM_MONGODB_URI`)

- **Object storage credentials** defined in PBM configuration (pbm config)

By default, these credentials are often stored in plaintext in environment variables or configuration files. This introduces security risks such as credential leakage and unauthorized access.

Check warning on line 11 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L11

[Vale.Spelling] Did you really mean 'plaintext'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'plaintext'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 11, "column": 51}}}, "severity": "WARNING"}

This section describes how to securely manage PBM credentials using **systemd service credentials**.

Check warning on line 13 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L13

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 13, "column": 71}}}, "severity": "WARNING"}

## Why use systemd credentials?

Check warning on line 15 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L15

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 15, "column": 12}}}, "severity": "WARNING"}

Storing credentials in plaintext significantly increases the risk of compromise. Secrets placed in configuration files or environment variables can be exposed through:

Check warning on line 17 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L17

[Vale.Spelling] Did you really mean 'plaintext'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'plaintext'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 17, "column": 24}}}, "severity": "WARNING"}

- File access
- Process inspection (e.g., `ps`, `/proc`)

Check failure on line 20 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L20

[Google.Latin] Use 'for example' instead of 'e.g.'.
Raw output
{"message": "[Google.Latin] Use 'for example' instead of 'e.g.'.", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 20, "column": 23}}}, "severity": "ERROR"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be fixed according to Vale's suggestion?

- Unauthorized system access.

**`systemd` credentials** mitigate these risks by:

- Encrypting credentials at rest
- Decrypting them only at service runtime
- Storing them in a temporary, non-swappable directory
- Restricting access to the service itself


## Prerequisites

- systemd version 250 or higher

Check warning on line 33 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L33

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 33, "column": 3}}}, "severity": "WARNING"}
- Root or sudo privileges

Check warning on line 34 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L34

[Vale.Spelling] Did you really mean 'sudo'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'sudo'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 34, "column": 11}}}, "severity": "WARNING"}
- (Optional) TPM2 support for hardware-backed encryption
- Kernel 5.4+


## Procedure

Here are the steps to integrate PBM with systemd's [System and service credentials :octicons-link-external-16:](https://systemd.io/CREDENTIALS/)

Check warning on line 41 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L41

[Vale.Spelling] Did you really mean 'systemd's'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd's'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 41, "column": 42}}}, "severity": "WARNING"}
{.power-number}

1. Create a **temporary PBM agent YAML config file** containing the `mongodb-uri` key with your connection string:

```sh
echo "mongodb-uri: mongodb://pbmuser:secretpwd@localhost:27017/?authSource=admin" > pbm_uri.yaml
```

2. Encrypt the credential using the local system key (and Trusted Platform Module version 2.0 if available):

```sh
systemd-creds encrypt --name=pbm_connection.yaml pbm_uri.yaml pbm_connection.yaml.cred
```

3. Securely delete the plain text file:

```sh
shred -u pbm_uri.yaml
```

4. Edit the systemd unit file (default location at `/lib/systemd/system/pbm-agent.service`) and in the `[Service]` section, add the `LoadCredentialEncrypted` and `PrivateMounts` directives:

Check warning on line 62 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L62

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 62, "column": 13}}}, "severity": "WARNING"}

```
[Service]
LoadCredentialEncrypted=pbm_connection.yaml:/path/to/pbm_connection.yaml.cred
PrivateMounts=yes
ExecStart=/usr/bin/pbm-agent -f /run/credentials/%n/pbm_connection.yaml
```

5. Reload the systemd manager configuration:

Check warning on line 71 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L71

[Vale.Spelling] Did you really mean 'systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 71, "column": 15}}}, "severity": "WARNING"}

```sh
sudo systemctl daemon-reload
```

6. Restart the PBM agent:

```sh
sudo systemctl restart pbm-agent
```

??? info "What happens under the hood"
Systemd automatically decrypts the credential during service startup and places it in a temporary, non-swappable directory.

Check warning on line 84 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/install/secure-credentials-systemd.md#L84

[Vale.Spelling] Did you really mean 'Systemd'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'Systemd'?", "location": {"path": "docs/install/secure-credentials-systemd.md", "range": {"start": {"line": 84, "column": 9}}}, "severity": "WARNING"}

- The path to the decrypted plaintext is stored in the `$CREDENTIALS_DIRECTORY` environment variable.
- In the example above, the PBM agent will read the contents of the file at `%d/pbm_connection.yaml` as its connection string.


## How to verify?

Run the following command to ensure the service can see the credential. This file is only accessible while the service is running and is stored in a secure, temporary directory.

```sh
sudo cat /run/credentials/pbm-agent.service/pbm_connection.yaml
```

1 change: 1 addition & 0 deletions mkdocs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ nav:
- 2. Set up and configure:
- Initial setup: install/initial-setup.md
- install/configure-authentication.md
- Secure credentials with systemd: install/secure-credentials-systemd.md
- install/backup-storage.md
- Start the pbm-agent process: install/start-pbm-agent.md
- Backup and restore:
Expand Down
Loading