Skip to content

Commit 4815781

Browse files
dschoGit for Windows Build Agent
authored andcommitted
credential: advertise NTLM suppression and allow helpers to re-enable
The previous commits disabled NTLM authentication by default due to its cryptographic weaknesses. Users can re-enable it via the config setting http.<url>.allowNTLMAuth, but this requires manual intervention. Credential helpers may have knowledge about which servers are trusted for NTLM authentication (e.g., known on-prem Azure DevOps instances). To allow them to signal this trust, introduce a simple negotiation: when NTLM is suppressed and the server offered it, Git advertises ntlm=suppressed to the credential helper. The helper can respond with ntlm=allow to re-enable NTLM for this request. This happens precisely at the point where we would otherwise warn the user about NTLM being suppressed, ensuring the capability is only advertised when relevant. Helped-by: Matthew John Cheetham <mjcheetham@outlook.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent d9b8fcb commit 4815781

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

credential.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ int credential_read(struct credential *c, FILE *fp,
360360
credential_set_capability(&c->capa_authtype, op_type);
361361
else if (!strcmp(value, "state"))
362362
credential_set_capability(&c->capa_state, op_type);
363+
} else if (!strcmp(key, "ntlm")) {
364+
if (!strcmp(value, "allow"))
365+
c->ntlm_allow = 1;
363366
} else if (!strcmp(key, "continue")) {
364367
c->multistage = !!git_config_bool("continue", value);
365368
} else if (!strcmp(key, "password_expiry_utc")) {
@@ -420,6 +423,8 @@ void credential_write(const struct credential *c, FILE *fp,
420423
if (c->ephemeral)
421424
credential_write_item(c, fp, "ephemeral", "1", 0);
422425
}
426+
if (c->ntlm_suppressed)
427+
credential_write_item(c, fp, "ntlm", "suppressed", 0);
423428
credential_write_item(c, fp, "protocol", c->protocol, 1);
424429
credential_write_item(c, fp, "host", c->host, 1);
425430
credential_write_item(c, fp, "path", c->path, 0);

credential.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ struct credential {
177177
struct credential_capability capa_authtype;
178178
struct credential_capability capa_state;
179179

180+
unsigned ntlm_suppressed:1,
181+
ntlm_allow:1;
182+
180183
char *username;
181184
char *password;
182185
char *credential;

http.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ static void init_curl_http_auth(CURL *result)
661661

662662
credential_fill(the_repository, &http_auth, 1);
663663

664+
if (http_auth.ntlm_allow && !(http_auth_methods & CURLAUTH_NTLM)) {
665+
http_auth_methods |= CURLAUTH_NTLM;
666+
curl_easy_setopt(result, CURLOPT_HTTPAUTH, http_auth_methods);
667+
}
668+
664669
if (http_auth.password) {
665670
if (always_auth_proactively()) {
666671
/*
@@ -1908,6 +1913,8 @@ static int handle_curl_result(struct slot_results *results)
19081913
} else if (missing_target(results))
19091914
return HTTP_MISSING_TARGET;
19101915
else if (results->http_code == 401) {
1916+
http_auth.ntlm_suppressed = (results->auth_avail & CURLAUTH_NTLM) &&
1917+
!(http_auth_any & CURLAUTH_NTLM);
19111918
if ((http_auth.username && http_auth.password) ||\
19121919
(http_auth.authtype && http_auth.credential)) {
19131920
if (http_auth.multistage) {
@@ -1917,8 +1924,7 @@ static int handle_curl_result(struct slot_results *results)
19171924
credential_reject(the_repository, &http_auth);
19181925
if (always_auth_proactively())
19191926
http_proactive_auth = PROACTIVE_AUTH_NONE;
1920-
if ((results->auth_avail & CURLAUTH_NTLM) &&
1921-
!(http_auth_any & CURLAUTH_NTLM)) {
1927+
if (http_auth.ntlm_suppressed) {
19221928
warning(_("Due to its cryptographic weaknesses, "
19231929
"NTLM authentication has been\n"
19241930
"disabled in Git by default. You can "
@@ -2452,6 +2458,13 @@ static int http_request_recoverable(const char *url,
24522458
http_reauth_prepare(1);
24532459
}
24542460

2461+
/*
2462+
* Re-enable NTLM auth if the helper allows it and we would
2463+
* otherwise suppress authentication via NTLM.
2464+
*/
2465+
if (http_auth.ntlm_suppressed && http_auth.ntlm_allow)
2466+
http_auth_methods |= CURLAUTH_NTLM;
2467+
24552468
ret = http_request(url, result, target, options);
24562469
}
24572470
if (ret == HTTP_RATE_LIMITED) {

t/t5563-simple-http-auth.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,19 @@ test_expect_success NTLM 'access using NTLM auth' '
807807
test_must_fail env GIT_TRACE_CURL=1 git \
808808
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" 2>err &&
809809
test_grep "allowNTLMAuth" err &&
810+
811+
# Can be enabled via config
810812
GIT_TRACE_CURL=1 git -c http.$HTTPD_URL.allowNTLMAuth=true \
811-
ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
813+
ls-remote "$HTTPD_URL/ntlm_auth/repo.git" &&
814+
815+
# Or via credential helper responding with ntlm=allow
816+
set_credential_reply get <<-EOF &&
817+
username=user
818+
password=pwd
819+
ntlm=allow
820+
EOF
821+
822+
git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
812823
'
813824

814825
test_done

0 commit comments

Comments
 (0)