Consul 和 Vault 的灾难恢复和配置管理
hashi-helper is a tool meant to enable Disaster Recovery and Configuration Management for Consul and Vault clusters, by exposing configuration via a simple to use and share hcl format.
To build a binary, run the following
# get this repo
go get github.com/seatgeek/hashi-helper
# go to the repo directory
cd $GOPATH/src/github.com/seatgeek/hashi-helper
# build the `hashi-helper` binary
make buildThis will create a hashi-helper binary in your $GOPATH/bin directory.
The following environment variables are required for setting configuration and keys in Consul and Vault.
VAULT_TOKEN environment variable (preferable a root/admin token)VAULT_ADDR environment variable (example: http://127.0.0.1:8200)CONSUL_ADDR_HTTP environment variable (example: http://127.0.0.1:8500)hashi-helper [--global-flags] command [--command-flags]--lintProviding this flag will make hashi-helper only process configuration, and not push any changes to Consul or Vault
This is useful for CI pipelines
--variableA number of key=value pairs to expose as template variables during template rendering.
The flag can be repeated any number of times. The order they are provided in is also the order they are read.
--var key1=value1 --var key2=value2
--var key1=value1 --var key2=value2 --var key1=value2 - key1 will be having the value value2
Aliases: --var key=value
--variable-fileA number of files to parse and expose as template variables template rendering.
The flag can be repeated any number of times. The order they are provided in is also the order they are read.
--variable-file example/conf.hcl --variable-file example/conf.json --variable-file example/conf.yaml
Aliases: --var-file value | --varf value
--concurrencyHow many parallel requests to run in parallel against remote servers
Default: 2 * CPU Cores
Environment Key: CONCURRENCY
--log-levelDebug level of debug, info, warn/warning, error, fatal, panic
Default: info
Environment Key: LOG_LEVEL
--config-dirOne or more directories to recursively scan for hcl configuration files.
The flag can be repeated any number of times. The order they are provided in is also the order they are read.
--config-dir conf.d/
--config-dir conf.d/ --config-dir shared/
Environment Key: CONFIG_DIR
--config-fileOne or more hcl configuration file to parse instead of a directory
The flag can be repeated any number of times. The order they are provided in is also the order they are read.
--config-file conf.d/config.hcl
--config-file conf.d/config.hcl --config-file conf.d/another_config.hcl
Environment key: CONFIG_FILE
--environmentThe environment to process configuration for
Default: all
Environment Key: ENVIRONMENT
--applicationThe application to process for
Default: all
Environment Key: APPLICATION
push-allPush all Consul and Vault data to remote servers (same as running vault-push-all and consul-push-all)
profile-editDecrypt (or create), open and encrypt the secure HASHI_HELPER_PROFILE_FILE (~/.vault_profiles.pgp) file containing your vault clusters
File format is as described below, a simple yaml file
…profile-useDecrypt the HASHI_HELPER_PROFILE_FILE and output bash/zsh compatible commands to set VAULT_ADDR, VAULT_TOKEN, ENVIRONMENT based on the profile you selected.
Example: $(hashi-helper profile-use name_1)
consul-push-allPush all local consul state to remote consul cluster.
consul-push-servicesPush all service{} stanza to remote Consul cluster
consul-push-kvPush all kv{} stanza to remote Consul cluster
vault-create-tokenCreate a Vault token, optionally encrypt it using keybase
--keybase optional - can be repeated for multiple recipients, token will be encrypted for all recipients to decrypt. If omitted, token is shown in cleartext in the shell--id optional - The ID of the client token. Can only be specified by a root token. Otherwise, the token ID is a randomly generated UUID.--display-name optional The display name of the token. Defaults to "token".--ttl optional - The TTL period of the token, provided as "1h", where hour is the largest suffix. If not provided, the token is valid for the default lease TTL, or indefinitely if the root policy is used.--period optional - If specified, the token will be periodic; it will have no maximum TTL (unless an "explicit-max-ttl" is also set) but every renewal will use the given period. Requires a root/sudo token to use.--orphan Will create the token as orphan--policy optional - Can be repeated for each policy needed. A list of policies for the token. This must be a subset of the policies belonging to the token making the request, unless root. If not specified, defaults to all the policies of the calling token.vault-find-tokenScan all tokens in the Vault server, optionally tokens matching certain conditions
Filter flags:
--filter-name jose will only match tokens where display name contains jose
--filter-policy root will only match tokens that have the policy root
--filter-path auth/github/login will only match tokens that have the path auth/github/login
--filter-meta-username jippi will only match tokens that have the meta[username] value jippi (GitHub auth backend injects this, as an example)
--filter-orphan will only match tokens that are orphaned
Action flags:
--delete-matches will match all tokens matching the filter flags. You will be asked to verify each token before deleting it.
vault-list-secretsPrint a list of local from conf.d/ (default) or remote secrets from Vault (--remote).
Add --detailed / DETAILED to show secret data rather than just the key names.
vault-pull-secretsNOT IMPLEMENTED YET
Write remote Vault secrets to local disk in conf.d/
vault-push-allPushes all mounts, policies and secrets to a remote vault server
vault-push-authWrite Vault auth {} stanza found in conf.d/ to remote vault server
vault-push-mountsMount and configure mount {} stanza found in conf.d/ to remote vault server
vault-push-policiesWrite Vault policy {} stanza found in conf.d/ to remote vault server
vault-push-secretsWrite local secrets to remote Vault instance
vault-unseal-keybaseUnseal Vault using the raw unseal key from keybase / gpg init/rekey .
The command expect the raw base64encoded unseal key as env VAULT_UNSEAL_KEY or --unseal-key CLI argument
It basically automates echo "$VAULT_UNSEAL_KEY" | base64 -D | keybase pgp decrypt | xargs vault unseal -address http://:8200
--unseal-key/ VAULT_UNSEAL_KEY (default: ``) The raw base64encoded unseal key as env or CLI argument--consul-service-name / CONSUL_SERVICE_NAME (default: ``) If specified, the tool will try to lookup all vault servers in the configured Consul catalog and unseal all of them. This is the service name, e.g. vault--consul-service-tag / CONSUL_SERVICE_TAG (default: standby) The Consul catalog tag to filter vault instances from if CONSUL_SERVICE_NAME is used.--vault-protocol / VAULT_PROTOCOL (default: http) The protocol to use when constructing the VAULT_ADDR value when using CONSUL_SERVICE_NAME unseal strategy.All VAULT_* env keys are preserved when using CONSUL_SERVICE_TAG, address is the only field being overwritten per vault instance found in the catalog. So you can still configure TLS and other Vault changes as usual with the environment.
VAULT_UNSEAL_KEY=$token hashi-helper vault-unseal-keybasehashi-helper vault-unseal-keybase --unseal-key=$keyVAULT_CONSUL_SERVICE=vault VAULT_UNSEAL_KEY=$token hashi-helper vault-unseal-keybasehashi-helper vault-unseal-keybase --unseal-key=$key --consul-service-name vaulthashi-helper version >= 2.0 support templating for configuration files.
All configuration files loaded are automatically rendered as a template using go text/template.
This is identical to how hashicorp/consul-template renders content.
Templates use [[ ]] brackes instead of the default {{ }} style to avoid clashes with HCL { } stanza definitions.
You can provide variables for templating through the CLI in various ways. All of these options can be provided any number of times
--variable-file or --var-file
--variable key=value or --var key=value
The tool can load files with extensions .hcl, .yaml/.yml and .json. Variables are loaded in the order they are provided in CLI, so it's possible to cascade / overwrite configuration files by using a specific loading order. --variable-file are loaded before CLI --variable key=value arguments.
consul_domain = "consul"
environment_name = "staging"
environment_tld = "stag"
db_default_ttl = "9h"
db_max_ttl = "72h"
my_key = "hello world"
# a list of things
stuff = ["a", "b", "c"]
here_doc = <<-DOC
something multiline
that will be available
as a single string
D暂无开放 Issues,或尚未同步最近议题。