ephraimbuddy commented on code in PR #75917:
URL: https://github.com/apache/airflow/pull/75917#discussion_r4455369441
##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -344,6 +365,12 @@ def _token_credential_env(self) -> Generator[None]:
"AIRFLOW_GIT_USER": self.user_name,
"AIRFLOW_GIT_TOKEN": self.auth_token,
}
+ # A public repository answers anonymous requests, so git never
gets the 401 that makes
+ # it send the token, and the fetch counts against the server's
anonymous rate limit.
+ if str(self.repo_url).startswith("https://") and
_is_proactive_auth_supported():
Review Comment:
This changes behaviour for existing connections. Today a public repo never
sees the token, so an expired or revoked token goes unnoticed. With proactive
auth the server rejects it, and the bundle stops syncing.
Repro with git 2.50, the same helper shape the hook writes, and a bogus
token against a public repo:
```
proactiveAuth=none -> GET info/refs, no Authorization -> 200, ls-remote OK
proactiveAuth=basic -> GET info/refs + Authorization -> 401
remote: Invalid username or token. Password authentication is not
supported for Git operations.
fatal: Authentication failed for
'https://github.com/apache/airflow-site.git/'
```
At minimum this needs a `.. warning::` in
`providers/git/docs/changelog.rst`, like the 1.0.0 entry for the
credential-helper change. It also needs a per-connection opt-out (for example a
`proactive_auth` extra), or it should default to off. Someone hitting the 401
shouldn't have to downgrade the provider or delete the token to recover.
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @ephraimbuddy before posting
##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -37,6 +38,26 @@
log = logging.getLogger(__name__)
+@cache
+def _is_proactive_auth_supported() -> bool:
Review Comment:
Is the version probe needed? git ignores config variables it doesn't
recognise, so on git older than 2.46 `http.<url>.proactiveAuth` does nothing
and behaviour is unchanged.
As written, the probe spawns `git version` in each process. It then logs a
WARNING once per process on any older git (bookworm ships 2.39, Ubuntu 24.04
ships 2.43). That includes every task process that builds a `GitDagBundle`, and
private-repo users, for whom the message doesn't apply.
I'd drop it and note the 2.46 requirement in the class docstring, which
still lists only the 2.31 requirement, and in the changelog. If you want to
keep a signal, log at `debug`. Removing it also lets the autouse fixture and
the version tests go.
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @ephraimbuddy before posting
##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -344,6 +365,12 @@ def _token_credential_env(self) -> Generator[None]:
"AIRFLOW_GIT_USER": self.user_name,
"AIRFLOW_GIT_TOKEN": self.auth_token,
}
+ # A public repository answers anonymous requests, so git never
gets the 401 that makes
+ # it send the token, and the fetch counts against the server's
anonymous rate limit.
Review Comment:
Nit: proactive auth is scoped to the repo URL, while the helper is scoped to
the host, so submodules on the same host still go anonymous first. That seems
like the right choice. Could the comment say it's deliberate, so nobody widens
it to `scope` later?
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @ephraimbuddy before posting
##########
providers/git/src/airflow/providers/git/hooks/git.py:
##########
@@ -344,6 +365,12 @@ def _token_credential_env(self) -> Generator[None]:
"AIRFLOW_GIT_USER": self.user_name,
"AIRFLOW_GIT_TOKEN": self.auth_token,
}
+ # A public repository answers anonymous requests, so git never
gets the 401 that makes
+ # it send the token, and the fetch counts against the server's
anonymous rate limit.
+ if str(self.repo_url).startswith("https://") and
_is_proactive_auth_supported():
+ values["GIT_CONFIG_COUNT"] = str(index + 3)
Review Comment:
Changing `GIT_CONFIG_COUNT` after the dict is built splits the index
arithmetic across two places, and the next entry (e.g. #74938) has to touch
both. Consider collecting the pairs and deriving the count once:
```python
config = [
(f"credential.{scope}.helper", ""),
(f"credential.{scope}.helper", "!" + shlex.quote(helper_path)),
]
if scope.startswith("https://"):
config.append((f"http.{self.repo_url}.proactiveAuth", "basic"))
values = {"GIT_CONFIG_COUNT": str(index + len(config)), ...}
for offset, (key, value) in enumerate(config, start=index):
values[f"GIT_CONFIG_KEY_{offset}"] = key
values[f"GIT_CONFIG_VALUE_{offset}"] = value
```
`scope` already carries the scheme, so there's no need to re-check
`str(self.repo_url)`.
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @ephraimbuddy before posting
##########
providers/git/tests/unit/git/hooks/test_git.py:
##########
@@ -781,6 +855,76 @@ def
test_token_credential_env_skipped_for_ssh_transport(self, create_connection_
assert "GIT_CONFIG_COUNT" not in hook.env
assert "AIRFLOW_GIT_TOKEN" not in hook.env
+ @pytest.mark.parametrize(
+ ("url", "supported", "expected_count", "expected_key"),
+ [
+ pytest.param(AIRFLOW_HTTPS_URL, True, "3",
f"http.{AIRFLOW_HTTPS_URL}.proactiveAuth", id="https"),
+ pytest.param(AIRFLOW_HTTPS_URL, False, "2", None,
id="git-older-than-2.46"),
+ pytest.param(AIRFLOW_HTTP_URL, True, "2", None, id="plain-http"),
+ ],
+ )
+ def test_proactive_auth_config(
+ self,
+ url,
+ supported,
+ expected_count,
+ expected_key,
+ proactive_auth_supported,
+ create_connection_without_db,
+ ):
+ proactive_auth_supported.return_value = supported
+ create_connection_without_db(
+ Connection(conn_id="git_proactive_auth", host=url,
password=ACCESS_TOKEN, conn_type="git")
+ )
+ hook = GitHook(git_conn_id="git_proactive_auth")
+
+ with hook.configure_hook_env():
+ assert hook.env["GIT_CONFIG_COUNT"] == expected_count
+ assert hook.env.get("GIT_CONFIG_KEY_2") == expected_key
+ assert hook.env.get("GIT_CONFIG_VALUE_2") == ("basic" if
expected_key else None)
+
+ @pytest.mark.skipif(Git().version_info < (2, 46),
reason="http.proactiveAuth needs git 2.46+")
+ def test_token_reaches_a_public_repository_without_a_challenge(
+ self, proactive_auth_supported, create_connection_without_db, tmp_path
+ ):
+ proactive_auth_supported.return_value = True
+ with recording_public_https_git_server(tmp_path) as (port, received,
cert_file):
+ url = f"https://127.0.0.1:{port}/repo.git"
+ create_connection_without_db(
+ Connection(
+ conn_id="git_public_repo",
+ host=url,
+ login="token_user",
+ password=ACCESS_TOKEN,
+ conn_type="git",
+ )
+ )
+ hook = GitHook(git_conn_id="git_public_repo")
+
+ with hook.configure_hook_env():
+ git_ls_remote(url, {**hook.env, "GIT_SSL_CAINFO":
str(cert_file)})
+
+ assert set(received) == {f"token_user:{ACCESS_TOKEN}"}
+
+ @pytest.mark.parametrize(
+ ("version_info", "side_effect", "expected"),
+ [
+ pytest.param((2, 46, 0), None, True, id="2.46"),
+ pytest.param((2, 51, 2), None, True, id="2.51"),
+ pytest.param((2, 45, 4), None, False, id="2.45"),
+ pytest.param((), GitCommandNotFound("git", "not found"), False,
id="unknown"),
Review Comment:
(Only relevant if the version check stays.) In GitPython, `git version` runs
when `version_info` is accessed, not in `Git()`, so this case raises from a
point the real code never fails at. Something like
`type(mock_git.return_value).version_info = mock.PropertyMock(side_effect=...)`
would match the real failure point. The `ValueError` branch isn't covered
either.
---
Drafted-by: Claude Code (Opus 5.5); reviewed by @ephraimbuddy before posting
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]