example_key_setup.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Example Key Setup Script
  3. # Demonstrates how to use the key management tools
  4. set -e
  5. # Colors for output
  6. GREEN='\033[0;32m'
  7. YELLOW='\033[1;33m'
  8. NC='\033[0m' # No Color
  9. echo -e "${GREEN}Emergency Access Key Management Example${NC}"
  10. echo "=========================================="
  11. # Check if we're in the right directory
  12. if [[ ! -f "add_key.py" || ! -f "manage_keys.py" ]]; then
  13. echo "Error: Please run this script from the emergency-access directory"
  14. exit 1
  15. fi
  16. echo
  17. echo -e "${YELLOW}1. Generating passwords for default keys...${NC}"
  18. python3 generate_passwords.py --keys backup master recovery --hide-passwords
  19. echo
  20. echo -e "${YELLOW}2. Adding a backup key interactively...${NC}"
  21. echo " (This would normally be interactive - showing programmatic example instead)"
  22. # Example of adding a key programmatically
  23. python3 add_key.py --key-id example_backup \
  24. --file /tmp/emergency-access-example/backup-key.txt \
  25. --backends matrix_sec,email_emergency \
  26. --message "🚨 EMERGENCY: Backup key accessed from server" \
  27. --create-file \
  28. --key-content "# Example backup key content\nBACKUP_KEY=example_key_content_here\n" \
  29. --config config.json.example || echo "Key already exists or config not found"
  30. echo
  31. echo -e "${YELLOW}3. Listing all configured keys...${NC}"
  32. python3 add_key.py --list --config config.json.example || echo "Using example config"
  33. echo
  34. echo -e "${YELLOW}4. Checking key file status...${NC}"
  35. python3 manage_keys.py --list-files --config config.json.example || echo "Using example config"
  36. echo
  37. echo -e "${YELLOW}5. Generating different types of key content...${NC}"
  38. echo "SSH Key:"
  39. python3 manage_keys.py --generate-content ssh | head -3
  40. echo
  41. echo "API Key:"
  42. python3 manage_keys.py --generate-content api
  43. echo
  44. echo "Password:"
  45. python3 manage_keys.py --generate-content password
  46. echo
  47. echo -e "${YELLOW}6. Example testing (requires running server)...${NC}"
  48. echo "To test key access when server is running:"
  49. echo " python3 manage_keys.py --test-key backup_key --password 'your_password'"
  50. echo " python3 manage_keys.py --test-health --password 'health_password'"
  51. echo
  52. echo -e "${GREEN}Key Management Commands Summary:${NC}"
  53. echo "================================"
  54. echo
  55. echo "Add keys:"
  56. echo " python3 add_key.py --interactive"
  57. echo " python3 add_key.py --key-id NAME --file /path --backends backend1,backend2"
  58. echo
  59. echo "Manage keys:"
  60. echo " python3 manage_keys.py --list-files"
  61. echo " python3 manage_keys.py --validate"
  62. echo " python3 manage_keys.py --rotate-key NAME --key-type ssh"
  63. echo
  64. echo "Generate passwords:"
  65. echo " python3 generate_passwords.py --keys key1 key2"
  66. echo " python3 generate_passwords.py --interactive"
  67. echo
  68. echo "Test access:"
  69. echo " python3 manage_keys.py --test-key NAME --password PASSWORD"
  70. echo " python3 manage_keys.py --test-health --password PASSWORD"
  71. echo
  72. echo -e "${GREEN}Example complete!${NC}"
  73. echo "See README.md for more detailed usage information."