Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit 7ca1149

Browse files
committed
run-vault: support raft as HA storage
1 parent b21edc4 commit 7ca1149

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

modules/install-vault/install-vault

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ function create_vault_install_paths {
156156
sudo mkdir -p "$path/data"
157157
sudo mkdir -p "$path/tls"
158158
sudo mkdir -p "$path/scripts"
159+
sudo mkdir -p "$path/raft"
159160
sudo chmod 755 "$path"
160161
sudo chmod 755 "$path/bin"
161162
sudo chmod 755 "$path/data"

modules/run-vault/run-vault

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function print_usage {
4747
echo -e " --enable-dynamo-backend\tIf this flag is set, DynamoDB will be enabled as the backend storage (HA)"
4848
echo -e " --dynamo-region\tSpecifies the AWS region where --dynamo-table lives. Only used if '--enable-dynamo-backend is on'"
4949
echo -e " --dynamo--table\tSpecifies the DynamoDB table to use for HA Storage. Only used if '--enable-dynamo-backend is on'"
50+
echo -e " --enable-raft-backend\tIf this flag is set, Vault's Integrated Storage will be enabled as the backend storage (HA)"
51+
echo -e " --raft-dir\t\tSpecifies the path to store Vault's Integrated Storage data. Optional. Default is the absolute path of '../raft', relative to this script."
5052
echo
5153
echo "Options for Vault Agent:"
5254
echo
@@ -244,6 +246,8 @@ function generate_vault_config {
244246
local -r auto_unseal_kms_key_id="${16}"
245247
local -r auto_unseal_kms_key_region="${17}"
246248
local -r auto_unseal_endpoint="${18}"
249+
local -r enable_raft_backend="${19}"
250+
local -r raft_dir="${20}"
247251
local -r config_path="$config_dir/$VAULT_CONFIG_FILE"
248252

249253
local instance_ip_address
@@ -301,8 +305,19 @@ EOF
301305
dynamodb_storage_type="ha_storage"
302306
fi
303307

308+
if [[ "$enable_raft_backend" == "true" ]]; then
309+
vault_storage_backend=$(cat <<EOF
310+
ha_storage "raft" {
311+
path = "$raft_dir"
312+
node_id = "$instance_ip_address"
313+
}
314+
# HA settings
315+
cluster_addr = "https://$instance_ip_address:$cluster_port"
316+
api_addr = "$api_addr"
317+
EOF
318+
)
304319

305-
if [[ "$enable_dynamo_backend" == "true" ]]; then
320+
elif [[ "$enable_dynamo_backend" == "true" ]]; then
306321
vault_storage_backend=$(cat <<EOF
307322
$dynamodb_storage_type "dynamodb" {
308323
ha_enabled = "true"
@@ -438,6 +453,7 @@ function run {
438453
local cluster_port=""
439454
local api_addr=""
440455
local config_dir=""
456+
local raft_dir=""
441457
local bin_dir=""
442458
local data_dir=""
443459
local log_level="$DEFAULT_LOG_LEVEL"
@@ -452,6 +468,7 @@ function run {
452468
local enable_dynamo_backend="false"
453469
local dynamo_region=""
454470
local dynamo_table=""
471+
local enable_raft_backend="false"
455472
local agent="false"
456473
local agent_vault_address="$DEFAULT_AGENT_VAULT_ADDRESS"
457474
local agent_vault_port="$DEFAULT_PORT"
@@ -558,6 +575,14 @@ function run {
558575
dynamo_table="$2"
559576
shift
560577
;;
578+
--enable-raft-backend)
579+
enable_raft_backend="true"
580+
;;
581+
--raft-dir)
582+
assert_not_empty "$key" "$2"
583+
raft_dir="$2"
584+
shift
585+
;;
561586
--agent)
562587
agent="true"
563588
;;
@@ -641,7 +666,7 @@ function run {
641666
assert_not_empty "--s3-bucket-region" "$s3_bucket_region"
642667
fi
643668
fi
644-
669+
645670
if [[ "$enable_dynamo_backend" == "true" ]]; then
646671
assert_not_empty "--dynamo-table" "$dynamo_table"
647672
assert_not_empty "--dynamo-region" "$dynamo_region"
@@ -666,6 +691,10 @@ function run {
666691
data_dir=$(cd "$SCRIPT_DIR/../data" && pwd)
667692
fi
668693

694+
if [[ -z "$raft_dir" ]]; then
695+
raft_dir=$(cd "$SCRIPT_DIR/../raft" && pwd)
696+
fi
697+
669698
if [[ -z "$user" ]]; then
670699
user=$(get_owner_of_path "$config_dir")
671700
fi
@@ -720,7 +749,9 @@ function run {
720749
"$enable_auto_unseal" \
721750
"$auto_unseal_kms_key_id" \
722751
"$auto_unseal_kms_key_region" \
723-
"$auto_unseal_endpoint"
752+
"$auto_unseal_endpoint" \
753+
"$enable_raft_backend" \
754+
"$raft_dir"
724755
fi
725756
fi
726757

0 commit comments

Comments
 (0)