You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: Using git credential helpers in CI examples #8989
Some users have been encountering issues when trying out out Git credential helpers in CI
I am moving the conversation to its own issue @pspurlock, and cleaning up the other (everything was screenshotted)
After discussing with @nipuna-perera, they do manage to make it work ; It seems to be a configuration issue / patterns to use, which shall become a standard.
I have a working implementation in a gitlab-ci.yml:
image: docker:latestservices:
- name: docker:${DOCKER_VERSION}-dindalias: dockervariables:
DOCKER_HOST: tcp://docker:2376DOCKER_TLS_VERIFY: '1'DOCKER_TLS_CERTDIR: '/certs'DOCKER_CERT_PATH: '/certs/client'DOCKER_DRIVER: overlay2DOCKER_VERSION: '24.0.6'GIT_USERNAME: "grouville"GIT_TOKEN: "${PAT}"stages:
- builddagger_job:
stage: buildbefore_script:
# Install required packages
- apk add --no-cache git curl# Install Dagger
- curl -L https://dl.dagger.io/dagger/install.sh | sh
- mv bin/dagger /usr/local/bin
- chmod +x /usr/local/bin/dagger# Configure Git credentials with improved script
- | cat > /tmp/git-credential-helper.sh << 'EOF' #!/bin/sh case "$1" in get) if [ -n "$GIT_USERNAME" ] && [ -n "$GIT_TOKEN" ]; then echo "username=$GIT_USERNAME" echo "password=$GIT_TOKEN" fi ;; store) # Don't store credentials ;; erase) # Don't need to erase credentials ;; esac exit 0 EOF
- chmod +x /tmp/git-credential-helper.sh# Configure git with the helper and additional settings
- git config --global credential."https://github.com".helper "/tmp/git-credential-helper.sh"
- git config --global credential."https://github.com".useHttpPath truescript:
# Run Dagger commands
- dagger -m github.com/grouville/daggerverse-private/zip functions# Graceful shutdown for cache
- | if docker ps --filter name="dagger-engine-*" -q; then docker stop -t 300 $(docker ps --filter name="dagger-engine-*" -q) fi
Just add the PAT secret as an env var and replace the dagger command as well as the username
Here, everything is in-memory, so pretty safe. We could also extend to several other providers by adding many credential helpers and with such command:
@grouville Thanks for doing this. I can't try out your example fully because dind requires privileged mode for the runner which we don't allow. However, I did try to mimic it as much as possible and still get the same access denied error.
For context, we have a gitlab runner deployed alongside a dagger engine/deamon in a cluster. When we run a CI Job, we then use _EXPERIMENTAL_DAGGER_RUNNER_HOST so that the CI Job will connect and use the daemon running in the cluster. So when dagger -m mymodule call ... is ran, which git credential context is being used here? The one running in the CI Job that is running the dagger call command, or the host we are connecting to?
I have tried to add credentials in both places and neither have worked, but it would help to clarify. I know it isn't a credential issue because I can run the same credential helper commands and then git clone successfully before the dagger command fails.
Thanks a ton for your quick response/feedback on this.
Mmmh, weird 😢 i'd be happy to sync with you to debug that live
Normally, the source of truth is always the CLI, so the one running in the CI Job that is running the dagger call command. I'll try with the _EXPERIMENTAL_DAGGER_RUNNER_HOST, if there's a bug, but I don't think so.
I have tried to add credentials in both places and neither have worked, but it would help to clarify. I know it isn't a credential issue because I can run the same credential helper commands and then git clone successfully before the dagger command fails.
If you make the same behavior as I did above, basically setting your own credential helper, if you add a step that actually prints it:
- script:
# this should print user and pat -- please ensure that
- /tmp/git-credential-helper.sh get # Run Dagger command
- dagger -m github.com/grouville/daggerverse-private/zip functions
@grouville Thanks for doing this. I can't try out your example fully because dind requires privileged mode for the runner which we don't allow. However, I did try to mimic it as much as possible and still get the same access denied error.
For context, we have a gitlab runner deployed alongside a dagger engine/deamon in a cluster. When we run a CI Job, we then use _EXPERIMENTAL_DAGGER_RUNNER_HOST so that the CI Job will connect and use the daemon running in the cluster. So when dagger -m mymodule call ... is ran, which git credential context is being used here? The one running in the CI Job that is running the dagger call command, or the host we are connecting to?
I have tried to add credentials in both places and neither have worked, but it would help to clarify. I know it isn't a credential issue because I can run the same credential helper commands and then git clone successfully before the dagger command fails.
Thanks a ton for your quick response/feedback on this.
Ok, could you please share what your gitconfig looks like ? Even privately, it would help. Are you using a proxy ? Git is a beast, and maybe there's other config interfering in this git cli ? does the clone work directly inside the runner too ?
Basically, I want to ensure that you don't have a .gitconfig conflicting here:
#!/bin/bashset -e
# Function to show all git configshow_git_config() {
echo"Active Git Config:"
git config --list
}
# Backup original configs
OLD_GIT_CONFIG_GLOBAL=$GIT_CONFIG_GLOBAL
OLD_GIT_CONFIG_SYSTEM=$GIT_CONFIG_SYSTEM# Get credentials
creds=$(echo -e "host=github.com\nprotocol=https"| git credential fill)
username=$(echo "$creds"| grep "username="| cut -d= -f2)
password=$(echo "$creds"| grep "password="| cut -d= -f2)# Show what configs would be used normallyecho"=== Before isolation ==="
show_git_config
# Run isolated commandecho -e "\n=== Running isolated command ===\n"
GIT_CONFIG_GLOBAL=/dev/null \
GIT_CONFIG_SYSTEM=/dev/null \
git -c credential.helper= \
-c core.sshCommand=/bin/false \
-c http.sslVerify=false \
ls-remote https://${username}:${password}@github.com/username/repo.git HEAD
# Show that no configs were usedecho -e "\n=== During isolation (should be empty) ==="
GIT_CONFIG_GLOBAL=/dev/null \
GIT_CONFIG_SYSTEM=/dev/null \
git config --list
# Restore original configsexport GIT_CONFIG_GLOBAL=$OLD_GIT_CONFIG_GLOBALexport GIT_CONFIG_SYSTEM=$OLD_GIT_CONFIG_SYSTEM
And, are you using the http ref ? (prefer to double check)
Don't hesitate to DM me on Discord (#guillaume_derouville)
What the dagger engine does is: retrieving from the host where the CLI is located the credentials via the git credential helpers. Under the hood, it does: echo "host=github.com\nprotocol=https\n" | git credential fill to retrieve the credentials and passing it to our git. It does not have the gitconfig context, so this might be the conflicting part.
Could you please try to have a git run without any config and see if it still works ? Above scripts tries to do that
Ok I got it! It wasn't a git-config issue, it WAS a token issue, I just don't know why:
dagger test:
extends: .daggerstage: testvariables:
GIT_USERNAME: gitlab-ci-tokenscript:
- | cat > /tmp/git-credential-helper.sh << 'EOF' #!/bin/sh case "$1" in get) if [ -n "$GIT_USERNAME" ]; then echo "protocol=https" echo "username=$GIT_USERNAME" echo "password=$CI_JOB_TOKEN" fi ;; store) # Don't store credentials ;; erase) # Don't need to erase credentials ;; esac exit 0 EOF
- chmod +x /tmp/git-credential-helper.sh
- git clone https://myproject.com.git || true
- git config --system credential."https://myproject.com".helper "/tmp/git-credential-helper.sh"
- echo -e "host=myproject.com\nprotocol=https\n" | git credential fill
- git clone https://myproject.com.git
- dagger -v -m https://myproject.com/ruff call lint -h
The git clones before the dagger calls are my sanity checks -- first clone before the config (to make sure it fails as it should), then one after to make sure it passes after my git config is changed.
Scenario 2 - Use $TEST_DAGGER_TOKEN -- A var I created with a PAT from our private dagger module repo.
Same as above, except this time Dagger also works successfully! So the only change being made is the token, but the token not working for dagger DOES work when doing a git clone.
If I had to guess, maybe Dagger is making a call that CI_JOB_TOKEN doesn't have access to? It is limited in scope so it does NOT have full API access. reference
Thanks again for sticking with me, you guys are awesome.
Reacted by Guillaume de Rouville, Miranda Carter, Manuel Leonhardt and Sebastian Fritsch
Ok I got it! It wasn't a git-config issue, it WAS a token issue, I just don't know why:
Thanks for everything 🙏 I would be interested to know what permissions are required though. If at some point you have the time to explore it that would be awesome 👼
is it possble to configure this at global level something similar git config --global url."https://gitlab-ci-token:[email protected]/".insteadOf "https://gitlab.com/"
is it possble to configure this at global level something similar git config --global url."https://gitlab-ci-token:[email protected]/".insteadOf "https://gitlab.com/"
Hi @abhibacheti, your command rewrites the url to pass the command via the ref ; we currently do not support that, as we just rely on the git credential helper to get the token and pass it as a header in the git query ; However, this would potentially be unlocked with: #9007
The CI_JOB_TOKEN can only be used as a password in the remote URL, e.gg https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.example.com/...
Alternatively, the job token can be passed in the request using any of these methods:
Unlike PATs, CI_JOB_TOKEN do not work with an authorisation header (which explains why PATs work while CI_JOB_TOKEN don’t), which however is what happens in the above function:
Even when a user calls the module with dagger call -m https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.my.company/my-module.git, Dagger appears to remove the credentials from the remote URL and set them as an auth header instead, i.e. gs.auth contains [-c http.https://gitlab.my.company/my-module.git.extraheader=Authorization: basic [redacted]] as a result.
I managed to access a private Dagger module after replacing the above line with a similar configuration like the Bitbucket Cloud Git one from the same function.
Potential solutions might include:
Preserve the username/password in the remote URL when explicitly provided by the user
Apply one of the above methods when the token starts with glcbt-
Preserve the username/password in the remote URL when explicitly provided by the user
Something to keep in mind is when you do this currently dagger will print out your credentials in its pod logs if running daemon on a different host like in a cluster.
Let me correct my earlier statement. The issue isn't that CI_JOB_TOKEN is being passed as an auth header (git/libcurl does this internally anyway). Rather, the problem is that GitLab doesn't accept the hard-coded username x-access-token:
While PATs, PrATs and GrATs allow any non-blank value as a username, CI_JOB_TOKEN requires gitlab-ci-token for the username (although I had issues using a PrAT with Dagger as a workaround as well, maybe I'm still missing something). Here a working example:
A solution would be to preserve the username from the user's credential helper and/or the remote URL (For GitLab CI, using https://gitlab-ci-token:${CI_JOB_TOKEN}@... is more convenient and common than setting up a git credential helper)
I think preserving the username when explicitly specified makes sense - we should only auto populate it if it wasn't directly specified. cc @grouville
I would like to avoid a general solution where we put the credentials into the URL - as mentioned above, this appears in logs, in the cache, etc - this could then leak the token, allowing undesired external API access while the token was valid.
I would like to avoid a general solution where we put the credentials into the URL - as mentioned above, this appears in logs, in the cache, etc - this could then leak the token, allowing undesired external API access while the token was valid.
That's fine, given the concern @pspurlock raised. Nevertheless, you would only need to keep the credentials in the remote URL until they're transformed into an auth header, i.e. they could be removed at the earliest possible point in code. However, they could still leak before then. In my logs, both Dagger (https://xxxxx@...) and GitLab CI (https://gitlab-ci-token:[MASKED]@...) have masked the credentials so far, but your results may vary. I haven't checked the daemon logs yet.
I strongly recommend adding an example to the docs demonstrating Dagger's solution, since GitLab CI users are familiar with https://gitlab-ci-token:${CI_JOB_TOKEN}@... - this is GitLab's recommended solution that appears throughout their documentation. Perhaps Dagger could also display a warning when users include credentials in a URL.
While several solutions have been proposed here using a custom credential helper script, I prefer keeping pipeline scripts concise for better readability. Here's a shorter approach; haven't tested though; but what do you think? Any concerns with using the cache helper?
...
.dagger...before_script:
- ...# Store the credentials in memory for the duration of the job
- git config --global credential."${CI_SERVER_URL}".helper "cache --timeout=${CI_JOB_TIMEOUT}"
- |- git credential approve << EOT url=${CI_SERVER_URL} username=gitlab-ci-token password=${CI_JOB_TOKEN} EOTscript:
- dagger call ...
Thank you for digging the root cause, I was falling short on time 🙏
We already retrieve the username, so totally doable -- it means that users will always have to specify the username, for every provider. If well documented in our docs, would that be ok ? x-access-token for all the other CI providers, gitlab-ci-token for gitlab
Regarding your pipeline example, I really like it ; smoother indeed.
Regarding the use of the cache git config --global credential."${CI_SERVER_URL}".helper "cache --timeout=${CI_JOB_TIMEOUT}", no objection on my end, this is totally valid
I narrowed it down to just using the .git-credential file since the helper store will ultimately do this anyway. Nice and tidy and ofc its wiped after every ci run:
We already retrieve the username, so totally doable -- it means that users will always have to specify the username, for every provider. If well documented in our docs, would that be ok ? x-access-token for all the other CI providers, gitlab-ci-token for gitlab
In my experience, users of private repositories are accustomed to specifying both username and token. If the following line from the documentation represents the intended goal, then I would expect Dagger to use whatever username that the user specified:
If this works, Dagger will be able to use the same credentials to access your private repositories.
I cannot tell for other CI provider, however for Gitlab CI, I would recommend using gitlab-ci-token and CI_JOB_TOKEN in the docs.
I narrowed it down to just using the .git-credential file since the helper store will ultimately do this anyway.
Be careful when using the store helper and .git-credentials in the $HOME directory. When using runner executors other than Docker or Kubernetes, storing credentials outside of the job's workspace may cause unexpected side effects (especially when allowing concurrent jobs on the same machine). Additionally, AFAIK GitLab CI would not clean up this file after a run (at least not until the next run on the same machine). If one would still want to use the store helper, I would probability set up a file CI/CD variable GIT_CREDENTIALS (ensure to have expand variable reference enabled) with the following value https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_FQDN}/ and then use it like this:
File CI/CD variables are guaranteed to be cleaned up after a run. An additional benefit is that users can securely store credentials for multiple Git hosts in a single location. If defined at as a group variable the same credentials can be use for multiple projects.
I also removed the --global in this example to avoid modifying the .gitconfig in the user's HOME directory for the reasons mentioned above. I'm hoping that Dagger can still receive the git credential helper config from the local config.
Update on this issue: v0.16.0/v0.16.1 seems to has broken the above workarounds for using private repos on GitLab. While I'm still trying to set up a minimal reproducible example, I can confirm that accessing modules in private repos worked with Project Access Tokens or Group Access Tokens in v0.15.4, but no longer works in v0.16.0 and later versions. I get the following error:
Stderr:
╭─ Error ──────────────────────────────────────────────────────────────────────╮
│ Failed to convert result to primitive values: unknown error (failed to get │
│ generated context directory: select: failed to generate code: failed to call │
│ sdk module codegen: select: failed to add client resources from ID: failed │
│ to add secret from source client iy4n56jwts31zcnpg86h7qxgh: secret │
│ xxh3:6ca97b9b155b5cf7 not found in other store) │
╰──────────────────────────────────────────────────────────────────────────────╯
I want to bring attention back to this issue, as it is currently blocking from effectively using modules on GitLab due to the incorrectly hard-coded username used for HTTPS authentication being incompatible with CI_JOB_TOKENs.
Should we split the "HTTPS with GitLab not working with CI_JOB_TOKEN" or "Dagger not respecting username for HTTPS auth" into a separate issue? The initial intent, as the title suggests, was to provide examples in the docs. However, the discussion revealed an issue with the hard-coded username that prevents us from using Dagger modules as intended.
Is there any chance we can have this fixed in one of the next releases? Can we somehow contribute?
I want to bring attention back to this issue, as it is currently blocking from effectively using modules on GitLab due to the incorrectly hard-coded username used for HTTPS authentication being incompatible with CI_JOB_TOKENs.
Should we split the "HTTPS with GitLab not working with CI_JOB_TOKEN" or "Dagger not respecting username for HTTPS auth" into a separate issue? The initial intent, as the title suggests, was to provide examples in the docs. However, the discussion revealed an issue with the hard-coded username that prevents us from using Dagger modules as intended.
Is there any chance we can have this fixed in one of the next releases? Can we somehow contribute?
Hey @skycaptain, thanks for the ping. Taking a look 👀
Activity
grouville commentedon Nov 18, 2024
hey @pspurlock
I have a working implementation in a
gitlab-ci.yml:Just add the PAT secret as an env var and replace the dagger command as well as the username
Here, everything is in-memory, so pretty safe. We could also extend to several other providers by adding many credential helpers and with such command:
cc @vikram-dagger, where shall i document those examples ?
vikram-dagger commentedon Nov 19, 2024
https://docs.dagger.io/integrations/gitlab would work - thanks for creating this example :)
pspurlock commentedon Nov 19, 2024
@grouville Thanks for doing this. I can't try out your example fully because dind requires privileged mode for the runner which we don't allow. However, I did try to mimic it as much as possible and still get the same access denied error.
For context, we have a gitlab runner deployed alongside a dagger engine/deamon in a cluster. When we run a CI Job, we then use
_EXPERIMENTAL_DAGGER_RUNNER_HOSTso that the CI Job will connect and use the daemon running in the cluster. So whendagger -m mymodule call ...is ran, which git credential context is being used here? The one running in the CI Job that is running the dagger call command, or the host we are connecting to?I have tried to add credentials in both places and neither have worked, but it would help to clarify. I know it isn't a credential issue because I can run the same credential helper commands and then
git clonesuccessfully before the dagger command fails.Thanks a ton for your quick response/feedback on this.
grouville commentedon Nov 19, 2024
Mmmh, weird 😢 i'd be happy to sync with you to debug that live
Normally, the source of truth is always the CLI, so the one running in the CI Job that is running the dagger call command. I'll try with the
_EXPERIMENTAL_DAGGER_RUNNER_HOST, if there's a bug, but I don't think so.grouville commentedon Nov 19, 2024
If you make the same behavior as I did above, basically setting your own credential helper, if you add a step that actually prints it:
grouville commentedon Nov 19, 2024
Ok, could you please share what your gitconfig looks like ? Even privately, it would help. Are you using a proxy ? Git is a beast, and maybe there's other config interfering in this git cli ? does the clone work directly inside the runner too ?
Basically, I want to ensure that you don't have a
.gitconfigconflicting here:And, are you using the http ref ? (prefer to double check)
Don't hesitate to DM me on Discord (
#guillaume_derouville)What the dagger engine does is: retrieving from the host where the CLI is located the credentials via the git credential helpers. Under the hood, it does:
echo "host=github.com\nprotocol=https\n" | git credential fillto retrieve the credentials and passing it to our git. It does not have the gitconfig context, so this might be the conflicting part.Could you please try to have a git run without any config and see if it still works ? Above scripts tries to do that
nipuna-perera commentedon Nov 19, 2024
FWIW, This is what we do. I've tested this to work on our Jenkins runners.
It's basically doing the helper function inline.
pspurlock commentedon Nov 19, 2024
Ok I got it! It wasn't a git-config issue, it WAS a token issue, I just don't know why:
The git clones before the dagger calls are my sanity checks -- first clone before the config (to make sure it fails as it should), then one after to make sure it passes after my git config is changed.
Scenario 1 - Use
$CI_JOB_TOKEN1st git clone fails, 2nd git clone works. That's what I'd expect. Dagger, however fails.
Scenario 2 - Use
$TEST_DAGGER_TOKEN-- A var I created with a PAT from our private dagger module repo.Same as above, except this time Dagger also works successfully! So the only change being made is the token, but the token not working for dagger DOES work when doing a git clone.
If I had to guess, maybe Dagger is making a call that
CI_JOB_TOKENdoesn't have access to? It is limited in scope so it does NOT have full API access. referenceThanks again for sticking with me, you guys are awesome.
grouville commentedon Nov 19, 2024
Thanks for everything 🙏 I would be interested to know what permissions are required though. If at some point you have the time to explore it that would be awesome 👼
abhibacheti commentedon Dec 1, 2024
is it possble to configure this at global level something similar
git config --global url."https://gitlab-ci-token:[email protected]/".insteadOf "https://gitlab.com/"grouville commentedon Dec 3, 2024
Hi @abhibacheti, your command rewrites the url to pass the command via the ref ; we currently do not support that, as we just rely on the git credential helper to get the token and pass it as a header in the git query ; However, this would potentially be unlocked with: #9007
skycaptain commentedon Dec 4, 2024
I encountered the same issue today. After debugging, I found that the issue lies within this line:
dagger/engine/sources/gitdns/source.go
Line 275 in 7efce52
The
CI_JOB_TOKENcan only be used as a password in the remote URL, e.gghttps://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.example.com/...Alternatively, the job token can be passed in the request using any of these methods:
--form "token=$CI_JOB_TOKEN"--header "JOB-TOKEN: $CI_JOB_TOKEN"--data "job_token=$CI_JOB_TOKEN"See https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#to-git-clone-a-private-projects-repository for reference.
Unlike PATs,
CI_JOB_TOKENdo not work with an authorisation header (which explains why PATs work whileCI_JOB_TOKENdon’t), which however is what happens in the above function:Even when a user calls the module with
dagger call -m https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.my.company/my-module.git, Dagger appears to remove the credentials from the remote URL and set them as an auth header instead, i.e.gs.authcontains[-c http.https://gitlab.my.company/my-module.git.extraheader=Authorization: basic [redacted]]as a result.I managed to access a private Dagger module after replacing the above line with a similar configuration like the Bitbucket Cloud Git one from the same function.
Potential solutions might include:
glcbt-pspurlock commentedon Dec 4, 2024
Something to keep in mind is when you do this currently dagger will print out your credentials in its pod logs if running daemon on a different host like in a cluster.
skycaptain commentedon Dec 5, 2024
Let me correct my earlier statement. The issue isn't that
CI_JOB_TOKENis being passed as an auth header (git/libcurl does this internally anyway). Rather, the problem is that GitLab doesn't accept the hard-coded usernamex-access-token:dagger/engine/sources/gitdns/source.go
Line 271 in 7efce52
While PATs, PrATs and GrATs allow any non-blank value as a username,
CI_JOB_TOKENrequiresgitlab-ci-tokenfor the username (although I had issues using a PrAT with Dagger as a workaround as well, maybe I'm still missing something). Here a working example:$ git clone -c http.extraHeader="Authorization: Basic $(echo -n gitlab-ci-token:$CI_JOB_TOKEN | base64)" https://gitlab.my.company/my-module.gitWhile this doesn't work:
git clone -c http.extraHeader="Authorization: Basic $(echo -n x-token-auth:$CI_JOB_TOKEN | base64)" https://gitlab.my.company/my-module.gitA solution would be to preserve the username from the user's credential helper and/or the remote URL (For GitLab CI, using
https://gitlab-ci-token:${CI_JOB_TOKEN}@...is more convenient and common than setting up a git credential helper)jedevc commentedon Dec 5, 2024
I think preserving the username when explicitly specified makes sense - we should only auto populate it if it wasn't directly specified. cc @grouville
I would like to avoid a general solution where we put the credentials into the URL - as mentioned above, this appears in logs, in the cache, etc - this could then leak the token, allowing undesired external API access while the token was valid.
skycaptain commentedon Dec 5, 2024
That's fine, given the concern @pspurlock raised. Nevertheless, you would only need to keep the credentials in the remote URL until they're transformed into an auth header, i.e. they could be removed at the earliest possible point in code. However, they could still leak before then. In my logs, both Dagger (
https://xxxxx@...) and GitLab CI (https://gitlab-ci-token:[MASKED]@...) have masked the credentials so far, but your results may vary. I haven't checked the daemon logs yet.I strongly recommend adding an example to the docs demonstrating Dagger's solution, since GitLab CI users are familiar with
https://gitlab-ci-token:${CI_JOB_TOKEN}@...- this is GitLab's recommended solution that appears throughout their documentation. Perhaps Dagger could also display a warning when users include credentials in a URL.While several solutions have been proposed here using a custom credential helper script, I prefer keeping pipeline scripts concise for better readability. Here's a shorter approach; haven't tested though; but what do you think? Any concerns with using the cache helper?
grouville commentedon Dec 5, 2024
Hi @skycaptain 👋
Thank you for digging the root cause, I was falling short on time 🙏
We already retrieve the username, so totally doable -- it means that users will always have to specify the
username, for every provider. If well documented in our docs, would that be ok ?x-access-tokenfor all the other CI providers,gitlab-ci-tokenfor gitlabRegarding your
pipeline example, I really like it ; smoother indeed.Regarding the use of the cache
git config --global credential."${CI_SERVER_URL}".helper "cache --timeout=${CI_JOB_TIMEOUT}", no objection on my end, this is totally validpspurlock commentedon Dec 5, 2024
I narrowed it down to just using the .git-credential file since the helper store will ultimately do this anyway. Nice and tidy and ofc its wiped after every ci run:
skycaptain commentedon Dec 6, 2024
In my experience, users of private repositories are accustomed to specifying both username and token. If the following line from the documentation represents the intended goal, then I would expect Dagger to use whatever username that the user specified:
dagger/docs/current_docs/api/remote-modules.mdx
Line 60 in 1881475
I cannot tell for other CI provider, however for Gitlab CI, I would recommend using
gitlab-ci-tokenandCI_JOB_TOKENin the docs.Be careful when using the store helper and
.git-credentialsin the $HOME directory. When using runner executors other than Docker or Kubernetes, storing credentials outside of the job's workspace may cause unexpected side effects (especially when allowing concurrent jobs on the same machine). Additionally, AFAIK GitLab CI would not clean up this file after a run (at least not until the next run on the same machine). If one would still want to use the store helper, I would probability set up a file CI/CD variableGIT_CREDENTIALS(ensure to have expand variable reference enabled) with the following valuehttps://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_FQDN}/and then use it like this:File CI/CD variables are guaranteed to be cleaned up after a run. An additional benefit is that users can securely store credentials for multiple Git hosts in a single location. If defined at as a group variable the same credentials can be use for multiple projects.
I also removed the
--globalin this example to avoid modifying the.gitconfigin the user's HOME directory for the reasons mentioned above. I'm hoping that Dagger can still receive the git credential helper config from the local config.docs: add authentication and best practices for GitHub and GitLab int…
docs: add git credential helpers guide
docs: update git credential helper anchor links
docs: update remote-modules.mdx with CI credentials and token usernames
skycaptain commentedon Feb 22, 2025
Update on this issue: v0.16.0/v0.16.1 seems to has broken the above workarounds for using private repos on GitLab. While I'm still trying to set up a minimal reproducible example, I can confirm that accessing modules in private repos worked with Project Access Tokens or Group Access Tokens in v0.15.4, but no longer works in v0.16.0 and later versions. I get the following error:
nipuna-perera commentedon Feb 22, 2025
Thread on Discord if anyone wants to follow there. https://discord.com/channels/707636530424053791/1336068640168218756
skycaptain commentedon Mar 25, 2025
I want to bring attention back to this issue, as it is currently blocking from effectively using modules on GitLab due to the incorrectly hard-coded username used for HTTPS authentication being incompatible with CI_JOB_TOKENs.
Should we split the "HTTPS with GitLab not working with CI_JOB_TOKEN" or "Dagger not respecting username for HTTPS auth" into a separate issue? The initial intent, as the title suggests, was to provide examples in the docs. However, the discussion revealed an issue with the hard-coded username that prevents us from using Dagger modules as intended.
Is there any chance we can have this fixed in one of the next releases? Can we somehow contribute?
grouville commentedon Mar 27, 2025
Hey @skycaptain, thanks for the ping. Taking a look 👀