• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..25-Jul-2019-

.gitignoreH A D25-Jul-2019249 2015

LICENSEH A D25-Jul-201916.3 KiB374293

MakefileH A D25-Jul-20191.3 KiB3924

README.mdH A D25-Jul-20195.9 KiB140103

client.goH A D25-Jul-20196.3 KiB232162

elasticsearch.goH A D25-Jul-201912 KiB354247

go.modH A D25-Jul-2019544 1613

go.sumH A D25-Jul-201913.6 KiB144143

README.md

1# Elasticsearch Database Secrets Engine
2This plugin provides unique, short-lived credentials for Elasticsearch using native X-Pack Security.
3
4## Getting Started
5
6To take advantage of this plugin, you must first enable Elasticsearch's native realm of security by activating X-Pack. These
7instructions will walk you through doing this using ElasticSearch 7.1.1.
8
9### Enable X-Pack Security in Elasticsearch
10
11Read [Securing the Elastic Stack](https://www.elastic.co/guide/en/elastic-stack-overview/7.1/elasticsearch-security.html) and
12follow [its instructions for enabling X-Pack Security](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/setup-xpack.html).
13
14### Enable Encrypted Communications
15
16This plugin communicates with Elasticsearch's security API. In ES 7.1.1, you must enable TLS to consume that API.
17
18To set up TLS in Elasticsearch, first read [encrypted communications](https://www.elastic.co/guide/en/elastic-stack-overview/7.1/encrypting-communications.html)
19and go through its instructions on [encrypting HTTP client communications](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/configuring-tls.html#tls-http).
20
21After enabling TLS on the Elasticsearch side, you'll need to convert the .p12 certificates you generated to other formats so they can be
22used by Vault. [Here is an example using OpenSSL](https://stackoverflow.com/questions/15144046/converting-pkcs12-certificate-into-pem-using-openssl)
23to convert our .p12 certs to the pem format.
24
25Also, on the instance running Elasticsearch, we needed to install our newly generated CA certificate that was originally in the .p12 format.
26We did this by converting the .p12 CA cert to a pem, and then further converting that
27[pem to a crt](https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key), adding that crt to `/usr/share/ca-certificates/extra`,
28and using `sudo dpkg-reconfigure ca-certificates`.
29
30The above instructions may vary if you are not using an Ubuntu machine. Please ensure you're using the methods specific to your operating
31environment. Describing every operating environment is outside the scope of these instructions.
32
33### Set Up Passwords
34
35When done, verify that you've enabled X-Pack by running `$ $ES_HOME/bin/elasticsearch-setup-passwords interactive`. You'll
36know it's been set up successfully if it takes you through a number of password-inputting steps.
37
38### Create a Role for Vault
39
40Next, in Elasticsearch, we recommend that you create a user just for Vault to use in managing secrets.
41
42To do this, first create a role that will allow Vault the minimum privileges needed to administer users and passwords by performing a
43POST to Elasticsearch. To do this, we used the `elastic` superuser whose password we created in the
44`$ $ES_HOME/bin/elasticsearch-setup-passwords interactive` step.
45
46```
47$ curl \
48    -X POST \
49    -H "Content-Type: application/json" \
50    -d '{"cluster": ["manage_security"]}' \
51    http://elastic:$PASSWORD@localhost:9200/_xpack/security/role/vault
52```
53
54Next, create a user for Vault associated with that role.
55
56```
57$ curl \
58    -X POST \
59    -H "Content-Type: application/json" \
60    -d @data.json \
61    http://elastic:$PASSWORD@localhost:9200/_xpack/security/user/vault
62```
63
64The contents of `data.json` in this example are:
65```
66{
67 "password" : "myPa55word",
68 "roles" : [ "vault" ],
69 "full_name" : "Hashicorp Vault",
70 "metadata" : {
71   "plugin_name": "Vault Plugin Secrets ElasticSearch",
72   "plugin_url": "https://github.com/hashicorp/vault-plugin-secrets-elasticsearch"
73 }
74}
75```
76
77Now, Elasticsearch is configured and ready to be used with Vault.
78
79## Example Walkthrough
80
81Here is an example of how to successfully configure and use this secrets engine using the Vault CLI. Note that the
82`plugin_name` may need to be `vault-plugin-database-elasticsearch` if you manually mounted it rather than using the
83version of the plugin built in to Vault.
84```
85export ES_HOME=/home/somewhere/Applications/elasticsearch-7.1.1
86
87vault secrets enable database
88
89vault write database/config/my-elasticsearch-database \
90    plugin_name="elasticsearch-database-plugin" \
91    allowed_roles="internally-defined-role,externally-defined-role" \
92    username=vault \
93    password=myPa55word \
94    url=http://localhost:9200 \
95    ca_cert=/usr/share/ca-certificates/extra/elastic-stack-ca.crt.pem \
96    client_cert=$ES_HOME/config/certs/elastic-certificates.crt.pem \
97    client_key=$ES_HOME/config/certs/elastic-certificates.key.pem
98
99# create and get creds with one type of role
100vault write database/roles/internally-defined-role \
101    db_name=my-elasticsearch-database \
102    creation_statements='{"elasticsearch_role_definition": {"indices": [{"names":["*"], "privileges":["read"]}]}}' \
103    default_ttl="1h" \
104    max_ttl="24h"
105
106vault read database/creds/internally-defined-role
107
108# create and get creds with another type of role
109vault write database/roles/externally-defined-role \
110    db_name=my-elasticsearch-database \
111    creation_statements='{"elasticsearch_roles": ["vault"]}' \
112    default_ttl="1h" \
113    max_ttl="24h"
114
115vault read database/creds/externally-defined-role
116
117# renew credentials
118vault lease renew database/creds/internally-defined-role/nvJ6SveX9PN1E4BlxVWdKuX1
119
120# revoke credentials
121vault lease revoke database/creds/internally-defined-role/nvJ6SveX9PN1E4BlxVWdKuX1
122
123# rotate root credentials
124vault write -force database/rotate-root/my-elasticsearch-database
125```
126
127## Developing
128
129The Vault plugin system is documented on the [Vault documentation site](https://www.vaultproject.io/docs/internals/plugins.html).
130
131You will need to define a plugin directory using the `plugin_directory` configuration directive, then place the `vault-plugin-database-elasticsearch` executable generated above in the directory.
132
133Register the plugin using
134
135```
136vault write sys/plugins/catalog/vault-plugin-database-elasticsearch \
137    sha256=$(sha256sum bin/vault-plugin-database-elasticsearch) \
138    command="vault-plugin-database-elasticsearch"
139```
140