amperity / vault-clj

Clojure client for Hashicorp's Vault secret management system.
Other
70 stars 17 forks source link

Veil secrets #105

Closed greglook closed 11 months ago

greglook commented 11 months ago

Despite the HTTP client defining a custom Object#toString() and print-method, there are cases where the internal state can still be exposed in logs and other print output. This specifically happens when the client is fed into a pretty-printer (such as clj-commons/pretty) which wind up traversing the client's attributes as a record type. This is undesirable, because the auth and leases fields contain secret information which should remain private.

To address this, we can define a new Veil type which hides the data in an internal field. There's a bunch of refactoring to go with this, mostly adjusting callsites to unveil the data before using it. To simplify this, and provide a more consistent interface, several functions in the vault.auth and vault.lease namespaces have shifted to accept clients directly instead of operating on the "store" atom.

Before this change:

vault.repl=> (puget.printer/pprint client)
#vault.client.http.HTTPClient
{:address "http://127.0.0.1:8200",
 :auth #<Atom@3985175e {:vault.auth/token "t0p-53cr3t"}>,
 :flow #<vault.client.flow.SyncHandler@d91e8c7>,
 :http-opts nil,
 :leases #<Atom@66011fbc {}>,
 :maintenance-executor #<java.util.concurrent.ScheduledThreadPoolExecutor@77afdbc5 ...>,
 :maintenance-task #<Future@757ad227 pending>}

After:

vault.repl=> (puget.printer/pprint client)
#vault.client.http.HTTPClient
{:address "http://127.0.0.1:8200",
 :auth #<vault.util.Veil@6137dc84>,
 :flow #<vault.client.flow.SyncHandler@22f1a340>,
 :http-opts nil,
 :leases #<vault.util.Veil@32f243f>,
 :maintenance-executor #<java.util.concurrent.ScheduledThreadPoolExecutor@7aa5292d ...>,
 :maintenance-task #<Future@25291901 pending>}