-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from jeliebig/feature/custom-onepassword-cli-…
…backend
- Loading branch information
Showing
8 changed files
with
137 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env sh | ||
|
||
# | ||
# The 1Password CLI (https://developer.1password.com/docs/cli) allows you to get secrets | ||
# from your vaults using secret references (https://developer.1password.com/docs/cli/secrets-reference-syntax). | ||
# Secrets can be referenced in configuration files as described | ||
# by the template syntax documentation (https://developer.1password.com/docs/cli/secrets-template-syntax). | ||
# | ||
# To use this secret backend, you need to install the 1Password CLI and sign in: | ||
# https://developer.1password.com/docs/cli/get-started | ||
# | ||
|
||
set -euf | ||
|
||
_ONEPASSWORD="${HELM_SECRETS_ONEPASSWORD_PATH:-op}" | ||
|
||
# shellcheck disable=SC2034 | ||
# https://developer.1password.com/docs/cli/secrets-reference-syntax/#syntax-rules | ||
_BACKEND_REGEX='op://[A-Za-z0-9\-_./ ]*' | ||
|
||
# shellcheck source=scripts/lib/backends/_custom.sh | ||
. "${SCRIPT_DIR}/lib/backends/_custom.sh" | ||
|
||
_onepassword() { | ||
# shellcheck disable=SC2086 | ||
set -- ${SECRET_BACKEND_ARGS} "$@" | ||
eval "$($_ONEPASSWORD signin)" | ||
$_ONEPASSWORD "$@" | ||
} | ||
|
||
_custom_backend_get_secret() { | ||
if [ $# -eq 1 ]; then | ||
_SECRET=$1 | ||
else | ||
_SECRET=$2 | ||
fi | ||
|
||
_onepassword read --force "${_SECRET}" | ||
} | ||
|
||
_custom_backend_decrypt_file() { | ||
input="${2}" | ||
# if omit then output to stdout | ||
output="${3:-}" | ||
|
||
# Templates supported by `op inject`: | ||
# https://developer.1password.com/docs/cli/secrets-template-syntax | ||
|
||
if [ "${output}" = "" ]; then | ||
_onepassword inject --force --in-file "${input}" | ||
else | ||
_onepassword inject --force --in-file "${input}" --out-file "${output}" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,27 @@ Alternately available via [homebrew](https://brew.sh/): | |
brew info vault | ||
``` | ||
|
||
### onepassword (optional) | ||
|
||
The 1Password CLI is only required to run the tests with the `HELM_SECRETS_BACKEND=custom-onepassword` environment variable. | ||
|
||
Instructions on how to install and set up the 1Password CLI can be found here: https://developer.1password.com/docs/cli/get-started | ||
|
||
Create the following test item before running the tests: | ||
|
||
```shell | ||
op item create --category=login \ | ||
--title='helm-secrets test' \ | ||
--vault='Private' \ | ||
'username=test-username' \ | ||
'password=mytestpassword123' \ | ||
'email[email][email protected]' \ | ||
'data.username[text]=a-test-name' \ | ||
'data.password[password]=testthispassword' \ | ||
'data 2.email[email][email protected]' \ | ||
'data 2.password[password]=my-test-could-be-different!' | ||
``` | ||
|
||
## Run | ||
|
||
If possible start the tests from the root of the repository. Then execute: | ||
|
11 changes: 11 additions & 0 deletions
11
tests/assets/values/custom-backend/onepassword-secrets.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
service: | ||
username: op://Private/helm-secrets test/username | ||
password: op://Private/helm-secrets test/password | ||
data: | ||
owner: op://Private/helm-secrets test/email | ||
names: | ||
- op://Private/helm-secrets test/data/username | ||
- op://Private/helm-secrets test/data 2/email | ||
passwords: | ||
- op://Private/helm-secrets test/data/password | ||
- op://Private/helm-secrets test/data 2/password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,37 @@ load '../bats/extensions/bats-file/load' | |
assert_output --partial 'production#global_secret' | ||
assert_success | ||
} | ||
|
||
@test "secret-backend: helm secrets --backend ${GIT_ROOT}/examples/backends/onepassword.sh" { | ||
if ! is_custom_backend "onepassword"; then | ||
skip | ||
fi | ||
|
||
FILE="${TEST_TEMP_DIR}/assets/values/custom-backend/onepassword-secrets.yaml" | ||
|
||
run "${HELM_BIN}" secrets --backend "${GIT_ROOT}/examples/backends/onepassword.sh" decrypt "${FILE}" | ||
|
||
refute_output --partial 'op://' | ||
assert_output --partial 'test-username' | ||
assert_output --partial 'mytestpassword123' | ||
assert_output --partial 'a-test-name' | ||
assert_output --partial '[email protected]' | ||
assert_success | ||
} | ||
|
||
@test "secret-backend: helm secrets + env HELM_SECRETS_BACKEND=${GIT_ROOT}/examples/backends/onepassword.sh" { | ||
if ! is_custom_backend "onepassword"; then | ||
skip | ||
fi | ||
|
||
FILE="${TEST_TEMP_DIR}/assets/values/custom-backend/onepassword-secrets.yaml" | ||
|
||
run env HELM_SECRETS_BACKEND="${GIT_ROOT}/examples/backends/onepassword.sh" WSLENV="HELM_SECRETS_BACKEND:${WSLENV}" "${HELM_BIN}" secrets decrypt "${FILE}" | ||
|
||
refute_output --partial 'op://' | ||
assert_output --partial 'test-username' | ||
assert_output --partial 'mytestpassword123' | ||
assert_output --partial 'a-test-name' | ||
assert_output --partial '[email protected]' | ||
assert_success | ||
} |