How to handle secrets on the command line
smallstep.com·11h·
Discuss: Hacker News
Flag this post

Updated on: May 20, 2024

The command line really wasn’t designed for secrets. So, keeping secrets secret on the command line requires some extra care and effort. The other day in my homelab I was configuring a TLS client certificate for a Grafana datasource. The intention was to write something I could run on a timer whenever the certificate is renewed. The command needed to:

  1. Build some JSON with the renewed certificate and private key injected into it
  2. PUT it to Grafana’s API to update the datasource configuration.

I thought I was being very clever when I wrote this lil’ Bash pipeline:

BEARER_TOKEN=MhY3b3i3gFpa9otnLQVznJYoWLxpGJUod3iDJwCKRFUVtuALGJooBJuCUf7w9HJfbu;
jq -n
--arg ca_cert "$(< $STEPPATH/certs/root_ca.crt)"
--arg client_cert "$(< $CERT_LOCATION)"
--arg clien...

Similar Posts

Loading similar posts...