morningman opened a new pull request, #71105:
URL: https://github.com/apache/doris/pull/71105

   ### Background
   
   `enable_all_http_auth` decides whether the HTTP endpoints of FE (port 8030) 
and BE (port 8040) demand credentials. On master the FE flag is on by default 
and can only be changed in `fe.conf` (#66205); the BE flag is off by default. 
FE `/api/health` and `/metrics` skip the check (#60761), so the FE flag gates 
neither. On BE every handler goes through `HttpHandlerWithAuth`, so once the BE 
flag is on, `/api/health` needs credentials too.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #66205 (turned the FE flag on by default and kept FE `/metrics` 
public), #60761 (made FE `/api/health` and `/metrics` public; BE handlers of 
privilege type `NONE`, health included, still need credentials when the BE flag 
is on)
   PR Type: Enhancement
   
   Problem Summary:
   
   With the flag on, these two endpoints are the wrong way round. FE `/metrics` 
answers anyone who reaches 8030, and its labels carry user, job and compute 
group names; 8030 also serves Stream Load and the web UI, so a firewall cannot 
single the path out. A BE with the flag on answers Kubernetes probes on 
`/api/health` with 401, so its pods never turn ready. This PR leaves 
`/api/health` as the only endpoint the flag keeps open on either port: FE 
`/metrics` follows the FE flag and accepts any valid account, and BE 
`/api/health` stays public. After an upgrade, with the default config, 
anonymous scrapes of FE `/metrics` get 401 until the scraper sends HTTP basic 
auth.
   
   On a local FE with the default config (`enable_all_http_auth = true`), the 
same requests before and after:
   
   | Request | Before | After |
   |---|---|---|
   | `GET /metrics`, no credentials | 200, every metric, e.g. 
`doris_fe_query_total{user="root"} 10` | 401, `WWW-Authenticate: Basic 
realm="Restricted"`, body `Need auth information.` |
   | `GET /metrics`, wrong password | 200, every metric | 401, body `Access 
denied for user '[email protected]' (using password: YES)` |
   | `GET /metrics`, an account with no grants | 200 | 200 |
   | `GET /metrics?type=json` or `?type=core`, no credentials | 200 | 401 |
   | `GET /api/health`, no credentials | 200 | 200 |
   
   ### Details
   
   - **Change map:** 431 changed lines: production code +38 -13 in 4 files, 
tests +263 -16 in 13 files, docs +70 -31 in 2 files.
     1. FE `MetricsAction` follows the flag and answers a real 401 (+22 -3); 
the flag's description in `Config.java` (+10 -3).
     2. BE `HealthAction` becomes a plain `HttpHandler` (`health_action.h`, 
`http_service.cpp`, +6 -7).
     3. Tests: new FE `MetricsActionTest`, a new case in BE 
`http_auth_test.cpp`, `auth/test_http_api_auth` reversed for FE `/metrics` and 
extended to BE with its flag on, and 10 suites that scraped FE `/metrics` 
anonymously now pass FE credentials (1 or 2 lines each).
     4. Docs: `threat-model.md` records the decision as M20 and updates every 
section that listed FE `/metrics` as anonymous; one phrase in `SECURITY.md`.
   - **Before and after:** FE with the flag on: the table above; a rejected 
request gets a plain-text 401, not the HTTP 200 JSON envelope (`code: 401`) of 
the other FE REST endpoints. FE with the flag off: unchanged. BE with its flag 
on: `/api/health` answers without credentials, every other handler still needs 
them. BE with its flag off: unchanged.
   - **Configs and defaults:** None changed. FE `enable_all_http_auth` stays on 
by default and BE stays off; neither can change at runtime. No switch exempts 
`/metrics` alone: with the flag on, a scraper needs credentials.
   - **Impact on existing users:** Anonymous scrapers of FE `/metrics` get HTTP 
401 after the upgrade, also on clusters that already ran with the flag on 
(4.1.1 and later served `/metrics` anonymously whatever the flag said). Give 
the scraper an account with no privileges, for example via `basic_auth` in 
Prometheus; `enable_all_http_auth = false` in `fe.conf` is only a temporary 
fallback, since it opens the whole REST surface. With the BE flag on, probes of 
BE `/api/health` start to succeed.
   
   ### Testing
   
   - FE UT, run locally: new `MetricsActionTest` (no credentials, wrong 
password, account without privileges, flag off) and existing `HttpApiAuthTest` 
pass; with `MetricsAction` reverted to master, three of the four new cases fail.
   - A local FE built from this branch, default config: the table above. 
"Before" is the same build with only `MetricsAction.class` taken from master.
   - BE UT `HttpAuthTest.health_stays_public_when_all_http_auth_is_on`: serves 
`HealthAction` and `MetricsAction` on a real `EvHttpServer` with the flag on; 
expects 200 for anonymous `/api/health`, 401 for anonymous `/metrics`, 200 with 
credentials. Not run locally (no BE build here; the BE files were only compiled 
with `-fsyntax-only`); the BE UT pipeline runs it.
   - Regression suites: not run locally. Five are `docker` suites 
(`auth/test_http_api_auth` and four under `cloud_p0`), which run only where 
`excludeDockerTest` is false; `test_streaming_mysql_job_metrics` needs the 
external MySQL; the other five are regular P0 suites, which run with the FE 
flag at its default, on.
   
   ### Notes for Reviewers
   
   - A real 401 for `/metrics` only: scrapers judge a scrape by its HTTP 
status, and the JSON envelope is an HTTP 200 whose body is not in the 
exposition format, so a scraper could not tell a rejected scrape from a 
malformed one. The global `RestApiExceptionHandler` keeps the envelope, which 
the web UI relies on; the realm is the one BE already sends. Since the handler 
now catches the exception the global handler used to log, it logs the rejection 
at INFO itself.
   - Password only, as on branch-4.0: a scraper can run as an account with no 
privileges.
   - BE `HealthAction` is now a plain `HttpHandler`, like the Stream Load 
handlers. Letting privilege type `NONE` skip the check in 
`HttpHandlerWithAuth::on_header` would also have opened BE `/metrics`, which is 
`NONE` too.
   - The `FE.BLOCK_IMPORT_LOCK` debug point in `MetricsAction` now comes after 
the auth check; no test reaches it through `/metrics`.
   
   ### Release note
   
   With `enable_all_http_auth` on, the FE default, FE `/metrics` now requires 
HTTP basic auth credentials of any valid account (no privilege is needed) and 
answers HTTP 401 without them; configure the scraper with credentials, for 
example `basic_auth` in Prometheus. BE `/api/health` now answers without 
credentials even when `enable_all_http_auth = true` in `be.conf`, so Kubernetes 
probes keep working; every other BE endpoint still needs credentials.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes (doris-website: the 
`enable_all_http_auth` config page and the Prometheus monitoring guide need a 
`basic_auth` example; a doris-website PR will follow)
   - Pre-submission status: Partially verified: the new BE UT case and the 
updated regression suites have not run locally; the BE change was only compiled 
with -fsyntax-only
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, docs edits, this description
   - Human review: not stated
   - Prompts: The author asked for an analysis of Kubernetes probes failing 
when `enable_all_http_auth` is on, then asked whether master could make the 
flag cover every endpoint except health, decided that FE `/metrics` follows the 
flag with no separate switch to exempt it, and asked for the fix and a PR.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to