-
Notifications
You must be signed in to change notification settings - Fork 465
Feature/ddb backend #77
Changes from 5 commits
d6f5711
6544406
a8e6b72
6cd9bfa
fdc8fac
6d308d2
966df0a
36a74d7
0761984
36e1b94
8d539cd
14c4e94
6a55724
93fb7b6
f3020a8
2df7148
ffabbb8
10b5cb1
011d71a
0b74d0a
7449675
45f7658
c5f0603
481c675
773d47a
c8d9fab
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 |
---|---|---|
|
@@ -63,22 +63,30 @@ The `run-vault` script accepts the following arguments: | |
* `user` (optional): The user to run Vault as. Default is to use the owner of `config-dir`. | ||
* `skip-vault-config` (optional): If this flag is set, don't generate a Vault configuration file. This is useful if you | ||
have a custom configuration file and don't want to use any of of the default settings from `run-vault`. | ||
* `--enable-s3-backend` (optional): If this flag is set, an S3 backend will be enabled in addition to the HA Consul backend. | ||
* `--enable-s3-backend` (optional): Cannot be set with `--enable-dynamo`. If this flag is set, an S3 backend will be enabled in addition to the HA Consul backend. | ||
* `--s3-bucket` (optional): Specifies the S3 bucket to use to store Vault data. Only used if `--enable-s3-backend` is set. | ||
* `--s3-bucket-region` (optional): Specifies the AWS region where `--s3-bucket` lives. Only used if `--enable-s3-backend` is set. | ||
* `--enable-dynamo` (optional): Cannot be set with `--enable-s3-backend`. If this flag is set, a DynamoDB backend will be enabled. Consul will __NOT__ be enabled as a backend. | ||
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. Probably 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. find-replace in readme, userdata in example, and run-vault script. |
||
* `--dynamo-table` (optional): Specifies the DynamoDB table to use to store Vault data. Only used if `--enable-dynamo` is set. | ||
* `--dynamo-region` (optional): Specifies the AWS region where `--dynamo-table` lives. Only used if `--enable-dynamo` is set. | ||
|
||
Example: | ||
|
||
``` | ||
/opt/vault/bin/run-vault --tls-cert-file /opt/vault/tls/vault.crt.pem --tls-key-file /opt/vault/tls/vault.key.pem | ||
``` | ||
|
||
Or if you want to enable an S3 backend: | ||
If you want to enable an S3 backend: | ||
|
||
``` | ||
/opt/vault/bin/run-vault --tls-cert-file /opt/vault/tls/vault.crt.pem --tls-key-file /opt/vault/tls/vault.key.pem --enable-s3-backend --s3-bucket my-vault-bucket --s3-bucket-region us-east-1 | ||
``` | ||
|
||
OR if you want to enable DynamoDB backend: | ||
|
||
``` | ||
/opt/vault/bin/run-vault --tls-cert-file /opt/vault/tls/vault.crt.pem --tls-key-file /opt/vault/tls/vault.key.pem --enable-dynamo --dynamo-table my-dynamo-table --dynamo-region us-east-1 | ||
``` | ||
|
||
|
||
## Vault configuration | ||
|
@@ -134,6 +142,14 @@ available. | |
* [region](https://www.vaultproject.io/docs/configuration/storage/s3.html#region): Set to the `--s3-bucket-region` | ||
parameter. | ||
|
||
* [storage](https://www.vaultproject.io/docs/configuration/index.html#storage): Set the `--enable-dynamo` flag to | ||
configure DynamoDB as the main (HA) storage backend for Vault: | ||
|
||
* [table](https://www.vaultproject.io/docs/configuration/storage/dynamodb.html#table): Set to the `--dynamo-table` | ||
parameter. | ||
* [region](https://www.vaultproject.io/docs/configuration/storage/dynamodb.html#region): Set to the `--dynamo-region` | ||
parameter. | ||
|
||
### Overriding the configuration | ||
|
||
To override the default configuration, simply put your own configuration file in the Vault config folder (default: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,10 @@ function print_usage { | |
echo -e " --skip-vault-config\tIf this flag is set, don't generate a Vault configuration file. Optional. Default is false." | ||
echo -e " --enable-s3-backend\tIf this flag is set, an S3 backend will be enabled in addition to the HA Consul backend. Default is false." | ||
echo -e " --s3-bucket\tSpecifies the S3 bucket to use to store Vault data. Only used if '--enable-s3-backend' is set." | ||
echo -e " --s3-bucket-region\tSpecifies the AWS region where `--s3-bucket` lives. Only used if `--enable-s3-backend` is set." | ||
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. backticks were previously used causing this function to behave unexpectedly. Replaced with single quotes per all other items in the list. 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. Whoops! Good fix, thanks! |
||
echo -e " --s3-bucket-region\tSpecifies the AWS region where '--s3-bucket' lives. Only used if '--enable-s3-backend' is set." | ||
echo -e " --enable-dynamo\tIf this flag is set, DynamoDB will be enabled as the backend storage (HA)" | ||
echo -e " --dynamo-region\tSpecifies the AWS region where --dynamo-table lives. Only used if '--enable-dynamo is on'" | ||
echo -e " --dynamo--table\tSpecifies the DynamoDB table to use for HA Storage. Only used if '--enable-dynamo is on'" | ||
echo | ||
echo "Examples:" | ||
echo | ||
|
@@ -112,16 +115,34 @@ function generate_vault_config { | |
local readonly api_addr="$5" | ||
local readonly config_dir="$6" | ||
local readonly user="$7" | ||
local readonly enable_s3_backend="$8" | ||
local readonly s3_bucket="$9" | ||
local readonly s3_bucket_region="${10}" | ||
|
||
if [[ "$enable_s3_backend" == "true" ]]; then | ||
local readonly enable_s3_backend="$8" | ||
local readonly s3_bucket="$9" | ||
local readonly s3_bucket_region="${10}" | ||
local readonly enable_dynamo="" | ||
local readonly dynamo_region="" | ||
local readonly dynamo_table="" | ||
fi | ||
|
||
if [[ "$enable_dynamo" == "true" ]]; then | ||
local readonly enable_dynamo="$8" | ||
local readonly dynamo_region="$9" | ||
local readonly dynamo_table="${10}" | ||
local readonly enable_s3_backend="" | ||
local readonly s3_bucket="" | ||
local readonly s3_bucket_region="" | ||
fi | ||
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. I find changing the list of input params a bit confusing. I'd recommend making this a single list: local readonly enable_s3_backend="$8"
local readonly s3_bucket="$9"
local readonly s3_bucket_region="${10}"
local readonly enable_dynamo="${11}"
local readonly dynamo_region="${12}"
local readonly dynamo_table="${13}" The 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. I agree, however, by default the vault config generation just adds the S3 params at the end (no harm if they are empty). I can add extra vault config generation logic (at the bottom) if you'd rather see this as a list. 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. Changed it back to a list and updated logic at the bottom (vault generation script) to match |
||
|
||
local readonly config_path="$config_dir/$VAULT_CONFIG_FILE" | ||
|
||
local instance_ip_address | ||
instance_ip_address=$(get_instance_ip_address) | ||
|
||
log_info "Creating default Vault config file in $config_path" | ||
local readonly listener_config=$(cat <<EOF | ||
ui = true | ||
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. Enabled vault UI by default 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. Thx! We should probably make this configurable though with a |
||
|
||
listener "tcp" { | ||
address = "0.0.0.0:$port" | ||
cluster_address = "0.0.0.0:$cluster_port" | ||
|
@@ -133,6 +154,7 @@ EOF | |
|
||
local consul_storage_type="storage" | ||
local s3_config="" | ||
|
||
if [[ "$enable_s3_backend" == "true" ]]; then | ||
s3_config=$(cat <<EOF | ||
storage "s3" { | ||
|
@@ -144,7 +166,24 @@ EOF | |
consul_storage_type="ha_storage" | ||
fi | ||
|
||
local readonly consul_storage=$(cat <<EOF | ||
|
||
if [[ "$enable_dynamo" == "true" ]]; then | ||
consul_storage="" | ||
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. Please declare 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. Good call. Adjusting. |
||
vault_storage=$(cat <<EOF | ||
storage "dynamodb" { | ||
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. In order to have both dynamodb and s3 backend we would need to be able to make that block similar to how its handled for consul. Currently what I have adjusted on my end, and is working so far with manual testing: local consul_storage_type="storage"
local dynamodb_storage_type="storage"
local s3_config=""
local consul_storage=""
local vault_storage=""
if [[ "$enable_s3_backend" == "true" ]]; then
s3_config=$(cat <<EOF
storage "s3" {
bucket = "$s3_bucket"
region = "$s3_bucket_region"
}\n
EOF
)
consul_storage_type="ha_storage"
dynamodb_storage_type="ha_storage"
fi
if [[ "$enable_dynamo_backend" == "true" ]]; then
vault_storage=$(cat <<EOF
$dynamodb_storage_type "dynamodb" {
ha_enabled = "true"
region = "$dynamo_region"
table = "$dynamo_table"
}
# HA settings
cluster_addr = "https://$instance_ip_address:$cluster_port"
api_addr = "$api_addr"
EOF
) |
||
ha_enabled = "true" | ||
region = "$dynamo_region" | ||
table = "$dynamo_table" | ||
} | ||
|
||
# HA settings | ||
cluster_addr = "https://$instance_ip_address:$cluster_port" | ||
api_addr = "$api_addr" | ||
|
||
EOF | ||
) | ||
else | ||
local readonly consul_storage=$(cat <<EOF | ||
$consul_storage_type "consul" { | ||
address = "127.0.0.1:8500" | ||
path = "vault/" | ||
|
@@ -159,9 +198,12 @@ api_addr = "$api_addr" | |
EOF | ||
) | ||
|
||
fi | ||
|
||
echo -e "$listener_config" >> "$config_path" | ||
echo -e "$s3_config" >> "$config_path" | ||
echo -e "$consul_storage" >> "$config_path" | ||
echo -e "$vault_storage" >> "$config_path" | ||
|
||
chown "$user:$user" "$config_path" | ||
} | ||
|
@@ -215,6 +257,9 @@ function run { | |
local enable_s3_backend="false" | ||
local s3_bucket="" | ||
local s3_bucket_region="" | ||
local enable_dynamo="false" | ||
local dynamo_region="" | ||
local dynamo_table="" | ||
local all_args=() | ||
|
||
while [[ $# > 0 ]]; do | ||
|
@@ -283,6 +328,17 @@ function run { | |
s3_bucket_region="$2" | ||
shift | ||
;; | ||
--enable-dynamo) | ||
enable_dynamo="true" | ||
;; | ||
--dynamo-region) | ||
dynamo_region="$2" | ||
shift | ||
;; | ||
--dynamo-table) | ||
dynamo_table="$2" | ||
shift | ||
;; | ||
--help) | ||
print_usage | ||
exit | ||
|
@@ -305,6 +361,11 @@ function run { | |
assert_not_empty "--s3-bucket-region" "$s3_bucket_region" | ||
fi | ||
|
||
if [[ "$enable_dynamo" == "true" ]]; then | ||
assert_not_empty "--dynamo-table" "$dynamo_table" | ||
assert_not_empty "--dynamo-region" "$dynamo_region" | ||
fi | ||
|
||
assert_is_installed "supervisorctl" | ||
assert_is_installed "aws" | ||
assert_is_installed "curl" | ||
|
@@ -336,6 +397,8 @@ function run { | |
|
||
if [[ "$skip_vault_config" == "true" ]]; then | ||
log_info "The --skip-vault-config flag is set, so will not generate a default Vault config file." | ||
elif [[ "$enable_dynamo" == "true" ]]; then | ||
generate_vault_config "$tls_cert_file" "$tls_key_file" "$port" "$cluster_port" "$api_addr" "$config_dir" "$user" "$enable_dynamo" "$dynamo_region" "$dynamo_table" | ||
else | ||
generate_vault_config "$tls_cert_file" "$tls_key_file" "$port" "$cluster_port" "$api_addr" "$config_dir" "$user" "$enable_s3_backend" "$s3_bucket" "$s3_bucket_region" | ||
fi | ||
|
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.
Couldn't
supervisor
be installed via tools other thanpip
? And won't this return false positives for anything that has the word "supervisor" in the name?Seems like a better check might be for the presence of
supervisorctl
in thePATH
.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.
Also, to avoid wrapping this whole method in an
if
, consider inverting the check and doing an early return right at the top.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.
Removed this check entirely. This was something I did on my local instance because it simply timed out with pip (no internet connectivity). So I had installed the package manually and just ran a check to bypass.
Reverted to the the prior code.