Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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"
We recommend using `systemd` credentials for secure, encrypted, runtime-only access rather than storing credentials (such as `PBM_MONGODB_URI`) in plaintext environment variables or service files. 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

[Google.We] Try to avoid using first-person plural like 'We'.
Raw output
{"message": "[Google.We] Try to avoid using first-person plural like 'We'.", "location": {"path": "docs/install/configure-authentication.md", "range": {"start": {"line": 66, "column": 5}}}, "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 'plaintext'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'plaintext'?", "location": {"path": "docs/install/configure-authentication.md", "range": {"start": {"line": 66, "column": 152}}}, "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": 262}}}, "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
112 changes: 112 additions & 0 deletions docs/install/secure-credentials-systemd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# 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

This guide describes how to securely store the **MongoDB connection URI** (`mongodb-uri`) for `pbm-agent` using **systemd service credentials**. The same technique can be applied to other sensitive PBM credentials, such as object storage credentials in the PBM configuration.

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 5, "column": 115}}}, "severity": "WARNING"}

By default, 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 7 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

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

[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": 7, "column": 45}}}, "severity": "WARNING"}

## Why use systemd credentials?

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 9, "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 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": 24}}}, "severity": "WARNING"}

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

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 14, "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 27 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

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

[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": 27, "column": 3}}}, "severity": "WARNING"}

To check the installed `systemd` version on your system, run:

```bash
systemctl --version
```

??? example "Output"

```sh
systemd 252 (252.5-2ubuntu3)
+PAM +AUDIT +SELINUX ...
```

The following operating systems meet this requirement:

- RHEL/OL/Rocky Linux 9
- Ubuntu 24.04
- Debian 12
- Amazon Linux 2023

- Root or sudo privileges

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 49, "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 56 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

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

[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": 56, "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 (for example, `/lib/systemd/system/pbm-agent.service` on Debian/Ubuntu or `/usr/lib/systemd/system/pbm-agent.service` on RHEL-based distributions). In the `[Service]` section, add the `LoadCredentialEncrypted` and `PrivateMounts` directives, and update `ExecStart` to pass the decrypted credential file to `pbm-agent`:

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 77, "column": 13}}}, "severity": "WARNING"}

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

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

Step 4 references an “earlier How to find the environment file section”, but that section doesn’t exist on this page. Please either link directly to the relevant section in configure-authentication.md (or another page), or rephrase/remove the reference so the instructions are self-contained.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Removed the reference to the non-existent section. Step 4 now directly lists the distro-specific paths: /lib/systemd/system/pbm-agent.service for Debian/Ubuntu and /usr/lib/systemd/system/pbm-agent.service for RHEL-based distributions. Committed in 46db4f5.

```

5. Reload the systemd manager configuration:

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

View workflow job for this annotation

GitHub Actions / vale

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

[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": 86, "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 99 in docs/install/secure-credentials-systemd.md

View workflow job for this annotation

GitHub Actions / vale

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

[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": 99, "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 YAML configuration file at `%d/pbm_connection.yaml`, which contains the `mongodb-uri` setting with 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