fix: log security warning when auth disabled and remove API key from 401 response#391
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #391 +/- ##
==========================================
+ Coverage 75.90% 76.50% +0.60%
==========================================
Files 145 146 +1
Lines 10626 10685 +59
==========================================
+ Hits 8066 8175 +109
+ Misses 2212 2169 -43
+ Partials 348 341 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7a49abc to
acc880f
Compare
…401 response When keyCfg is nil, CheckApiKey silently grants every request admin-level AnonymousUser access with no indication to operators. This change adds a prominent error-level log on every such request so operators can detect misconfigured deployments immediately from logs. Additionally, the 401 error response body previously echoed the submitted API key value back to the caller, aiding brute-force key validation. Replaced with a static 'Invalid API Key' message. Updated test expectations to reflect the new generic 401 message. Fixes openkruise#389
acc880f to
d736ac4
Compare
What
Two security hardening changes to
pkg/servers/e2b/routes.go:Log a security warning when authentication is disabled — when
keyCfgisnil, every request silently received admin-levelAnonymousUseraccess with no operator visibility. Now logs anError-level message on every request so misconfigured deployments are immediately detectable in logs/alerts.Stop echoing submitted API key in 401 responses — the previous error message
"Invalid API Key: <submitted-key>"reflected the caller's key back in the response body, aiding brute-force key validation. Replaced with the static message"Invalid API Key".Why
Changes
routes.go: Addklog.Errorwarning inCheckApiKeywhensc.keys == nilroutes.go: Replacefmt.Sprintf("Invalid API Key: %s", apiKey)with"Invalid API Key"routes_test.go: Update test expectations to match new generic 401 messageTesting
go test github.com/openkruise/agents/pkg/servers/e2b -run TestCheckApiKey✅go build ./pkg/servers/e2b/...✅Fixes #389