|
77 | 77 | (format "%s/Library/Containers/com.docker.docker/Data/backend.sock" (System/getenv "HOME"))]]
|
78 | 78 | (some unix-socket-file coll)))
|
79 | 79 |
|
| 80 | +(defn- get-jfs-socket [] |
| 81 | + (let [coll [(or (System/getenv "JFS_SOCKET_PATH") "/jfs.sock") |
| 82 | + (format "%s/Library/Containers/com.docker.docker/Data/jfs.sock" (System/getenv "HOME"))]] |
| 83 | + (some unix-socket-file coll))) |
| 84 | + |
| 85 | +(defn jfs-get-secret [s] |
| 86 | + (curl/get |
| 87 | + (format "http://localhost/secrets/%s" s) |
| 88 | + {:raw-args ["--unix-socket" (get-jfs-socket)] |
| 89 | + :throw false})) |
| 90 | + |
80 | 91 | (defn backend-is-logged-in? [_]
|
81 | 92 | (curl/get
|
82 | 93 | "http://localhost/registry/is-logged-in"
|
|
310 | 321 | (def pull (comp (status? 200 "pull-image") pull-image))
|
311 | 322 | (def images (comp ->json list-images))
|
312 | 323 | (def containers (comp ->json (status? 200 "list-containers") list-containers))
|
| 324 | +(def secrets-get (comp ->json (status? 200 "secrets-get") jfs-get-secret)) |
313 | 325 |
|
314 | 326 | (defn add-latest [image]
|
315 | 327 | (let [[_ tag] (re-find #".*(:.*)$" image)]
|
|
367 | 379 | [s])
|
368 | 380 | (string/join " ; ")))
|
369 | 381 |
|
| 382 | +(defn get-secrets [{:keys [secrets]}] |
| 383 | + (logger/info (format "getting secrets %s" secrets)) |
| 384 | + (->> secrets |
| 385 | + (map (fn [[k v]] |
| 386 | + [v (:value (secrets-get (name k)))])) |
| 387 | + (into {}))) |
| 388 | + |
370 | 389 | (defn inject-secret-transform [container-definition]
|
371 | 390 | (check-then-pull container-definition)
|
372 |
| - (let [{:keys [Entrypoint Cmd Env]} |
| 391 | + (let [{:keys [Entrypoint Cmd Env User]} |
373 | 392 | (->
|
374 | 393 | (image-inspect {:Name (:image container-definition)})
|
375 | 394 | :Config)
|
376 | 395 | real-entrypoint (string/join " " (concat
|
377 | 396 | (or (:entrypoint container-definition) Entrypoint)
|
378 | 397 | (or (:command container-definition) Cmd)))]
|
379 |
| - (-> container-definition |
380 |
| - (assoc :entrypoint ["/bin/sh" "-c" (injected-entrypoint |
381 |
| - (:secrets container-definition) |
382 |
| - (concat |
383 |
| - Env |
384 |
| - (->> (:environment container-definition) |
385 |
| - (map (fn [[k v]] (format "%s=%s" (if (keyword? k) (name k) k) v))) |
386 |
| - (into []))) |
387 |
| - real-entrypoint)]) |
388 |
| - (dissoc :command)))) |
| 398 | + (if (#{"" "root"} User) |
| 399 | + (-> container-definition |
| 400 | + (assoc :entrypoint ["/bin/sh" "-c" (injected-entrypoint |
| 401 | + (:secrets container-definition) |
| 402 | + (concat |
| 403 | + Env |
| 404 | + (->> (:environment container-definition) |
| 405 | + (map (fn [[k v]] (format "%s=%s" (if (keyword? k) (name k) k) v))) |
| 406 | + (into []))) |
| 407 | + real-entrypoint)]) |
| 408 | + (dissoc :command)) |
| 409 | + (-> container-definition |
| 410 | + (update :environment (fnil merge {}) (get-secrets container-definition)))))) |
389 | 411 |
|
390 | 412 | (defn run-streaming-function-with-no-stdin
|
391 | 413 | "run container function with no stdin, and no timeout, but streaming stdout"
|
|
660 | 682 | output-channel (async/chan)]
|
661 | 683 | (start x)
|
662 | 684 | (.start ^Thread
|
663 |
| - (Thread. |
664 |
| - (fn [] |
665 |
| - (read-loop socket-channel c)))) |
| 685 | + (Thread. |
| 686 | + (fn [] |
| 687 | + (read-loop socket-channel c)))) |
666 | 688 | (async/go
|
667 | 689 | (docker/wait x)
|
668 | 690 | (async/>! c :stopped)
|
|
0 commit comments