Skip to content

Commit fec558a

Browse files
Merge pull request #2077 from Red-GV/958-pkcs12-certs
Converting JKS format to PKCS for elasticsearch
2 parents e7fbabb + cce8890 commit fec558a

File tree

10 files changed

+105
-437
lines changed

10 files changed

+105
-437
lines changed

elasticsearch/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ else
7777
exit 1
7878
fi
7979

80-
build_jks_truststores
80+
build_p12_truststores
8181
./init.sh &
8282

8383
# this is because the deployment mounts the configmap at /usr/share/java/elasticsearch/config

elasticsearch/utils/es_seed_acl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ function sgadmin {
2424
-i $( get_security_conf_index ) \
2525
-h ${ES_CLUSTER_HOST} \
2626
-p ${ES_CLUSTER_PORT} \
27-
-ks ${ES_PATH_CONF}/secret/admin.jks \
28-
-kst JKS \
27+
-ks ${ES_PATH_CONF}/secret/admin.p12 \
28+
-kst PKCS12 \
2929
-kspass kspass \
30-
-ts ${ES_PATH_CONF}/secret/truststore \
31-
-tst JKS \
30+
-ts ${ES_PATH_CONF}/secret/truststore.p12 \
31+
-tst PKCS12 \
3232
-tspass tspass \
3333
-nhnv \
3434
-arc \

elasticsearch/utils/logging

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ check_index_exists() {
8080
[[ $response_code -eq 200 ]] || exit 1
8181
}
8282

83-
# Pull in the certs provided in our secret and generate our necessary jks and truststore files
84-
build_jks_truststores() {
83+
# Pull in the certs provided in our secret and generate our necessary p12 and truststore files
84+
build_p12_truststores() {
8585

8686
copy_keys_to_secretdir
87-
87+
8888
info "Building required jks files and truststore"
8989

9090
# check for lack of admin.jks
@@ -124,6 +124,45 @@ build_jks_truststores() {
124124
-alias sig-ca
125125
fi
126126

127+
info "Building required p12 files and truststore"
128+
129+
# check for lack of admin.p12
130+
if [[ ! -e $secret_dir/admin.p12 ]]; then
131+
build_p12_from_pem "admin" "admin-key" "admin-cert" "admin-ca"
132+
fi
133+
134+
# check for elasticsearch.key and elasticsearch.crt
135+
if [[ -e $secret_dir/elasticsearch.key && -e $secret_dir/elasticsearch.crt && ! -e $secret_dir/searchguard-key.p12 ]]; then
136+
build_p12_from_pem "elasticsearch" "elasticsearch.key" "elasticsearch.crt" "admin-ca"
137+
mv $secret_dir/elasticsearch.p12 $secret_dir/searchguard-key.p12
138+
fi
139+
140+
# check for logging-es.key and logging-es.crt
141+
if [[ -e $secret_dir/logging-es.key && -e $secret_dir/logging-es.crt && ! -e $secret_dir/key.p12 ]]; then
142+
build_p12_from_pem "logging-es" "logging-es.key" "logging-es.crt" "admin-ca"
143+
mv $secret_dir/logging-es.p12 $secret_dir/key.p12
144+
fi
145+
146+
if [[ ! -e $secret_dir/truststore.p12 ]]; then
147+
build_p12_truststore "truststore" "admin-ca"
148+
fi
149+
150+
if [[ ! -e $secret_dir/searchguard-truststore.p12 ]]; then
151+
build_p12_truststore "searchguard-truststore" "admin-ca"
152+
fi
153+
154+
info "JKS files will be removed soon and replaced with p12 certs..."
155+
156+
#rm $secret_dir/*.jks
157+
158+
#if [[ -e $secret_dir/truststore ]]; then
159+
# rm $secret_dir/truststore
160+
#fi
161+
162+
#if [[ -e $secret_dir/searchguard.truststore ]]; then
163+
# rm $secret_dir/searchguard.truststore
164+
#fi
165+
127166
# set all files to 600 and dir to 700
128167
chmod -R go-rwx,u+X $secret_dir
129168
}
@@ -161,6 +200,50 @@ wait_for_port_open() {
161200
exit 1
162201
}
163202

203+
build_p12_from_pem() {
204+
205+
p12_name=$1
206+
key_name=$2
207+
cert_name=$3
208+
ca_name=$4
209+
210+
openssl \
211+
pkcs12 \
212+
-export \
213+
-in $secret_dir/$cert_name \
214+
-inkey $secret_dir/$key_name \
215+
-out $secret_dir/$p12_name.p12 \
216+
-passout pass:kspass
217+
218+
keytool \
219+
-importkeystore \
220+
-srckeystore $secret_dir/$p12_name.p12 \
221+
-srcstoretype PKCS12 \
222+
-srcstorepass kspass \
223+
-destkeystore $secret_dir/$p12_name.p12 \
224+
-deststoretype PKCS12 \
225+
-deststorepass kspass \
226+
-noprompt \
227+
2>/dev/null
228+
229+
keytool \
230+
-changealias \
231+
-keystore $secret_dir/$p12_name.p12 \
232+
-storepass kspass \
233+
-alias 1 \
234+
-destalias $p12_name \
235+
2>/dev/null
236+
237+
keytool \
238+
-import \
239+
-file $secret_dir/$ca_name \
240+
-keystore $secret_dir/$p12_name.p12 \
241+
-storepass kspass \
242+
-noprompt \
243+
-alias sig-ca \
244+
2>/dev/null
245+
}
246+
164247
build_jks_from_pem() {
165248

166249
jks_name=$1
@@ -205,6 +288,20 @@ build_jks_from_pem() {
205288
2>/dev/null
206289
}
207290

291+
build_p12_truststore() {
292+
293+
trust_name=$1
294+
ca_name=$2
295+
296+
keytool \
297+
-import \
298+
-file $secret_dir/$ca_name \
299+
-keystore $secret_dir/$trust_name.p12 \
300+
-storepass tspass \
301+
-noprompt \
302+
-alias sig-ca
303+
}
304+
208305
copy_keys_to_secretdir() {
209306

210307
if [ -d $provided_secret_dir ] ; then

hack/ssl/createSecrets.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

hack/ssl/etc/root-ca.conf

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)