When you deploy elasticsearch in k8s via ECK by default it takes care of the transport certificates/http certificates/CA creation if you don't use your own custom ones.
Lets say that your cluster is up and running and now you are trying to configure something like SAML/LDAP/OIDC or something else that requires content to be made available to the elasticsearch pod but its a bit sensitive so you need it to be stored as a secret such as CA, certificates, etc. How would you go about doing this?
Following example will add a custom certificate authority to be used with your xpack settings when configuring various authentication with elasticsearch so that even if your auth provider has custom/internal/self-signed certificate it will work.
Create a secret
There are multiple ways to create the secret.
- via command line
$ kubectl create secret generic ca --from-file=ca.crt
- via yaml
$ cat ca.crt
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIVAMHMs72Dweteroshd5dObzjgtry+MA0GCSqGSIb3DQEB
CwUAMDQxMjAwBgNVBAMTKUVsYXN0aWMgQ2VydGlmaWNhdGUgVG9vbCBBdXRvZ2Vu
ZXJhdGVkIENBMB4XDTIyMDcyNzEzNDkyOFoXDTI1MDcyNjEzNDkyOFowNDEyMDAG
A1UEAxMpRWxhc3RpYyBDZXJ0aWZpY2F0ZSBUb29sIEF1dG9nZW5lcmF0ZWQgQ0Ew
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCxt6JV2y5PXhLyo5jU2RJw
g1E7ntt5an1sMXBg01Tgne0E3RH8ga4XSZnzPGqCP5w9WYvlIsBPRxj6tmQAL1V7
FS62e0WENbaIJyuPk4O3JhlsYIOe6ACOdjfq72w14gBdqPyRn6txIPZErXL2SmC5
uxd2ccAIW3FCMsvTgSLAKWkKpIgPTe3OznRJ7q0KJ5dNO7kCRukOrQ4eFrW6YboU
Iil8QtrjZqtG0IflkfKp+r7pzIgiZnn28hS7gz4wCVabzJlOy1Usgb71xOUyUNHP
cG1qLNBPEvxgqLP3VL6aI40Jta5IO4h4NOzRVFqgE+QvuELsW7scD8O1MVL3H+lp
AgMBAAGjUzBRMB0GA1UdDgQWBBR2eVQVdE6JmhNWi8jT9jitZdHB1TAfBgNVHSME
GDAWgBR2eVQVdE6JmhNWi8j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o5cnZMS3lYOGhRZWV1MTBRanF4ZGJNUTVsdXhJOGFRTnY0b1N2UU5iCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
kind: Secret
metadata:
name: ca
type: Opaque
kubectl apply -f secret.yml
Verify your secret
$ kubectl get secret
NAME TYPE DATA AGE
ca Opaque 2 23m
...
$ kubectl describe secret ca
Name: ca
Namespace: default
Labels: <none>
Annotations: <none>
Type: Opaque
Data
====
ca.crt: 1200 bytes
Edit your elasticsearch deployment to create the volumeMount
Updated my podTemplate to include the volumeMount
podTemplate:
metadata:
labels:
scrape: es
spec:
initContainers:
- name: sysctl
securityContext:
privileged: true
runAsUser: 0
command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']
containers:
- name: elasticsearch
volumeMounts:
- name: ca
mountPath: /usr/share/elasticsearch/config/certificates
readOnly: true
volumes:
- name: ca
secret:
secretName: ca
Apply and once the change is done you can see the mount and the file
$ kubectl exec -it eck-lab-es-default-0 -- bash
Defaulted container "elasticsearch" out of: elasticsearch, elastic-internal-init-filesystem (init), elastic-internal-suspend (init), sysctl (init)
elasticsearch@eck-lab-es-default-0:~$ cd config/certificates/
elasticsearch@eck-lab-es-default-0:~/config/certificates$ pwd
/usr/share/elasticsearch/config/certificates
elasticsearch@eck-lab-es-default-0:~/config/certificates$ ls
ca.crt
elasticsearch@eck-lab-es-default-0:~/config/certificates$ cat ca.crt
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIVAMHMs72Dweteroshd5dObzjgtry+MA0GCSqGSIb3DQEB
CwUAMDQxMjAwBgNVBAMTKUVsYXN0aWMgQ2VydGlmaWNhdGUgVG9vbCBBdXRvZ2Vu
ZXJhdGVkIENBMB4XDTIyMDcyNzEzNDkyOFoXDTI1MDcyNjEzNDkyOFowNDEyMDAG
A1UEAxMpRWxhc3RpYyBDZXJ0aWZpY2F0ZSBUb29sIEF1dG9nZW5lcmF0ZWQgQ0Ew
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCxt6JV2y5PXhLyo5jU2RJw
g1E7ntt5an1sMXBg01Tgne0E3RH8ga4XSZnzPGqCP5w9WYvlIsBPRxj6tmQAL1V7
FS62e0WENbaIJyuPk4O3JhlsYIOe6ACOdjfq72w14gBdqPyRn6txIPZErXL2SmC5
uxd2ccAIW3FCMsvTgSLAKWkKpIgPTe3OznRJ7q0KJ5dNO7kCRukOrQ4eFrW6YboU
Iil8QtrjZqtG0IflkfKp+r7pzIgiZnn28hS7gz4wCVabzJlOy1Usgb71xOUyUNHP
cG1qLNBPEvxgqLP3VL6aI40Jta5IO4h4NOzRVFqgE+QvuELsW7scD8O1MVL3H+lp
AgMBAAGjUzBRMB0GA1UdDgQWBBR2eVQVdE6JmhNWi8jT9jitZdHB1TAfBgNVHSME
GDAWgBR2eVQVdE6JmhNWi8jT9jitZdHB1TAPBgNVHRMBAf8EBTADAQH/MA0GCSqG
SIb3DQEBCwUAA4IBAQASnFScLgyFnxUsCx0pceQhBlRX5lvricMj3Z1PbJlPnWMY
IESLuuG0yOE4nutwuDcMf2+A3SmpXRCwcuLpHztJQ4w4Lo6jqOrlyFS6cfRfq+QP
mU2y5R7khhOT3vGSh6QFoHL5TyF2zFDv4Gy4b3Bp3kFaYhKnskrGx+CXjH8Dtxy5
mFWvtrodx2FoCy7RzPby368moqADuSuEWshO9t62IQs4JYL63NY1lxtI24x5beFv
H0fgi8Etcmc0oIdy8QYptrcHsZ6HZWD9sJZytK1+1jPTd3GQ8q3Mpx7qitRDCHCY
9rvLKyX8hQeeu10QjqxdbMQ5luxI8aQNv4oSvQNb
-----END CERTIFICATE-----
Now you can use this path/file to configure your settings
Example:
xpack:
security:
authc:
realms:
ldap:
ldap1:
order: 0
url: "ldaps://ldap.example.com:636"
ssl:
certificate_authorities: [ "/usr/share/elasticsearch/config/certificates/ca.crt" ]