Skip to content

📖 Implement BUILDKIT_CA_CERTS env variable to mount CA certificates inside spawned dagger-buildkitd container #2016

Closed

Description

@qjcg

What is the issue?

I'm trying to push an image to our private registry, but docker.#Push is failing with x509: certificate signed by unknown authority.

I'm running dagger locally on macOS and can confirm that the our private CA cert is indeed present in the system keychain as described here. I am able to manually run docker push my.private.registry/proj/example without issue.

Log output

[✗] actions.push               0.2s
6:15AM FTL failed to execute plan: task failed: actions.push._push: failed to do request: Head "https://<... redacted ...>/blobs/sha256:36d215df336793e88ec6c4e3b7ac55c1b553b65541854a0ce1b2171970ae9ede": x509: certificate signed by unknown authority

Steps to reproduce

  1. Use docker.#Push & { dest: "my.private.registry/proj/example" } in a dagger action, where the my.private.registry server certificate is signed by a private trusted CA.

Dagger version

0.2.4

OS version

macOS 10.15.7

Activity

  1. helderco commented on Apr 4, 2022

    @helderco
    Contributor

    Are you actually using $private-registry in there, or is it just a placeholder for the example?

  2. qjcg commented on Apr 4, 2022

    @qjcg
    Author

    Are you actually using $private-registry in there, or is it just a placeholder for the example?

    Just a placeholder for the example :)

  3. helderco commented on Apr 4, 2022

    @helderco
    Contributor

    Ok, but just to be clear... you're not trying to expand an environment variable inside dest?

  4. qjcg commented on Apr 4, 2022

    @qjcg
    Author

    you're not trying to expand an environment variable inside dest?

    No, not trying to expand any environment variables inside dest or anywhere else. In my actual dagger file, I'm using the real resolvable DNS name for our private registry.

    EDIT: I've updated the issue description above to remove any ambiguity.

  5. helderco commented on Apr 4, 2022

    @helderco
    Contributor

    Ok, I've used it successfully with the registry:2 docker image, behind Nginx and Let's Encrypt (in docker Swarm).

    Can you give any more details about your setup to enable us to reproduce your issue? I guess the error x509: certificate signed by unknown authority means you're self-signing or using a CA we don't have included.

  6. grouville commented on Apr 4, 2022

    @grouville
    Member

    @helderco related I think: moby/buildkit#1050. Especially this one: moby/buildkit#1050 (comment)

  7. grouville commented on Apr 4, 2022

    @grouville
    Member

    @qjcg I think there are two possibilities: you try to mount this certificate inside the container and check if it works (would be so cool🤞), or you'll need to have a custom Buidlkit setup if the certificate needs to be inside the buildkit container. An example is present here, and we can of course totally help: https://github.com/tonistiigi/buildkit/blob/56f76a56211bee437c0ef78e8fd9314bf9da9639/docs/buildkitd.toml.md

    How to connect to this different Buildkit container with Dagger:
    https://github.com/dagger/dagger/blob/3ddf6c995c09d172ba1280939f2c16ea48316b9a/docs/administrator/1013-operator-manual.md

  8. qjcg commented on Apr 4, 2022

    @qjcg
    Author

    self-signing or using a CA we don't have included

    Yes, I confirm that this is the case.

    you'll need to have a custom Buildlkit setup if the certificate needs to be inside the buildkit container

    After some more review, I'm pretty confident this is what will be needed, since from what I understand, docker.#Pull is executed in the buildkit container.

    I'll work on creating and using a custom buildkit (thanks for this link @grouville !) and report back here.

  9. grouville commented on Apr 4, 2022

    @grouville
    Member

    iew, I'm pretty confident this is what will be needed, since from what I understand, docker.#Pull is executed in the buildkit container.

    You may try this:

    docker run --net=host -d --restart always -v <mount your certificate> --name dagger-buildkitd --privileged moby/buildkit:v0.10.0
    
  10. qjcg commented on Apr 4, 2022

    @qjcg
    Author

    docker run --net=host -d --restart always -v $PWD/my-cert.pem:/etc/ssl/certs/my-cert.pem --name dagger-buildkitd --privileged moby/buildkit:v0.10.0

    @grouville I can confirm that running the above, mounting our private CA cert into the buildkit container, DOES in fact fix the issue --- I was able to use docker.#Push successfully in my dagger pipeline. Thank you!

    My 2 cents: this seems like a common enough scenario that a standard, built-in way to do this would take this from "fiddly & manual" UX to "awesome" UX :)

    Maybe something like:

    dagger.#Plan & {
      client: buildkit: certs: ca: [
        "myCA1.pem",
        "myCA2.pem",
      ]
      ...
    }
  11. grouville commented on Apr 4, 2022

    @grouville
    Member

    docker run --net=host -d --restart always -v $PWD/my-cert.pem:/etc/ssl/certs/my-cert.pem --name dagger-buildkitd --privileged moby/buildkit:v0.10.0

    @grouville I can confirm that running the above, mounting our private CA cert into the buildkit container, DOES in fact fix the issue --- I was able to use docker.#Push successfully in my dagger pipeline. Thank you!

    My 2 cents: this seems like a common enough scenario that a standard, built-in way to do this would take this from "fiddly & manual" UX to "awesome" UX :)

    Maybe something like:

    dagger.#Plan & {
      client: buildkit: certs: ca: [
        "myCA1.pem",
        "myCA2.pem",
      ]
      ...
    }

    Excellent idea 😇
    cc @helderco wdyt ?

  12. GooseYArd commented on Apr 4, 2022

    @GooseYArd

    I work in an organization which using an image registry which, in addition to presenting a server cert issued by a non-public CA, also requires a client certificate issued by the same CA for access, so ideally the mechanism used to identify the location of the issuing CA could include additional fields for a cert and key if client cert auth is required.

  13. helderco commented on Apr 4, 2022

    @helderco
    Contributor

    I don't think it should be in the plan. Using environment variables would be better. Like when you connect to a remote docker daemon you have DOCKER_TLS_VERIFY and DOCKER_CERT_PATH.

  14. qjcg commented on Apr 5, 2022

    @qjcg
    Author

    Env vars could definitely work, something like BUILDKIT_CA_CERTS.

  15. grouville commented on Apr 8, 2022

    @grouville
    Member

    @qjcg, I added the workaround to the doc: https://docs.dagger.io/1224/self-signed-certificates/. Closing this issue because it's more of a design improvement

  16. grouville commented on Apr 8, 2022

    @grouville
    Member

    Reopening after discussion with @helderco, just changing the name

  17. changed the title [-]🐞 Can't `docker.#Push` to private registry (`x509: certificate signed by unknown authority`)[/-] [+]📖 Implement `BUILDKIT_CA_CERTS` env variable to mount CA certificates inside `dagger-buildkitd`[/+] on Apr 8, 2022
  18. changed the title [-]📖 Implement `BUILDKIT_CA_CERTS` env variable to mount CA certificates inside `dagger-buildkitd`[/-] [+]📖 Implement `BUILDKIT_CA_CERTS` env variable to mount CA certificates inside spawned `dagger-buildkitd` container[/+] on Apr 8, 2022
  19. shykes commented on Dec 21, 2022

    @shykes
    Contributor

    I'm closing this since @qjcg fixed their problem with a workaround.

    Note that the core issue (ability to configure trusted CAs to support private docker registries) is not yet fixed: workarounds are still needed, not just for CUE developers but now Go, Python, NodeJS and GraphQL developers as well. Solving that issue is finally moving to the top of our list, and is tracked here: #4217

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions