Loading
fix(df): show the block reason where the package manager fails
What does this MR do and why?
Relates to https://gitlab.com/gitlab-org/cli/-/work_items/8740
When glab df blocked a package, Maven printed status code: 403, reason phrase: Forbidden (403), and the reason only appeared in the summary after Maven exited. A Beta customer read that as a registry or network problem.
- For HTTPS registries, the 403 status line now carries the reason:
403 Blocked by GitLab Dependency Firewall: <reason>. Maven, Gradle and pip print it in their own error line. - glab also prints
dependency firewall blocked <package> <version>: <reason>to standard error when it blocks a package, once per package. - When the policy check itself fails, the 403 status line and body say
Dependency Firewall could not evaluate this package, and no extra line is printed. The raw API error stays out of the package manager's output; the summary and CI log keep it. - The reason comes from the policy, so it is flattened to one line (no header injection) and capped at 512 bytes. The body keeps the full text.
- Help text and docs no longer say
403 Forbidden.
Not in this change
- The rule name: the evaluate API returns only the policy name in
reason(enforcement_service.rb:208). Needs an API change, tracked in #8740. - How to request an exception: that belongs in the user documentation, not in the CLI output.
- Plain
http://registries:net/httpalways writesForbidden. The stderr line and body still carry the reason. glab df go: its own module proxy, no stderr line.goalready prints the reason from that proxy's body.- The job-level proxy (
glab df job-proxy) gets the reason in the 403 status line, but no stderr line: its output goes to the daemon log, not the build log. - Non-ASCII policy names come out garbled in the status line (Maven and Gradle decode it as ISO-8859-1). The stderr line is correct.
- npm prints the reason twice (status line, then JSON body).
How to set up and validate locally
CI proof, glab built from main and from this MR: https://gitlab.com/gl-demo-premium-hbaker/maven-testing-ground/-/pipelines/3074425832 (passed). Maven and Gradle use the real "Test control - block log4j-core 2.14.1" policy, pip uses the fake one, and the failed-check jobs use a rejected token.
| job | main |
this MR |
|---|---|---|
| maven-blocked | Forbidden, no line |
reason in the 403, line printed |
| gradle-blocked | Forbidden, no line |
reason in the 403, line printed |
| pip-blocked | Forbidden, no line |
reason in the 403, line printed |
| maven-check-failed | Forbidden |
could not evaluate this package, no line |
| npm-check-failed | API URL in the npm error | could not evaluate this package, no URL |
| maven-allowed | resolves, exit 0 | resolves, exit 0 |
Tests
proxy/block_test.go: status line with a reason, without one, header injection, the 512-byte cap, and a failed check.proxy/proxy_test.goandproxy/plain_test.go: the notice once per package, without a reason, on one line, none for warnings, the uninspectable-request path, and a failed check (cached failure and checker error, tunnel and plain HTTP) keeping the API error out of the status line, body and stderr.pm/pm_test.go: the notice reaches standard error throughpm.Run.- Each new test fails on
main; removing any guard alone fails a test (12 mutants). go test ./internal/dependencyfirewall/... ./internal/commands/df/...andgolangci-lintare clean.
Edited by Hannah Baker