2022-06-17 00:30:53 +02:00
|
|
|
---
|
|
|
|
title: How to provide your passwords
|
|
|
|
eleventyNavigation:
|
|
|
|
key: 🔒 Provide your passwords
|
|
|
|
parent: How-to guides
|
|
|
|
order: 2
|
|
|
|
---
|
2023-12-31 00:10:50 +01:00
|
|
|
## Providing passwords and secrets to borgmatic
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
If you want to use a Borg repository passphrase or database passwords with
|
|
|
|
borgmatic, you can set them directly in your borgmatic configuration file,
|
2023-10-10 18:34:55 +02:00
|
|
|
treating those secrets like any other option value. For instance, you can
|
|
|
|
specify your Borg passhprase with:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
encryption_passphrase: yourpassphrase
|
|
|
|
```
|
|
|
|
|
|
|
|
But if you'd rather store them outside of borgmatic, whether for convenience
|
|
|
|
or security reasons, read on.
|
2022-06-17 00:30:53 +02:00
|
|
|
|
2023-12-31 00:48:55 +01:00
|
|
|
### Delegating to another application
|
2023-12-31 00:10:50 +01:00
|
|
|
|
|
|
|
borgmatic supports calling another application such as a password manager to
|
|
|
|
obtain the Borg passphrase to a repository.
|
|
|
|
|
|
|
|
For example, to ask the *Pass* password manager to provide the passphrase:
|
|
|
|
```yaml
|
|
|
|
encryption_passcommand: pass path/to/borg-repokey
|
|
|
|
```
|
|
|
|
|
|
|
|
### Environment variable interpolation
|
|
|
|
|
2022-06-17 05:49:15 +02:00
|
|
|
<span class="minilink minilink-addedin">New in version 1.6.4</span> borgmatic
|
|
|
|
supports interpolating arbitrary environment variables directly into option
|
|
|
|
values in your configuration file. That means you can instruct borgmatic to
|
|
|
|
pull your repository passphrase, your database passwords, or any other option
|
|
|
|
values from environment variables. For instance:
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
```yaml
|
2023-10-10 18:34:55 +02:00
|
|
|
encryption_passphrase: ${YOUR_PASSPHRASE}
|
2022-06-17 00:30:53 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
this option in the `storage:` section of your configuration.
|
|
|
|
|
2023-10-10 18:34:55 +02:00
|
|
|
This uses the `YOUR_PASSPHRASE` environment variable as your encryption
|
|
|
|
passphrase. Note that the `{` `}` brackets are required. `$YOUR_PASSPHRASE` by
|
2022-08-22 06:48:37 +02:00
|
|
|
itself will not work.
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
In the case of `encryption_passphrase` in particular, an alternate approach
|
|
|
|
is to use Borg's `BORG_PASSPHRASE` environment variable, which doesn't even
|
|
|
|
require setting an explicit `encryption_passphrase` value in borgmatic's
|
|
|
|
configuration file.
|
|
|
|
|
|
|
|
For [database
|
|
|
|
configuration](https://torsion.org/borgmatic/docs/how-to/backup-your-databases/),
|
|
|
|
the same approach applies. For example:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
postgresql_databases:
|
|
|
|
- name: users
|
2023-10-10 18:34:55 +02:00
|
|
|
password: ${YOUR_DATABASE_PASSWORD}
|
2022-06-17 00:30:53 +02:00
|
|
|
```
|
|
|
|
|
2023-07-12 07:10:57 +02:00
|
|
|
<span class="minilink minilink-addedin">Prior to version 1.8.0</span> Put
|
|
|
|
this option in the `hooks:` section of your configuration.
|
|
|
|
|
2023-10-10 18:34:55 +02:00
|
|
|
This uses the `YOUR_DATABASE_PASSWORD` environment variable as your database
|
2022-06-17 00:30:53 +02:00
|
|
|
password.
|
|
|
|
|
2022-06-17 05:23:16 +02:00
|
|
|
|
2023-12-31 00:10:50 +01:00
|
|
|
#### Interpolation defaults
|
2022-06-17 00:30:53 +02:00
|
|
|
|
2023-10-10 18:34:55 +02:00
|
|
|
If you'd like to set a default for your environment variables, you can do so
|
|
|
|
with the following syntax:
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
```yaml
|
2023-10-10 18:34:55 +02:00
|
|
|
encryption_passphrase: ${YOUR_PASSPHRASE:-defaultpass}
|
2022-06-17 00:30:53 +02:00
|
|
|
```
|
|
|
|
|
2023-10-10 18:34:55 +02:00
|
|
|
Here, "`defaultpass`" is the default passphrase if the `YOUR_PASSPHRASE`
|
2022-06-17 00:30:53 +02:00
|
|
|
environment variable is not set. Without a default, if the environment
|
|
|
|
variable doesn't exist, borgmatic will error.
|
|
|
|
|
|
|
|
|
2023-12-31 00:10:50 +01:00
|
|
|
#### Disabling interpolation
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
To disable this environment variable interpolation feature entirely, you can
|
|
|
|
pass the `--no-environment-interpolation` flag on the command-line.
|
|
|
|
|
2022-06-23 19:25:46 +02:00
|
|
|
Or if you'd like to disable interpolation within a single option value, you
|
|
|
|
can escape it with a backslash. For instance, if your password is literally
|
|
|
|
`${A}@!`:
|
|
|
|
|
|
|
|
```yaml
|
2023-07-12 07:10:57 +02:00
|
|
|
encryption_passphrase: \${A}@!
|
2022-06-23 19:25:46 +02:00
|
|
|
```
|
2022-06-17 00:30:53 +02:00
|
|
|
|
2023-12-31 00:10:50 +01:00
|
|
|
## Related features
|
2022-06-17 00:30:53 +02:00
|
|
|
|
|
|
|
Another way to override particular options within a borgmatic configuration
|
|
|
|
file is to use a [configuration
|
|
|
|
override](https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#configuration-overrides)
|
|
|
|
on the command-line. But please be aware of the security implications of
|
|
|
|
specifying secrets on the command-line.
|
|
|
|
|
|
|
|
Additionally, borgmatic action hooks support their own [variable
|
|
|
|
interpolation](https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/#variable-interpolation),
|
|
|
|
although in that case it's for particular borgmatic runtime values rather than
|
|
|
|
(only) environment variables.
|
2023-10-10 18:16:58 +02:00
|
|
|
|
|
|
|
Lastly, if you do want to specify your passhprase directly within borgmatic
|
|
|
|
configuration, but you'd like to keep it in a separate file from your main
|
|
|
|
configuration, you can [use a configuration include or a merge
|
|
|
|
include](https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#configuration-includes)
|
|
|
|
to pull in an external password.
|