-
Notifications
You must be signed in to change notification settings - Fork 12
scripts: added temp gpg key script #2893
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,25 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| GNUPGHOME="$(mktemp -d)" | ||
| export GNUPGHOME | ||
|
|
||
| cat >"$GNUPGHOME/gpg-batch" <<EOF | ||
| %echo Generating a basic OpenPGP key | ||
| Key-Type: RSA | ||
| Key-Length: 4096 | ||
| Name-Real: Local Test User | ||
| Name-Email: [email protected] | ||
| Expire-Date: 0 | ||
| %no-protection | ||
| %commit | ||
| %echo done | ||
| EOF | ||
|
|
||
| gpg --batch --generate-key "$GNUPGHOME/gpg-batch" >/dev/null 2>&1 | ||
|
|
||
| # SOPS needs this fingerprint to know which key to use | ||
| FINGERPRINT=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2) | ||
|
|
||
| echo "export GNUPGHOME='$GNUPGHOME'" | ||
| echo "export CK8S_PGP_FP='$FINGERPRINT'" |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -296,16 +296,31 @@ config() { | |||||||
| export flavor | ||||||||
| export ops_prefix | ||||||||
|
|
||||||||
| local config_path_was_unset=false | ||||||||
| local pgp_key_was_unset=false | ||||||||
|
|
||||||||
| if [[ -z "${name}" ]] || [[ -z "${flavor}" ]] || [[ -z "${domain}" ]]; then | ||||||||
| log.usage | ||||||||
| fi | ||||||||
|
|
||||||||
| if [[ -z "${CK8S_CONFIG_PATH:-}" ]]; then | ||||||||
| log.fatal "CK8S_CONFIG_PATH is unset" | ||||||||
| config_path_was_unset=true | ||||||||
| export CK8S_CONFIG_PATH="${HOME}/.ck8s/welkin-quick-start" | ||||||||
| mkdir -p "${CK8S_CONFIG_PATH}" | ||||||||
| log.info "CK8S_CONFIG_PATH is unset. Using default: ${CK8S_CONFIG_PATH}" | ||||||||
| fi | ||||||||
|
|
||||||||
| if [[ -z "${CK8S_PGP_FP:-}" ]]; then | ||||||||
| log.fatal "CK8S_PGP_FP is unset" | ||||||||
| pgp_key_was_unset=true | ||||||||
| if [[ -x "${ROOT}/bin/setup-local-gpg" ]]; then | ||||||||
| eval "$("${ROOT}/bin/setup-local-gpg")" | ||||||||
| log.info "CK8S_PGP_FP is unset. Using temp gpgkey: ${CK8S_PGP_FP}" | ||||||||
| log.info "Using temp GNUPGHOME: ${GNUPGHOME}" | ||||||||
|
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.
Suggested change
|
||||||||
| fi | ||||||||
|
|
||||||||
| if [[ -z "${CK8S_PGP_FP:-}" ]]; then | ||||||||
| log.fatal "CK8S_PGP_FP is unset and automatic generation failed." | ||||||||
| fi | ||||||||
| fi | ||||||||
|
|
||||||||
| if ! [[ -d "${CK8S_CONFIG_PATH}" ]]; then | ||||||||
|
|
@@ -353,6 +368,18 @@ config() { | |||||||
| fi | ||||||||
|
|
||||||||
| "${ROOT}/bin/ck8s" init both | ||||||||
|
|
||||||||
| if [[ "${config_path_was_unset}" == "true" ]] || [[ "${pgp_key_was_unset}" == "true" ]]; then | ||||||||
| log.info "Run these commands to configure your current shell session before creating cluster" | ||||||||
| if [[ "${config_path_was_unset}" == "true" ]]; then | ||||||||
| log.info "export CK8S_CONFIG_PATH='${CK8S_CONFIG_PATH}'" | ||||||||
| fi | ||||||||
|
|
||||||||
| if [[ "${pgp_key_was_unset}" == "true" ]]; then | ||||||||
| log.info "export CK8S_PGP_FP='${CK8S_PGP_FP}'" | ||||||||
| log.info "export GNUPGHOME='${GNUPGHOME}'" | ||||||||
| fi | ||||||||
| fi | ||||||||
| } | ||||||||
|
|
||||||||
| create() { | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,22 @@ with_kubeconfig() { | |
| export DETIK_CLIENT_NAME="kubectl" | ||
| } | ||
|
|
||
| # sets up a temporary GPG home and key for local testing | ||
| # usage: with_temporary_gpg | ||
| with_temporary_gpg() { | ||
| if ! command -v setup-local-gpg &>/dev/null; then | ||
| log.fatal "setup-local-gpg script not found in path" | ||
| fi | ||
|
|
||
| eval "$(setup-local-gpg)" | ||
|
|
||
| if [[ -z "${CK8S_PGP_FP:-}" ]]; then | ||
| fail "Failed to generate temporary GPG key" | ||
| fi | ||
|
|
||
| log.trace "Temporary GPG initialized. Fingerprint: $CK8S_PGP_FP" | ||
| } | ||
|
|
||
|
Comment on lines
+165
to
+180
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. Is this needed? We already have a function for it already in |
||
| # sets the kubeconfig to use | ||
| # usage: with_static_wc_kubeconfig <dev|...?> | ||
| with_static_wc_kubeconfig() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.