docker

viesti 2020-12-07T12:06:13.038100Z

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

viesti 2020-12-07T12:07:17.038900Z

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

mozinator2 2020-12-07T12:09:53.040800Z

(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 "any@valid.email",
       :serveraddress "<https://us.gcr.io>"})))
 
      (d/invoke images
                {:op :ImageCreate,
                 :params {:fromImage image-name,
                          :X-Registry-Auth registry-auth}}))

viesti 2020-12-07T12:09:53.040900Z

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"

viesti 2020-12-07T12:10:05.041100Z

ah, I'll try that!

mozinator2 2020-12-07T12:10:41.041300Z

🙂

viesti 2020-12-07T12:14:26.041900Z

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

viesti 2020-12-07T12:14:35.042100Z

thank you! 🙂

mozinator2 2020-12-07T12:27:00.042300Z

yw!