Fork me on GitHub
#docker
<
2020-12-07
>
viesti12:12:13

Hmm, trying to authenticate to a private registry with clj-docker-client, but didn't quite yet succeed

viesti12:12:17

the api docs (https://docs.docker.com/engine/api/v1.40/#section/Authentication) mention a X-Registry-Auth header, but didn't find out how to include it in :ImageCreate operation

mozinator212:12:53

(defn- encode-base64
  [input]
  (.encodeToString (java.util.Base64/getEncoder) (.getBytes input)))

(def ^:private registry-auth
  (encode-base64
    (json/write-str
      {:username "_json_key",
       :password (json/write-str (edn/read-string (slurp "auth.edn"))),
       :email "[email protected]",
       :serveraddress ""})))
 
      (d/invoke images
                {:op :ImageCreate,
                 :params {:fromImage image-name,
                          :X-Registry-Auth registry-auth}}))

viesti12:12:53

there's also /auth endpoint, posting to it seems to make a login to my private registry, but the response gives an empty IdentityToken

(req/fetch {:conn (req/connect* {:uri "unix:///var/run/docker.sock"})
            :url  "/v1.40/auth"
            :method :post
            :body {:username "reader"
                   :password "bar"
                   :serveraddress "localhost:5000"}})
"{\"IdentityToken\":\"\",\"Status\":\"Login Succeeded\"}\n"

viesti12:12:05

ah, I'll try that!

viesti12:12:26

oh man, it worked, had used encode, instead of encodeToString, just a minute ago facepalm

viesti12:12:35

thank you! 🙂