Merge pull request #84 from jolt-lang/bake-env-scrub

host: JOLT_BAKE_ENV_ALLOWLIST scrubs the env during image bakes (jolt-s3j)
This commit is contained in:
Dmitri Sotnikov 2026-06-12 02:00:28 +00:00 committed by GitHub
commit df909d0914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View file

@ -493,7 +493,26 @@
"user.home" (os/getenv "HOME") "user.home" (os/getenv "HOME")
"java.io.tmpdir" (or (os/getenv "TMPDIR") "/tmp") "java.io.tmpdir" (or (os/getenv "TMPDIR") "/tmp")
dflt)) dflt))
"getenv" (fn [&opt k] (if k (os/getenv k) (os/environ))) # JOLT_BAKE_ENV_ALLOWLIST (jolt-s3j): during an image bake (jpm build of a
# native executable, set by the project's build.sh) the env snapshot that
# libraries like config.core capture at load gets MARSHALED INTO THE BINARY
# — GitHub push protection once flagged real API tokens inside an example's
# build output. With the var set, System/getenv serves only the listed
# comma-separated names (single-var reads of unlisted names return nil), so
# nothing secret can bake. Unset (the normal runtime case), reads are live
# and unfiltered.
"getenv" (fn [&opt k]
(def allow (os/getenv "JOLT_BAKE_ENV_ALLOWLIST"))
(if (nil? allow)
(if k (os/getenv k) (os/environ))
(let [names (string/split "," allow)
ok @{}]
(each n names (put ok (string/trim n) true))
(if k
(when (get ok k) (os/getenv k))
(let [e (os/environ) out @{}]
(eachp [ek ev] e (when (get ok ek) (put out ek ev)))
out)))))
# the property subset getProperty serves, as an iterable map # the property subset getProperty serves, as an iterable map
"getProperties" (fn [] "getProperties" (fn []
{"os.name" (case (os/which) {"os.name" (case (os/which)

View file

@ -186,3 +186,16 @@
["replace fn gets group vector" "\"v=k\"" ["replace fn gets group vector" "\"v=k\""
"(do (require (quote [clojure.string :as s9])) (s9/replace \"k=v\" #\"(\\w+)=(\\w+)\" (fn [[_ k v]] (str v \"=\" k))))"] "(do (require (quote [clojure.string :as s9])) (s9/replace \"k=v\" #\"(\\w+)=(\\w+)\" (fn [[_ k v]] (str v \"=\" k))))"]
["indexOf int needle is a char code" "1" "(.indexOf \"a=b\" 61)"]) ["indexOf int needle is a char code" "1" "(.indexOf \"a=b\" 61)"])
# JOLT_BAKE_ENV_ALLOWLIST (jolt-s3j): with the allowlist set, System/getenv
# serves only the listed names — so an image bake can't marshal the builder's
# secrets into the binary. Unset, reads are live and unfiltered.
(defspec "host-interop / bake env scrub"
["unlisted name reads nil under the allowlist" "nil"
"(do (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" \"PATH\") (let [r (System/getenv \"HOME\")] (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" nil) r))"]
["listed name still reads" "true"
"(do (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" \"HOME\") (let [r (System/getenv \"HOME\")] (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" nil) (string? r)))"]
["full snapshot filtered to the allowlist" "true"
"(do (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" \"HOME\") (let [e (System/getenv)] (janet.os/setenv \"JOLT_BAKE_ENV_ALLOWLIST\" nil) (and (contains? (set (keys e)) \"HOME\") (= 1 (count (keys e))))))"]
["no allowlist: unfiltered live reads" "true"
"(string? (System/getenv \"HOME\"))"])