2022-03-23 16:45:39 +00:00
|
|
|
#!/bin/bash
|
2023-03-15 16:00:52 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Generate an OpenAPI document for all backends.
|
|
|
|
#
|
|
|
|
# Assumptions:
|
|
|
|
#
|
|
|
|
# 1. Vault has been checked out at an appropriate version and built
|
|
|
|
# 2. vault executable is in your path
|
2018-11-30 00:08:44 +00:00
|
|
|
# 3. Vault isn't already running
|
2022-03-23 16:45:39 +00:00
|
|
|
# 4. jq is installed
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
2018-11-05 20:24:39 +00:00
|
|
|
|
|
|
|
echo "Starting Vault..."
|
|
|
|
if pgrep -x "vault" > /dev/null
|
|
|
|
then
|
|
|
|
echo "Vault is already running. Aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
vault server -dev -dev-root-token-id=root &
|
|
|
|
VAULT_PID=$!
|
|
|
|
|
2023-07-05 19:59:26 +00:00
|
|
|
# Allow time for Vault to start its HTTP listener
|
|
|
|
sleep 1
|
|
|
|
|
2023-02-17 18:06:00 +00:00
|
|
|
defer_stop_vault() {
|
|
|
|
echo "Stopping Vault..."
|
|
|
|
kill $VAULT_PID
|
2023-07-05 19:59:26 +00:00
|
|
|
# Allow time for Vault to print final logging and exit,
|
|
|
|
# before this script ends, and the shell prints its next prompt
|
2023-02-17 18:06:00 +00:00
|
|
|
sleep 1
|
|
|
|
}
|
|
|
|
|
|
|
|
trap defer_stop_vault INT TERM EXIT
|
|
|
|
|
2022-11-01 21:32:54 +00:00
|
|
|
export VAULT_ADDR=http://127.0.0.1:8200
|
2018-11-05 20:24:39 +00:00
|
|
|
|
2023-07-05 19:29:29 +00:00
|
|
|
echo "Unmounting the default kv-v2 secrets engine ..."
|
|
|
|
|
|
|
|
# Unmount the default kv-v2 engine so that we can remount it at 'kv_v2/' later.
|
|
|
|
# The mount path will be reflected in the resultant OpenAPI document.
|
|
|
|
vault secrets disable "secret/"
|
|
|
|
|
|
|
|
echo "Mounting all builtin plugins ..."
|
2022-11-01 21:32:54 +00:00
|
|
|
|
|
|
|
# Enable auth plugins
|
2023-02-17 19:48:05 +00:00
|
|
|
vault auth enable "alicloud"
|
|
|
|
vault auth enable "approle"
|
|
|
|
vault auth enable "aws"
|
|
|
|
vault auth enable "azure"
|
|
|
|
vault auth enable "centrify"
|
|
|
|
vault auth enable "cert"
|
|
|
|
vault auth enable "cf"
|
|
|
|
vault auth enable "gcp"
|
|
|
|
vault auth enable "github"
|
|
|
|
vault auth enable "jwt"
|
|
|
|
vault auth enable "kerberos"
|
|
|
|
vault auth enable "kubernetes"
|
|
|
|
vault auth enable "ldap"
|
|
|
|
vault auth enable "oci"
|
|
|
|
vault auth enable "okta"
|
|
|
|
vault auth enable "radius"
|
|
|
|
vault auth enable "userpass"
|
2022-11-01 21:32:54 +00:00
|
|
|
|
|
|
|
# Enable secrets plugins
|
2023-02-17 19:48:05 +00:00
|
|
|
vault secrets enable "alicloud"
|
|
|
|
vault secrets enable "aws"
|
|
|
|
vault secrets enable "azure"
|
|
|
|
vault secrets enable "consul"
|
|
|
|
vault secrets enable "database"
|
|
|
|
vault secrets enable "gcp"
|
|
|
|
vault secrets enable "gcpkms"
|
|
|
|
vault secrets enable "kubernetes"
|
2023-07-05 19:29:29 +00:00
|
|
|
vault secrets enable -path="kv-v1/" -version=1 "kv"
|
|
|
|
vault secrets enable -path="kv-v2/" -version=2 "kv"
|
2023-02-17 19:48:05 +00:00
|
|
|
vault secrets enable "ldap"
|
|
|
|
vault secrets enable "mongodbatlas"
|
|
|
|
vault secrets enable "nomad"
|
|
|
|
vault secrets enable "pki"
|
|
|
|
vault secrets enable "rabbitmq"
|
|
|
|
vault secrets enable "ssh"
|
|
|
|
vault secrets enable "terraform"
|
|
|
|
vault secrets enable "totp"
|
|
|
|
vault secrets enable "transit"
|
2018-11-05 20:24:39 +00:00
|
|
|
|
2020-04-15 16:12:12 +00:00
|
|
|
# Enable enterprise features
|
2023-02-17 19:48:05 +00:00
|
|
|
if [[ -n "${VAULT_LICENSE:-}" ]]; then
|
|
|
|
vault secrets enable "keymgmt"
|
|
|
|
vault secrets enable "kmip"
|
|
|
|
vault secrets enable "transform"
|
2019-07-25 00:03:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Output OpenAPI, optionally formatted
|
2019-05-03 22:12:24 +00:00
|
|
|
if [ "$1" == "-p" ]; then
|
2023-01-31 23:37:19 +00:00
|
|
|
curl --header 'X-Vault-Token: root' \
|
|
|
|
--data '{"generic_mount_paths": true}' \
|
|
|
|
'http://127.0.0.1:8200/v1/sys/internal/specs/openapi' | jq > openapi.json
|
2019-05-03 22:12:24 +00:00
|
|
|
else
|
2023-01-31 23:37:19 +00:00
|
|
|
curl --header 'X-Vault-Token: root' \
|
|
|
|
--data '{"generic_mount_paths": true}' \
|
|
|
|
'http://127.0.0.1:8200/v1/sys/internal/specs/openapi' > openapi.json
|
2019-05-03 22:12:24 +00:00
|
|
|
fi
|
2018-11-05 20:24:39 +00:00
|
|
|
|
2022-03-23 21:43:02 +00:00
|
|
|
echo
|
|
|
|
echo "openapi.json generated"
|
2023-02-17 18:06:00 +00:00
|
|
|
echo
|