Skip to content

Commit

Permalink
Add support for reading AES backend password from external command
Browse files Browse the repository at this point in the history
  • Loading branch information
juergenhoetzel committed Jan 2, 2022
1 parent d636b69 commit 2051e24
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
16 changes: 16 additions & 0 deletions cfg/aesbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ import (
"os"
"path/filepath"

"os/exec"
"strings"

"golang.org/x/crypto/scrypt"
)

// PasswordEnvVar defines the environment variable name that should
// contain the configuration password.
const PasswordEnvVar = "BEEHIVE_CONFIG_PASSWORD"

// PasswordCmdEnvVar defines the environment variable name that should
// contain the external command to get the configuration password
const PasswordCmdEnvVar = "BEEHIVE_CONFIG_PASSWORD_COMMAND"

// EncryptedHeaderPrefix is added to the encrypted configuration
// to make it possible to detect it's an encrypted configuration file
const EncryptedHeaderPrefix = "beehiveconf+"
Expand Down Expand Up @@ -227,6 +234,15 @@ func getPassword(u *url.URL) (string, error) {
if p != "" {
return p, nil
}
if cmd := os.Getenv(PasswordCmdEnvVar); cmd != "" {
args := strings.Split(cmd, " ")
cmd := exec.Command(args[0], args[1:]...)
output, err := cmd.Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(output)), nil
}

if u != nil && u.User != nil {
p = u.User.Username()
Expand Down
7 changes: 6 additions & 1 deletion docs/config_encryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ Will happily detect and load an encrypted configuration file.

## Using user keyrings to store the password

A sample wrapper script (Linux only) is provided in [tools/encrypted-config-wrapper] that will read the configuration password from the sessions's keyring.
You can also set the `BEEHIVE_CONFIG_PASSWORD_COMMAND` environment variable to automatically retrieve the password from an external command.
For example this environment setting will retrieve the password using the Secret Service API (Gnome Keyring):

```
export BEEHIVE_CONFIG_PASSWORD_COMMAND="secret-tool lookup user behive"
```

Something similar could be written to do it on macOS using Keychain and its `security(1)` CLI.

Expand Down

0 comments on commit 2051e24

Please sign in to comment.