-
Notifications
You must be signed in to change notification settings - Fork 23
PBM-1268 Securely Store CLI Credentials using systemd #348
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
Changes from 16 commits
faf8831
b64558e
de45d28
c65721d
97d4af4
0ceb2b8
77ab1b1
c9388cb
a61e122
1139738
db640c0
79184c1
97075f7
bfe771b
69131bb
2de73dc
f085235
4790bcd
9ff2c65
e2242ff
3c5b7b9
c30b52c
bd1b2ab
b5a6dc9
4bd9902
7edfaed
f902c6c
46db4f5
5bf1ba4
19bc213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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
|
||
|
|
||
| ## Overview | ||
|
|
||
| Percona Backup for MongoDB (PBM) requires access to sensitive credentials such as: | ||
|
|
||
| - **MongoDB connection URI** (`PBM_MONGODB_URI`) | ||
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - **Object storage credentials** defined in PBM configuration (pbm config) | ||
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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
|
||
|
|
||
| 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
|
||
|
|
||
| ## Why use systemd credentials? | ||
|
Check warning on line 15 in docs/install/secure-credentials-systemd.md
|
||
|
|
||
| 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
|
||
|
|
||
| - File access | ||
| - Process inspection (e.g., `ps`, `/proc`) | ||
|
Check failure on line 20 in docs/install/secure-credentials-systemd.md
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Root or sudo privileges | ||
|
Check warning on line 34 in docs/install/secure-credentials-systemd.md
|
||
| - (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
|
||
| {.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
|
||
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ``` | ||
| [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 | ||
| ``` | ||
rasika-chivate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 5. Reload the systemd manager configuration: | ||
|
Check warning on line 71 in docs/install/secure-credentials-systemd.md
|
||
|
|
||
| ```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
|
||
|
|
||
| - 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. | ||
rasika-chivate marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## 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 | ||
| ``` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.