Repository navigation
Add local setup bootstrap script and fix stale credential docs #41
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
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export AWS_ACCESS_KEY_ID=<<YOUR_HETZNER_S3_ACCESS_KEY>> | ||
| export AWS_SECRET_ACCESS_KEY=<<YOUR_HETZNER_S3_SECRET_KEY>> | ||
| export OP_SERVICE_ACCOUNT_TOKEN=<<YOUR_1PASSWORD_SERVICE_ACCOUNT_TOKEN>> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| VAULT="${OP_VAULT:-Fleetyards}" | ||
| S3_ITEM="HETZNER_S3" | ||
| TOKEN_ITEM="Service Account Auth Token: Fleetyards Write" | ||
|
|
||
| cd "$(dirname "$0")/.." | ||
|
|
||
| FORCE=false | ||
|
|
||
| usage() { | ||
| echo "Usage: scripts/setup [--force]" | ||
| echo "" | ||
| echo " Bootstraps a local checkout: checks tooling, writes .env from 1Password," | ||
| echo " and runs terraform init." | ||
| echo "" | ||
| echo " --force - Overwrite an existing .env without asking" | ||
| echo "" | ||
| echo "Environment variables:" | ||
| echo " OP_VAULT - 1Password vault to read from (default: Fleetyards)" | ||
| exit 1 | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| --force) FORCE=true ;; | ||
| "") ;; | ||
| *) usage ;; | ||
| esac | ||
|
|
||
| require() { | ||
| if ! command -v "$1" >/dev/null 2>&1; then | ||
| echo "==> Missing '$1'. Install it with: $2" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| check_tooling() { | ||
| echo "==> Checking tooling..." | ||
| require terraform "brew install terraform" | ||
| require op "brew install 1password-cli" | ||
|
|
||
| # Doubles as the auth check: with desktop integration this is what raises the | ||
| # unlock prompt, and 'op whoami' stays unsigned-in even once that succeeds. | ||
| local error | ||
| if ! error=$(op vault get "$VAULT" 2>&1 >/dev/null); then | ||
| echo "==> Cannot reach the '$VAULT' vault with the 1Password CLI:" | ||
| echo " ${error:-unknown error}" | ||
| echo "" | ||
| echo " Approve the unlock prompt in the 1Password desktop app, or enable" | ||
| echo " Settings -> Developer -> 'Integrate with 1Password CLI' and retry." | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| read_field() { | ||
| local item="$1" field="$2" value | ||
| value=$(op item get "$item" --vault "$VAULT" --fields "$field" --reveal 2>/dev/null) || true | ||
| if [ -z "$value" ]; then | ||
| echo "==> Could not read '$field' from '$item' in vault '$VAULT'." >&2 | ||
| exit 1 | ||
| fi | ||
| printf '%s' "$value" | ||
| } | ||
|
|
||
| write_env() { | ||
| if [ -f .env ] && [ "$FORCE" = false ]; then | ||
| read -r -p "==> .env already exists. Overwrite? [y/N] " reply | ||
| case "$reply" in | ||
| y|Y) ;; | ||
| *) echo "==> Keeping existing .env."; return ;; | ||
| esac | ||
| fi | ||
|
|
||
| echo "==> Writing .env from 1Password vault '$VAULT'..." | ||
| local access_key secret_key token | ||
| access_key=$(read_field "$S3_ITEM" access_key_id) | ||
| secret_key=$(read_field "$S3_ITEM" secret_access_key) | ||
| token=$(read_field "$TOKEN_ITEM" credential) | ||
|
|
||
| cat > .env <<EOF | ||
| export AWS_ACCESS_KEY_ID=$access_key | ||
| export AWS_SECRET_ACCESS_KEY=$secret_key | ||
| export OP_SERVICE_ACCOUNT_TOKEN=$token | ||
| EOF | ||
| chmod 600 .env | ||
|
Comment on lines
+81
to
+86
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. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Set the If the process umask permits group or other reads, 🤖 Prompt for AI AgentsSource: Learnings |
||
| } | ||
|
|
||
| init_terraform() { | ||
| echo "==> Running terraform init..." | ||
| set -a | ||
| # shellcheck disable=SC1091 | ||
| . ./.env | ||
| set +a | ||
| terraform init -input=false | ||
| } | ||
|
|
||
| check_tooling | ||
| write_env | ||
| init_terraform | ||
|
|
||
| echo "" | ||
| echo "==> Done. Load the credentials into your shell and pick a workspace:" | ||
| echo " source .env" | ||
| echo " terraform workspace select stage # or live" | ||
| echo " terraform plan" | ||
This file was deleted.
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.
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift
Encode credential values before writing shell assignments.
If a 1Password field contains shell syntax, Line 93 interprets that syntax when it sources
.env. For example, a value containing$(command)executescommandinstead of remaining a literal credential. Write shell-escaped assignments, or use a format that does not execute credential text when loaded.🤖 Prompt for AI Agents