Comment on page
Authenticating Git and image registries
This page guides you through passing Git and Docker authentication to Earthly builds, to empower related Earthly features, like
A number of Earthly features use Git credentials to perform remote Git operations:
- Resolving a build context when referencing remote targets
There are two possible ways to pass Git authentication to Earthly builds:
- Via SSH agent socket (for SSH-based authentication)
- Via username-password (usually for HTTPS Git URLs)
Earthly defaults to an
autoauthentication mode, where ssh-based authentication is automatically attempted, and falls back to https-based cloning.
If you are having trouble accessing a private repository and want to use ssh-based authentication, first make sure
ssh-agentis running and the
SSH_AUTH_SOCKenvironment variable is set. If not, you can start it with
Next make sure your private key has been added by running
ssh-add <path to key>.
For users who want explicit control over git authentication, the following sections explain how.
Earthly uses the environment variable
SSH_AUTH_SOCKto detect where the SSH agent socket is located and mounts that socket to the BuildKit daemon container. (As an exception, on Mac, Docker's compatibility SSH auth socket is used instead).
If you need to override the SSH agent socket, you can set the environment variable
EARTHLY_SSH_AUTH_SOCK, or use the
--ssh-auth-sockflag to point to an alternative SSH agent.
In order for the SSH agent to have the right credentials available, make sure you run
ssh-addbefore executing Earthly builds.
Another key setting is the
authmode for the git site that hosts the repository. By default earthly automatically default to
sshauthentication if the ssh auth agent is running and has at least 1 key loaded, otherwise
earthlywill fallback to using non-authenticated HTTPS.
Global override via environment variables (deprecated)
Alternatively, environment variables can be set which will be override all host entries from the config file:
However, environment variable authentication are now deprecated in favor of using the configuration file instead.
bitbucket.orghave been tested as SCM providers. Without any host-specific configuration, Earthly first attempts to perform a clone over SSH on the default SSH port (22), and will fallback to HTTPS, followed by HTTP. In the event access can only be established over HTTP, Earthly will refuse to send credentials due to the insecure nature of HTTP.
Earthly can be configured to use a non-standard SSH port, by using the
When Earthly encounters a remote reference such as
ghe.internal.mycompany.com/user/repo+some-target, the git repository will be cloned using an explicit SSH scheme, for example:
git clone ssh://[email protected]:2222/user/repo.git.
The explicit ssh-scheme is an absolute path on the server's file-system; if the git repositories are located in a different location (e.g.
prefixconfiguration option can be specified.
Remapping Git Repositories Paths Using Regular Expressions
prefixconfiguration options are the preferred way to configure self-hosted git repositories; however prior to the introduction of these options, it was suggested to use a regular expression and substitution pattern:
Earthly, by default, assumes git repos are stored under two levels (i.e.
<org>/<path>.git). A regular expression must be configured in order to support sub groups:
example-orgis the name of your GitLab organisation. Note that the
)parenthesis are required, as they are used to assign the matched value to the
$2, ... values.
The pattern will depend on how your subgroups are setup; if you use a mix of 2 and 3 level groupings, you will have to configure them separately:
patternis used, the key of the git configuration is simply used by log messages, it is not used for any matching.
Note that patterns are evaluated from the top to the bottom, subgroup specific configurations should be listed first.
You can run earthly with
--verbose, which will provide debugging messages to help understand how a remote earthly reference is transformed into a git URL for cloning.
You can additionally enable low-level git debugging in buildkit, by adding the following to your
buildkit_additional_args: [ '-e', 'BUILDKIT_DEBUG_GIT=1' ]
The buildkit logs can be displayed with
docker logs earthly-buildkitd.
Docker credentials are used in Earthly for inheriting from private images (via
FROM) and for pushing images (via
SAVE IMAGE --push).
Docker authentication works automatically out of the box. It uses the same Docker libraries to infer the location of the credentials on the system and optionally invoke any necessary credentials store helper to decrypt them.
All you have to do as a user is issue the command
docker login --username <username>
Docker can use various credential helpers to automatically generate and use credentials on your behalf. These are usually created by cloud providers to allow Docker to authenticate using the cloud providers own credentials.
You can see examples of configuring Docker to use these, and working with Earthly here: