Skip to content

Latest commit

 

History

History
205 lines (143 loc) · 6.49 KB

File metadata and controls

205 lines (143 loc) · 6.49 KB

Vault Plugin Database Redis ElastiCache

This is a standalone Database Plugin for use with Hashicorp Vault.

This plugin supports exclusively AWS ElastiCache for Redis. Redis Enterprise and Redis Open Source use different plugins.

Please note: We take Vault's security and our users' trust very seriously. If you believe you have found a security issue in Vault, please responsibly disclose by contacting us at security@hashicorp.com.

Quick Links

Getting Started

This is a Vault plugin and is meant to work with Vault. This guide assumes you have already installed Vault and have a basic understanding of how Vault works.

Otherwise, first read this guide on how to get started with Vault.

Development

If you wish to work on this plugin, you'll first need Go installed on your machine (version 1.17+ recommended)

Make sure Go is properly installed, including setting up a GOPATH.

To run the tests locally you will need to have write permissions to an ElastiCache for Redis instance. A small Terraform project is included to provision one for you if needed. More details in the Environment Set Up section.

Building

If you're developing for the first time, run make bootstrap to install the necessary tools. Bootstrap will also update repository name references if that has not been performed ever before.

$ make bootstrap

To compile a development version of this plugin, run make or make dev. This will put the plugin binary in the bin and $GOPATH/bin folders. dev mode will only generate the binary for your platform and is faster:

$ make dev

Tests

Environment Set Up

To test the plugin, you need access to an Elasticache for Redis Cluster. A Terraform project is included for convenience to initialize a new cluster if needed. If not already available, you can install Terraform by using this documentation.

The setup script tries to find and use available AWS credentials from the environment. You can configure AWS credentials using this documentation. Or if you prefer you can edit the provider defined ./bootstrap/terraform/elasticache.tf with your desired set of credentials.

Note that resources created via the Terraform project cost a small amount of money per hour.

To set up the test cluster:

$ make set-up-env
...
Apply complete! Resources: 4 added, 0 changed, 0 destroyed.

Environment Teardown

The test cluster created via the set-up-env command can be destroyed using the teardown-env command.

$ make teardown-env
...
Destroy complete! Resources: 4 destroyed.

Testing Manually

Put the plugin binary into a location of your choice. This directory will be specified as the plugin_directory in the Vault config used to start the server.

# config.hcl
plugin_directory = "path/to/plugin/directory"
...

Start a Vault server with this config file:

$ vault server -dev -config=path/to/config.hcl ...
...

Once the server is started, register the plugin in the Vault server's plugin catalog:

$ SHA256=$(openssl dgst -sha256 $GOPATH/vault-plugin-database-redis-elasticache | cut -d ' ' -f2)
$ vault write sys/plugins/catalog/database/vault-plugin-database-redis-elasticache \
        command=vault-plugin-database-redis-elasticache \
        sha256=$SHA256
...
Success! Data written to: sys/plugins/catalog/database/vault-plugin-database-redis-elasticache

Enable the database engine to use this plugin:

$ vault secrets enable database
...

Success! Enabled the database secrets engine at: database/

Once the database engine is enabled you can configure an ElastiCache instance:

$ vault write database/config/redis-mydb \
        plugin_name="vault-plugin-database-redis-elasticache" \
        username=$USERNAME \
        password=$PASSWORD \
        url=$URL \
        region=$REGION
...

Success! Data written to: database/config/redis-mydb

Configure a role:

$ vault write database/roles/redis-myrole \
        db_name="redis-mydb" \
        creation_statements="on ~* +@all" \
        default_ttl=5m \
        max_ttl=15m
...

Success! Data written to: database/roles/redis-myrole

And generate your first set of dynamic credentials:

$ vault read database/creds/redis-myrole
...

Key                Value
---                -----
lease_id           database/creds/redis-myrole/ID
lease_duration     Xm
lease_renewable    true
password           PASSWORD
username           v_token_redis-myrole_ID_EPOCH

Automated Tests

To run the tests, invoke make test:

$ make test

You can also specify a TESTARGS variable to filter tests like so:

$ make test TESTARGS='-run=TestConfig'

Acceptance Tests

The majority of tests must communicate with an existing ElastiCache instance. See the Environment Set Up section for instructions on how to prepare a test cluster.

Some environment variables are required to run tests expecting to communicate with an ElastiCache cluster. The username and password should be valid IAM access key and secret key with read and write access to the ElastiCache cluster used for testing. The URL should be the complete configuration endpoint including the port, for example: vault-plugin-elasticache-test.id.xxx.use1.cache.amazonaws.com:6379.

$ export TEST_ELASTICACHE_USERNAME="AWS ACCESS KEY ID"
$ export TEST_ELASTICACHE_PASSWORD="AWS SECRET ACCESS KEY"
$ export TEST_ELASTICACHE_URL="vault-plugin-elasticache-test.id.xxx.use1.cache.amazonaws.com:6379"
$ export TEST_ELASTICACHE_REGION="us-east-1"

$ make test

You can also specify a TESTARGS variable to filter tests like so:

$ make test TESTARGS='-run=TestConfig'