Skip to content

Commit

Permalink
♻️ Elasticsearch cert renewal (#60)
Browse files Browse the repository at this point in the history
# Elasticsearch
Creates `elastic-certs.sh` script to pull renewed SSL certificate from
`traefik` and patch the kubernetes secret in the `elastic` namespace.

## Usage
```sh
# Update elastic cert
./elastic-certs.sh update-elasticsearch
# Update kibana cert
./elastic-certs.sh update-kibana
```

Closes #56
  • Loading branch information
mrharpo authored Sep 6, 2024
1 parent 1451609 commit 713cb73
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ on:
jobs:
update:
name: 🦿 Update dependencies
uses: WGBH-MLA/.github/.github/workflows/update.yml@dependabot/github_actions/dot-github/workflows/peter-evans/create-pull-request-7
uses: WGBH-MLA/.github/.github/workflows/update.yml@main
49 changes: 49 additions & 0 deletions elasticsearch/elastic-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

help() {
echo
echo "Usage: $0 <update-elasticsearch|update-kibana>"
echo
echo This script gets the latest certificate from Traefik
echo and updates the Elasticsearch or Kibana k8s secret
echo
}

get-traefik() {
# Get the name of the running Traefik pod
TRAEFIK=$(kubectl -n traefik -o json get po | jq -r .items[0].metadata.name)

if [ -z "$TRAEFIK" ]; then
echo "Traefik pod not found"
exit 1
fi
echo "$TRAEFIK"
}

get-cert() {
# Get the certificate object from Traefik that matches the domain
DOMAIN=$1
CERT=$(kubectl exec -n traefik $TRAEFIK -- cat /ssl-certs/acme-production.json | jq --arg domain $DOMAIN -r '.production.Certificates[] | select( .domain.main==$domain ).certificate')

if [ -z "$CERT" ]; then
echo "Certificate not found for $DOMAIN"
exit 1
fi
echo "$CERT"
}

update-elasticsearch() {
# Update the Elasticsearch secret with the latest certificate
TRAEFIK=$(get-traefik)
CERT=$(get-cert "elastic.wgbh-mla.org")
kubectl -n elastic patch secret elastic-certs -p "{\"data\":{\"tls.crt\":\"$CERT\"}}"
}

update-kibana() {
# Update the Kibana secret with the latest certificate
TRAEFIK=$(get-traefik)
CERT=$(get-cert "search.wgbh-mla.org")
kubectl -n elastic patch secret kibana-certs -p "{\"data\":{\"tls.crt\":\"$CERT\"}}"
}

"$@" || (help && exit 1)

0 comments on commit 713cb73

Please sign in to comment.