fix(cost-management): add structured audit logging with user identity - #2619
Conversation
Missing ChangesetsThe following package(s) are changed by this PR but do not have a changeset:
See CONTRIBUTING.md for more information about how to add changesets. Changed Packages
|
Review Summary by QodoAdd structured audit logging and secure server-side proxy with Apply Recommendation authorization
WalkthroughsDescription• Add structured audit logging with user identity across secure endpoints • Implement server-side secure proxy eliminating token exposure and RBAC bypass • Add authorization and validation for Apply Recommendation workflow execution • Move data fetching server-side with RBAC enforcement before API forwarding • Add confirmation dialog to prevent accidental workflow execution Diagramflowchart LR
A["Frontend Request"] -->|user-cookie| B["Backend Secure Proxy"]
B -->|authenticate| C["Backstage httpAuth"]
B -->|check permissions| D["Permission Framework"]
D -->|ros.* or cost.*| E["RBAC Decision"]
E -->|authorized clusters/projects| F["Strip Client Filters"]
F -->|inject server filters| G["Forward to Cost Management API"]
G -->|response| H["Return Filtered Data"]
H -->|audit log| I["Structured JSON Log"]
J["Apply Recommendation"] -->|POST| K["Backend Validation"]
K -->|check ros.apply| L["Permission Check"]
L -->|forward to Orchestrator| M["Workflow Execution"]
M -->|audit log| I
File Changes1. workspaces/cost-management/plugins/cost-management-backend/src/models/RouterOptions.ts
|
Code Review by Qodo
1.
|
610317b to
da03c34
Compare
- New auditLog utility resolves user identity via UserInfoService and emits structured JSON audit entries with actor, action, resource, decision, and filters - All endpoints now produce audit logs: secureProxy, /access, /access/cost-management, and /apply-recommendation - Inject coreServices.userInfo into the backend plugin Fixes: FLPATH-3490 Made-with: Cursor
Add logger.warn in resolveActor catch block so operators can detect and diagnose identity resolution failures instead of silently falling back to 'unknown' actor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50cb8ac to
d71b8c4
Compare
|
…edhat-developer#2616-redhat-developer#2620 - Remove outdated proxy config from workspace README (PR redhat-developer#2616 moved data fetching server-side) - Fix broken link typo in frontend plugin README - Update backend README: clarify mixed dot/slash permission format, add missing endpoints (access, apply-recommendation), add audit logging section (PR redhat-developer#2619) - Clarify permission name format in docs/rbac.md intro (dot for plugin-level, slash for cluster/project per PR redhat-developer#2620) - Update ADR 0002 status to Accepted with implementation notes documenting the backend gateway pattern (PRs redhat-developer#2616, redhat-developer#2618, redhat-developer#2619) Made-with: Cursor
…edhat-developer#2616-redhat-developer#2620 - Remove outdated proxy config from workspace README (PR redhat-developer#2616 moved data fetching server-side) - Fix broken link typo in frontend plugin README - Update backend README: clarify mixed dot/slash permission format, add missing endpoints (access, apply-recommendation), add audit logging section (PR redhat-developer#2619) - Clarify permission name format in docs/rbac.md intro (dot for plugin-level, slash for cluster/project per PR redhat-developer#2620) - Update ADR 0002 status to Accepted with implementation notes documenting the backend gateway pattern (PRs redhat-developer#2616, redhat-developer#2618, redhat-developer#2619) Made-with: Cursor
…2679) * docs(cost-management): update documentation to reflect security PRs #2616-#2620 - Remove outdated proxy config from workspace README (PR #2616 moved data fetching server-side) - Fix broken link typo in frontend plugin README - Update backend README: clarify mixed dot/slash permission format, add missing endpoints (access, apply-recommendation), add audit logging section (PR #2619) - Clarify permission name format in docs/rbac.md intro (dot for plugin-level, slash for cluster/project per PR #2620) - Update ADR 0002 status to Accepted with implementation notes documenting the backend gateway pattern (PRs #2616, #2618, #2619) Made-with: Cursor * docs(cost-management): address Qodo review findings - Fix inaccurate sanitization claim in ADR 0002: changed to "validated for presence and type" to match actual implementation - Remove non-existent `cost_access_check` audit action from backend README — the code emits `access_check` for both access endpoints Made-with: Cursor



Summary
Stacked on #2618 (which stacks on #2616) — review those PRs first. This PR adds commits on top.
Addresses FLPATH-3490 from the FLPATH-3503 security epic.
Problem
Data access events through the secure proxy and Apply Recommendation endpoint had no structured audit logging with user identity. Security teams need to be able to trace which user accessed which data, what RBAC decision was made, and what filters were applied.
Solution
Introduced structured audit logging across all secure backend endpoints:
resolveActor(req, options)— Resolves the authenticated user's entity ref (e.g.,user:default/admin) from the request via Backstage'sUserInfoService, falling back to'unknown'if resolution fails (with a warning log)emitAuditLog(options, entry)— Emits structured JSON log entries with standardized fieldsAudit log entry format
{ "audit": true, "actor": "user:default/admin", "action": "data_access", "resource": "recommendations/openshift", "decision": "ALLOW", "filters": { "clusters": ["cluster73"], "projects": ["rhdh"] } }Endpoints logged
GET /proxy/*(Optimizations)data_accessGET /proxy/*(OpenShift/Cost)data_accessPOST /apply-recommendationapply_recommendationGET /accessaccess_checkGET /access/cost-managementcost_access_checkChanges
src/util/auditLog.tswithresolveActorandemitAuditLogutilitiescoreServices.userInfointo the backend pluginuserInfotoRouterOptionsinterfacesecureProxy.ts,applyRecommendation.ts,access.ts,costManagementAccess.tsresolveActorandemitAuditLogTest plan
Unit tests
yarn tsc -b— clean compilation, zero errorsauditLog.test.ts— covers:resolveActorreturns entity ref fromUserInfoServiceresolveActorreturns'unknown'on failureemitAuditLogformats structured JSON with all fieldsemitAuditLogincludes optionalmetafieldCI
Deployment verification
2.0.3-rc.8)actorfield correctly resolves to the authenticated userQodo bot findings (addressed)