diff --git a/test_docker.sh b/test_docker.sh index b608760..1435df7 100755 --- a/test_docker.sh +++ b/test_docker.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eo pipefail # Colors for terminal output @@ -48,6 +48,12 @@ if ! command -v docker-compose > /dev/null 2>&1; then exit 1 fi +# Check if jq is available +if ! command -v jq > /dev/null 2>&1; then + log "ERROR" "jq command not found. Please install jq (JSON processor)." + exit 1 +fi + # Build the Docker image log "INFO" "Building Docker image..." docker-compose build @@ -171,27 +177,27 @@ root_token=$(jq -r '.root_token' vault-credentials.json) # First, try running 'vault operator unseal' directly for a more robust test log "INFO" "Attempting to unseal Vault directly with unseal keys..." -# Using an array to capture the keys -readarray -t key_array <<< "$unseal_keys" +# Split the keys - more portable than readarray which isn't available in all shells +key1=$(echo "$unseal_keys" | head -n 1) +key2=$(echo "$unseal_keys" | head -n 2 | tail -n 1) +key3=$(echo "$unseal_keys" | head -n 3 | tail -n 1) -for key in "${key_array[@]}"; do - log "INFO" "Applying unseal key: ${key:0:8}..." # Show only first 8 chars for security - docker-compose exec -T vault env VAULT_ADDR=http://127.0.0.1:8200 vault operator unseal "$key" +# Apply each key +for key in "$key1" "$key2" "$key3"; do + if [ -n "$key" ]; then + log "INFO" "Applying unseal key: ${key:0:8}..." # Show only first 8 chars for security + docker-compose exec -T vault env VAULT_ADDR=http://127.0.0.1:8200 vault operator unseal "$key" + fi done # As a fallback, also try running vault-init with environment variables log "INFO" "Starting vault-init with environment variables..." -# Check how many keys we have -key_count=${#key_array[@]} -env_vars="-e VAULT_ADDR=http://vault:8200" - -# Add each key to environment variables -for i in $(seq 0 $((key_count-1))); do - env_vars="$env_vars -e VAULT_UNSEAL_KEY_$((i+1))=${key_array[$i]}" -done - -# Run the command with all environment variables -docker-compose run $env_vars --rm vault-init +# Use simpler variable passing - more portable +docker-compose run -e VAULT_ADDR=http://vault:8200 \ + -e VAULT_UNSEAL_KEY_1="$key1" \ + -e VAULT_UNSEAL_KEY_2="$key2" \ + -e VAULT_UNSEAL_KEY_3="$key3" \ + --rm vault-init # Verify Vault is unsealed now vault_status=$(docker-compose exec -T vault env VAULT_ADDR=http://127.0.0.1:8200 vault status -format=json 2>/dev/null || echo '{"sealed": true}') diff --git a/test_local.sh b/test_local.sh index 903eb64..67f85e2 100755 --- a/test_local.sh +++ b/test_local.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e # Detect OS and handle accordingly