bingquanzhao opened a new pull request, #71350: URL: https://github.com/apache/doris/pull/71350
### Background The Beats Doris output plugin (`extension/beats`, docs: https://doris.apache.org/docs/dev/ecosystem/beats) ships events from Elastic Beats (Filebeat, Metricbeat, etc.) to Apache Doris via HTTP Stream Load `PUT` requests. During client initialization, it logs the configured hosts, Stream Load endpoint URL, and `clientSettings` (including request headers assembled from `user`/`password` and custom `headers:`). ### What problem does this PR solve? Issue Number: None Related PR: #71346 (sibling fix for Logstash Doris output plugin), #36355 (introduced `clientSettings.String()` and `client.String()` header logging) PR Type: Bugfix Problem Summary: `clientSettings.String()` and `client.String()` in `extension/beats/doris/client.go` previously redacted only the exact case-sensitive `"Authorization"` key via `strings.Replace(..., 1)`, leaving custom sensitive headers (such as lowercase `authorization`, `token`, `Auth-Token`, `Proxy-Authorization`, `Cookie`, or `Set-Cookie`) exposed in plaintext in startup `INFO` logs (`Received settings: ...`). In addition, `doris.go` and `client.go` logged raw `host` and `urlPrefix` strings directly, which would expose embedded passwords if a user configured URLs like `http://user:password@fe:8030`. This PR introduces `sanitizeHeaders` (case-insensitive map redaction to `***MASKED***`) and `sanitizeURL` (URL userinfo redaction), applies them at all startup/stringer log sites without touching outbound HTTP headers, and adds Go unit tests covering these paths. After upgrading, all sensitive headers and embedded URL passwords are redacted in logs while Stream Load authentication remains unchange d. ### Details - **Frequency:** On plugin startup (`makeDoris` / `NewDorisClient`) whenever custom sensitive headers (e.g., `token`, lowercase `authorization`, `Auth-Token`, `Proxy-Authorization`, `Cookie`) are configured under `headers:`, or whenever `http_hosts`/`fenodes` embeds credentials in the URL. - **Root cause:** `clientSettings.String()` and `client.String()` checked only `Headers["Authorization"]` with a single `strings.Replace`, and `doris.go` logged `host` and `urlPrefix` verbatim. - **Why existing tests missed it:** Existing tests in `extension/beats/doris/common_test.go` tested table selection, worker count, and multi-table publishing, with no tests asserting log/stringer redaction of headers or URLs. - **Fix:** Added `isSensitiveHeader`, `sanitizeHeaders`, and `sanitizeURL` in `extension/beats/doris/utils.go` (aligning the sensitive header set and `***MASKED***` placeholder with Doris FE's `LoadAction#isSensitiveHeader` and Logstash PR #71346); updated `clientSettings.String()` and `client.String()` in `extension/beats/doris/client.go` and host/endpoint logs in `extension/beats/doris/doris.go`; added unit tests in `extension/beats/doris/sanitize_test.go`. - **Other paths and branches:** Audited all logger calls across `extension/beats/doris/`. Per-request `logRequest` only dumps the HTTP response (`httputil.DumpResponse`) rather than request headers, and `createHeaders()` already allocates a fresh map without mutating `config.Headers`. - **Behavior change:** Sensitive headers (including `Authorization`, `Proxy-Authorization`, `Cookie`, `Set-Cookie`, `token`, and `Auth-Token`, case-insensitively) are now logged as `***MASKED***` (previously `"Authorization"` was logged as `Basic ******` and other sensitive headers were unmasked), and embedded URL passwords are redacted in logs; actual outbound HTTP requests are unchanged. ### Testing Ran locally via Docker (`golang:1.22`) against `extension/beats`: - `gofmt -l doris/utils.go doris/client.go doris/doris.go doris/sanitize_test.go` — clean (no formatting diffs). - `go vet ./doris/...` — clean on all modified and added files (only pre-existing warning in untouched `doris/doris_integration_test.go:242`). - `go test -vet=off -v -run 'TestSelector|TestWorkers|TestMultiTable|TestSanitize|TestClientAndSettingsStringMasksSensitiveInfo' ./doris/...` — 7/7 tests passed (`TestSelector`, `TestSelectorWithDefaultTable`, `TestWorkers`, `TestMultiTable`, `TestSanitizeHeaders`, `TestSanitizeURL`, `TestClientAndSettingsStringMasksSensitiveInfo`). `TestSanitizeURL` also caught and verified a fix for malformed URLs containing `://` where `parseURL` previously prepended a second `http://`. ### Release note Mask sensitive HTTP headers (case-insensitively, including `Authorization`, `Proxy-Authorization`, `Cookie`, `Set-Cookie`, `token`, and `Auth-Token`) as `***MASKED***` and redact embedded URL credentials in Beats Doris output plugin logs. ### Check List (For Author) - Behavior changed: Yes (see Details) - Does this need documentation: No - Pre-submission status: Ready ### AI Disclosure - Tool: Antigravity (Gemini) - Generated: Code fix, unit tests, and this PR description. - Human review: Reviewed the leak scenarios, requested the Beats hardening fix, and directed pushing and opening this 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]
