Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.

Commit f1ace23

Browse files
authored
Merge pull request #57 from opendistro/generate-certificates
Adds content on generating your own certificates
2 parents bd5137d + 70e545f commit f1ace23

13 files changed

+217
-12
lines changed

docs/install/docker-security.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ services:
7474
- "5601"
7575
environment:
7676
ELASTICSEARCH_URL: https://odfe-node1:9200
77+
ELASTICSEARCH_HOSTS: https://odfe-node1:9200
7778
volumes:
7879
- ./custom-kibana.yml:/usr/share/kibana/config/kibana.yml
7980
networks:

docs/install/docker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ services:
126126
- "5601"
127127
environment:
128128
ELASTICSEARCH_URL: https://odfe-node1:9200
129+
ELASTICSEARCH_HOSTS: https://odfe-node1:9200
129130
networks:
130131
- odfe-net
131132

docs/security/cross-cluster-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Cross-Cluster Search
44
parent: Security
5-
nav_order: 11
5+
nav_order: 30
66
---
77

88
# Cross-cluster search

docs/security/default-action-groups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Default Action Groups
44
parent: Security
5-
nav_order: 8
5+
nav_order: 20
66
---
77

88
# Default action groups

docs/security/disable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ If you disable the Security plugin in `elasticsearch.yml` (or delete the plugin
5151

5252
1. In `docker-compose.yml`, change `amazon/opendistro-for-elasticsearch-kibana:0.9.0` to `kibana-no-security`.
5353
1. Change `ELASTICSEARCH_URL` (`docker-compose.yml`) or `elasticsearch.url` (your custom `kibana.yml`) to `http://` rather than `https://`.
54+
1. Change `ELASTICSEARCH_HOSTS` or `elasticsearch.hosts` to `http://` rather than `https://`.
5455
1. Remove all `opendistro_security` lines from `kibana.yml`.
5556
1. `docker-compose up`.

docs/security/document-level-security.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Document-Level Security
44
parent: Security
5-
nav_order: 10
5+
nav_order: 22
66
---
77

88
# Document-level security
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
layout: default
3+
title: Generate Certificates
4+
parent: Security
5+
nav_order: 5
6+
---
7+
8+
# Generate certificates
9+
10+
If you don't have access to a certificate authority (CA) for your organization and want to use Open Distro for Elasticsearch for non-demo purposes, you can generate your own self-signed certificates using [OpenSSL](https://www.openssl.org/){:target='\_blank'}.
11+
12+
You can probably find OpenSSL in the package manager for your operating system.
13+
14+
On CentOS, use Yum:
15+
16+
```bash
17+
sudo yum install openssl
18+
```
19+
20+
On macOS, use [Homebrew](https://brew.sh/){:target='\_blank'}:
21+
22+
```bash
23+
brew install openssl
24+
```
25+
26+
27+
---
28+
29+
#### Table of contents
30+
1. TOC
31+
{:toc}
32+
33+
34+
---
35+
36+
## Generate private key
37+
38+
The first step in this process is to generate a private key using the `genrsa` command. As the name suggests, you should keep this file private.
39+
40+
Private keys need to be of sufficient length in order to be secure, so specify `2048`:
41+
42+
```bash
43+
openssl genrsa -out root-ca-key.pem 2048
44+
```
45+
46+
If desired, add the `-aes256` option to encrypt the key using the AES-256 standard. This option requires a password.
47+
48+
49+
## Generate root certificate
50+
51+
Next, use the key to generate a self-signed certificate for the root CA:
52+
53+
```bash
54+
openssl req -new -x509 -sha256 -key root-ca-key.pem -out root-ca.pem
55+
```
56+
57+
- The `-x509` option specifies that you want a self-signed certificate rather than a certificate request.
58+
- The `-sha256` option sets the hash algorithm to SHA-256. SHA-256 is the default in newer versions of OpenSSL, but older versions might use SHA-1.
59+
- Optionally, add `-days 3650` (10 years) or some other number of days to set an expiration date.
60+
61+
Specify details for your organization as prompted. Together, these details form the Distinguished Name (DN) of your CA.
62+
63+
64+
## Generate admin certificate
65+
66+
To generate an admin certificate, first create a new key:
67+
68+
```bash
69+
openssl genrsa -out admin-key-temp.pem 2048
70+
```
71+
72+
Then convert that key to PKCS#8 format for use in Java using a PKCS#12-compatible algorithm (3DES):
73+
74+
```bash
75+
openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
76+
```
77+
78+
Next, create a certificate signing request (CSR). This file acts as an application to a CA for a signed certificate:
79+
80+
```bash
81+
openssl req -new -key admin-key.pem -out admin.csr
82+
```
83+
84+
Fill in the details as prompted. You don't need to specify a challenge password. As noted in the [OpenSSL Cookbook](https://www.feistyduck.com/books/openssl-cookbook/){:target='\_blank'}, "Having a challenge password does not increase the security of the CSR in any way."
85+
86+
Finally, generate the certificate itself:
87+
88+
```bash
89+
openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem
90+
```
91+
92+
93+
## (Optional) Generate node and client certificates
94+
95+
Follow the steps in [Generate admin certificates](#generate-admin-certificate) with new file names to generate a new certificate for each node and as many client certificates as you need. Each certificate should use its own private key.
96+
97+
If you generate node certificates and have `opendistro_security.ssl.transport.enforce_hostname_verification` set to `true` (default), be sure to specify a Common Name (CN) for the certificate that matches the hostname of the intended node. If you want to use the same node certificate on all nodes (not recommended), set hostname verification to `false`. To learn more, see [Configure TLS certificates](../../security/tls-configuration/#advanced-hostname-verification-and-dns-lookup).
98+
99+
100+
### Sample script
101+
102+
```bash
103+
# Root CA
104+
openssl genrsa -out root-ca-key.pem 2048
105+
openssl req -new -x509 -sha256 -key root-ca-key.pem -out root-ca.pem
106+
# Admin cert
107+
openssl genrsa -out admin-key-temp.pem 2048
108+
openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem
109+
openssl req -new -key admin-key.pem -out admin.csr
110+
openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem
111+
# Node cert
112+
openssl genrsa -out node-key-temp.pem 2048
113+
openssl pkcs8 -inform PEM -outform PEM -in node-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node-key.pem
114+
openssl req -new -key node-key.pem -out node.csr
115+
openssl x509 -req -in node.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node.pem
116+
# Cleanup
117+
rm admin-key-temp.pem
118+
rm admin.csr
119+
rm node-key-temp.pem
120+
rm node.csr
121+
```
122+
123+
124+
## Get Distinguished Names
125+
126+
If you created admin and node certificates, you need to specify their DNs in `elasticsearch.yml`:
127+
128+
```yml
129+
opendistro_security.authcz.admin_dn:
130+
- 'CN=ADMIN,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'
131+
opendistro_security.nodes_dn:
132+
- 'CN=node1.example.com,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'
133+
```
134+
135+
But if you look at the `subject` of the certificate after creating it, you might see different formatting:
136+
137+
```
138+
subject=/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node1.example.com
139+
```
140+
141+
If you compare this string to the ones in `elasticsearch.yml` above, you can see that you need to invert the order of elements and use commas rather than slashes. To get the string you need:
142+
143+
```bash
144+
openssl x509 -subject -nameopt RFC2253 -noout -in node.pem
145+
```
146+
147+
Then you can copy and paste the output:
148+
149+
```
150+
subject= CN=node1.example.com,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA
151+
```
152+
153+
154+
## Configure certificates
155+
156+
This process generates many files, but the ones you need to add to your cluster configuration are:
157+
158+
- `root-ca.pem`
159+
- `admin.pem`
160+
- `admin-key.pem`
161+
- (Optional) `node.pem`
162+
- (Optional) `node-key.pem`
163+
164+
For information on adding and configuring these certificates, see [Docker security configuration](../../install/docker-security/) and [Configure TLS certificates](../tls-configuration).
165+
166+
167+
## Run securityadmin.sh
168+
169+
After configuring your certificates and starting Elasticsearch, run `securityadmin.sh` to initialize the Security plugin:
170+
171+
```
172+
./securityadmin.sh -cd ../securityconfig/ -icl -nhnv -cacert ../../../config/root-ca.pem -cert ../../../config/admin.pem -key ../../../config/admin-key.pem
173+
```
174+
175+
For more information about what this command does, see [Apply configuration changes](../security-admin/) and [Change passwords for read-only users](../../install/docker-security/#change-passwords-for-read-only-users).
176+
{: .tip }
177+
178+
If you're using Docker, see [Bash access to containers](../../install/docker/#bash-access-to-containers).
179+
180+
181+
## Kibana
182+
183+
Depending on your settings in `kibana.yml`, you might need to add `root-ca.pem` to your Kibana node, as well. You have two options: disable SSL verification or add the root CA.
184+
185+
- Disable SSL verification:
186+
187+
```yml
188+
elasticsearch.ssl.verificationMode: none
189+
```
190+
191+
- Add root CA:
192+
193+
```yml
194+
elasticsearch.ssl.certificateAuthorities: ["/usr/share/kibana/config/root-ca.pem"]
195+
elasticsearch.ssl.verificationMode: full
196+
```

docs/security/ldap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Active Directory and LDAP
44
parent: Security
5-
nav_order: 5
5+
nav_order: 10
66
---
77

88
# Active Directory and LDAP

docs/security/openid-connect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: OpenID Connect
44
parent: Security
5-
nav_order: 7
5+
nav_order: 12
66
---
77

88
# OpenID Connect

docs/security/permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
title: Permissions
44
parent: Security
5-
nav_order: 9
5+
nav_order: 21
66
---
77

88
# Permissions

0 commit comments

Comments
 (0)