Skip to content
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

secrets+*-import:// added syntax checks #400

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `secrets+*-import://` added syntax checks

## [4.5.0] - 2023-08-14

### Added
Expand Down
22 changes: 22 additions & 0 deletions scripts/commands/downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ downloader() {
_key_path=$(printf '%s' "${_key_and_file}" | cut -d '?' -f1)
file=$(printf '%s' "${_key_and_file}" | cut -d '?' -f2-)

# check if key file is given
if [ "${_key_path}" = "${file}" ]; then
fatal "Invalid syntax: secrets+gpg-import://[path to key]?[path secrets.yaml]"
fi

if ! _key_location_allowed "${_key_path}"; then
fatal "Key location '%s' is not allowed" "${_key_path}"
fi
Expand Down Expand Up @@ -67,6 +72,12 @@ downloader() {

_key_location=$(printf '%s' "${_key_and_file}" | cut -d '?' -f1)
file=$(printf '%s' "${_key_and_file}" | cut -d '?' -f2-)

# check if key file is given
if [ "${_key_location}" = "${file}" ]; then
fatal "Invalid syntax: secrets+gpg-import-kubernetes://[path to key]?[path secrets.yaml]"
fi

_gpg_init_kubernetes "${_key_location}"
;;
secrets+age-import://*)
Expand All @@ -91,6 +102,11 @@ downloader() {
_key_path=$(printf '%s' "${_key_and_file}" | cut -d '?' -f1)
file=$(printf '%s' "${_key_and_file}" | cut -d '?' -f2-)

# check if key file is given
if [ "${_key_path}" = "${file}" ]; then
fatal "Invalid syntax: secrets+age-import://[path to key]?[path secrets.yaml]"
fi

if ! _key_location_allowed "${_key_path}"; then
fatal "Key location '%s' is not allowed" "${_key_path}"
fi
Expand Down Expand Up @@ -118,6 +134,12 @@ downloader() {

_key_location=$(printf '%s' "${_key_and_file}" | cut -d '?' -f1)
file=$(printf '%s' "${_key_and_file}" | cut -d '?' -f2-)

# check if key file is given
if [ "${_key_location}" = "${file}" ]; then
fatal "Invalid syntax: secrets+age-import-kubernetes://[path to key]?[path secrets.yaml]"
fi

_age_init_kubernetes "${_key_location}"
;;
secrets+literal://*)
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/template.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,22 @@ load '../bats/extensions/bats-file/load'
run env GNUPGHOME="${HOME}/${BATS_TEST_NUMBER}" gpgconf --kill gpg-agent
}

@test "template: helm template w/ chart + secrets.age.yaml + secrets+gpg-import:// + without key file" {
if on_windows || ! is_backend "sops"; then
skip
fi

VALUES="assets/values/${HELM_SECRETS_BACKEND}/not-found.age.yaml"
VALUES_PATH="${TEST_TEMP_DIR}/${VALUES}"

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" template "$(_winpath "${TEST_TEMP_DIR}/chart")" -f "secrets+gpg-import://${VALUES_PATH}" 2>&1

assert_output --partial "Invalid syntax: secrets+gpg-import://[path to key]?[path secrets.yaml]"
assert_failure
}

@test "template: helm template w/ chart + secrets.gpg_key.yaml + secrets+gpg-import://git://" {
if on_windows || ! is_backend "sops"; then
skip
Expand Down Expand Up @@ -1375,6 +1391,22 @@ load '../bats/extensions/bats-file/load'
assert_success
}

@test "template: helm template w/ chart + secrets.age.yaml + secrets+age-import:// + without key file" {
if on_windows || ! is_backend "sops"; then
skip
fi

VALUES="assets/values/${HELM_SECRETS_BACKEND}/not-found.age.yaml"
VALUES_PATH="${TEST_TEMP_DIR}/${VALUES}"

create_chart "${TEST_TEMP_DIR}"

run "${HELM_BIN}" template "$(_winpath "${TEST_TEMP_DIR}/chart")" -f "secrets+age-import://${VALUES_PATH}" 2>&1

assert_output --partial "Invalid syntax: secrets+age-import://[path to key]?[path secrets.yaml]"
assert_failure
}

@test "template: helm template w/ chart + secrets.age.yaml + secrets+age-import://git://" {
if on_windows || ! is_backend "sops"; then
skip
Expand Down