Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plain-credentials</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.jenkinsci.plugins.gitclient.cgit.GitCommandsExecutor;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.framework.io.WriterOutputStream;

Expand Down Expand Up @@ -2150,6 +2151,15 @@ private String launchCommandWithCredentials(
env = new EnvVars(env);
env.put("GIT_ASKPASS", askpass.toAbsolutePath().toString());
env.put("SSH_ASKPASS", askpass.toAbsolutePath().toString());

} else if (credentials instanceof StringCredentials) {
var stringCred = (StringCredentials) credentials;
listener.getLogger().println("using GIT_CONFIG to set token header " + stringCred.getDescription());

env = new EnvVars(env);
env.put("GIT_CONFIG_COUNT", "0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for a nice use of the environment variables provided by newer versions of command line git. Unfortunately, this won't work on the following Linux systems because they deliver a command line git version that is older than 2.31:

  • Debian 10 (command line git 2.20) - end of life 30 Jun 2024
  • Debian 11 (command line git 2.30) - end of life 30 Jun 2026
  • Ubuntu 20.04 (command line git 2.25) - end of life 2 Apr 2025

They don't have the ability to process those environment variables.

Would you be willing to investigate support for those older versions of command line git?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some in investigation on that and unfortunately i think there is no proper way to configure it.

  1. Pass the header via git -c ... => token could be red by other processes (e.g. ps)
  2. Create a git config file and save the configuration in there. This is probably very error-prone and can lead to conflicts with existing configurations

With this PR at least the new git versions would work currently this is working for non of them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KalleOlaviNiemitalo had another link to a conversation where it was advised to not use extra headers for authentication, but I can't find that page.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in actions/checkout#415 (comment) there is a mismatch in Git vs. Git LFS clients behaviors.

Git LFS in this case is behaving in a bug-for-bug compatible way with Git

Bitbucket and Azure implemented Personal Access Tokens that way and its currently not possible to use them at all.

env.put("GIT_CONFIG_KEY_0", "http.extraHeader");
env.put("GIT_CONFIG_VALUE_0", "Authorization: Bearer " + stringCred.getSecret());
}

if ("http".equalsIgnoreCase(url.getScheme()) || "https".equalsIgnoreCase(url.getScheme())) {
Expand Down