-
Notifications
You must be signed in to change notification settings - Fork 16
[DAPS-1522] Authz Router Logging Improvements #1764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DAPS-1522] Authz Router Logging Improvements #1764
Conversation
Update nlhoman json version
* Add additional params to DatabaseAPI::userSetAccessToken to pass message with addtional info on to database API. * Add convenience method with old type signature of DatabaseAPI::userSetAccessToken for compatibility * Conditionally add other token options param when calling dbGetRaw. * Pass token type along to Database API. * Pass token type from message. * Extract logic for building URL from dbPost and dbGetRaw into separate function for easier testing and debugging * Extract url building logic from dbGet * Add some comments for moved code, address a TODO, add new TODO for AccessToken Message type field * Address default on token type, formatting * Add new AccessTokenType entries for a sentinel value and Globus default in SDMS.proto, use as desired in DatabaseAPI.cpp * Change query param to match backend changes * Restore formatting of SDMS.proto * Make built URL const where appropriate in DatabaseAPI.cpp and DatabaseAPI.hpp * Change default AccessTokenType for UserSetAccessTokenRequest in SDMS_Auth.proto. * Remove logging of potentially senitive data * Adjust AccessTokenType ACCESS_SENTINEL to have value of uint8 max. --------- Co-authored-by: Anthony Ramirez <[email protected]>
[DLT-1110] Add controller unit tests [DLT-1110] Remove debug [DLT-1110] Correct import statements, endpoint list [DLT-1110] Refactor out into MVC [DLT-1110] Add debug [DLT-1110] Functioning modal, needs refactoring [DLT-1110] Refactor dlg start transfer using OOO programming. Should be MVC cased on what I'm seeing but we'll see
…ransfer request when update or get
…ollection-endpoint-browse Revert "[DLT-1110] Mapped Collection Endpoint Browse (1/4)"
1209 feature add jsdoc linter
Co-authored-by: Anthony Ramirez <[email protected]>
Co-authored-by: Joshua S Brown <[email protected]> Co-authored-by: JoshuaSBrown <[email protected]>
…bus credentials for web service (#1731) Co-authored-by: Joshua S Brown <[email protected]> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: Joshua S Brown <[email protected]>
Reviewer's GuideThis PR integrates structured logging into the authz_router by importing a centralized logger, defining a basePath, hoisting client initialization, and instrumenting each endpoint with standardized logRequestStarted, logRequestSuccess, and logRequestFailure calls; it also enhances unit tests to cover the new perm/check and perm/get behaviors, including success and error cases. Sequence diagram for logging in /gridftp endpointsequenceDiagram
participant Client
participant Router
participant Logger
participant g_lib
Client->>Router: GET /gridftp
Router->>g_lib: getUserFromClientID(client)
Router->>Logger: logRequestStarted(...)
alt Success
Router->>g_lib: getUserFromClientID_noexcept(client)
Router->>Logger: logRequestSuccess(...)
else Failure
Router->>Logger: logRequestFailure(...)
end
Sequence diagram for logging in /perm/check endpointsequenceDiagram
participant Client
participant Router
participant Logger
participant g_lib
Client->>Router: GET /perm/check
Router->>g_lib: getUserFromClientID(client)
Router->>Logger: logRequestStarted(...)
alt Success
Router->>g_lib: resolveID(id, client)
Router->>Logger: logRequestSuccess(...)
else Failure
Router->>Logger: logRequestFailure(...)
end
Sequence diagram for logging in /perm/get endpointsequenceDiagram
participant Client
participant Router
participant Logger
participant g_lib
Client->>Router: GET /perm/get
Router->>g_lib: getUserFromClientID(client)
Router->>Logger: logRequestStarted(...)
alt Success
Router->>g_lib: resolveID(id, client)
Router->>Logger: logRequestSuccess(...)
else Failure
Router->>Logger: logRequestFailure(...)
end
Class diagram for new logger usage in authz_routerclassDiagram
class Logger {
+logRequestStarted(params)
+logRequestSuccess(params)
+logRequestFailure(params)
}
class Router {
+get(path, handler)
}
Router --> Logger: uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `core/database/foxx/api/authz_router.js:119-131` </location>
<code_context>
+ },
+ });
} catch (e) {
+ logger.logRequestFailure({
+ client: client?._id,
+ correlationId: req.headers["x-correlation-id"],
+ httpVerb: "GET",
+ routePath: basePath + "/gridftp",
+ status: "Failure",
+ description: "Checks authorization",
+ extra: {
+ id: client?._id,
+ is_admin: client?.is_admin,
+ },
+ error: e,
+ });
+
</code_context>
<issue_to_address>
**🚨 suggestion (security):** Failure logging may expose sensitive error details.
Sanitize or restrict the error information before logging to prevent exposure of sensitive data, especially if logs are accessible externally.
```suggestion
logger.logRequestFailure({
client: client?._id,
correlationId: req.headers["x-correlation-id"],
httpVerb: "GET",
routePath: basePath + "/gridftp",
status: "Failure",
description: "Checks authorization",
extra: {
id: client?._id,
is_admin: client?.is_admin,
},
error: {
message: typeof e === "object" && e !== null ? e.message : String(e),
name: typeof e === "object" && e !== null ? e.name : undefined,
},
});
```
</issue_to_address>
### Comment 2
<location> `core/database/foxx/api/authz_router.js:167` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Use `const` or `let` instead of `var`. ([`avoid-using-var`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-using-var))
<details><summary>Explanation</summary>`const` is preferred as it ensures you cannot reassign references (which can lead to buggy and confusing code).
`let` may be used if you need to reassign references - it's preferred to `var` because it is block- rather than
function-scoped.
From the [Airbnb JavaScript Style Guide](https://airbnb.io/javascript/#references--prefer-const)
</details>
</issue_to_address>
### Comment 3
<location> `core/database/foxx/api/authz_router.js:267` </location>
<code_context>
result = req.queryParams.perms ? req.queryParams.perms : permissions.PERM_ALL;
</code_context>
<issue_to_address>
**suggestion (code-quality):** Avoid unneeded ternary statements ([`simplify-ternary`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/simplify-ternary))
```suggestion
result = req.queryParams.perms || permissions.PERM_ALL;
```
<br/><details><summary>Explanation</summary>It is possible to simplify certain ternary statements into either use of an `||` or `!`.
This makes the code easier to read, since there is no conditional logic.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| logger.logRequestFailure({ | ||
| client: client?._id, | ||
| correlationId: req.headers["x-correlation-id"], | ||
| httpVerb: "GET", | ||
| routePath: basePath + "/gridftp", | ||
| status: "Failure", | ||
| description: "Checks authorization", | ||
| extra: { | ||
| id: client?._id, | ||
| is_admin: client?.is_admin, | ||
| }, | ||
| error: e, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 suggestion (security): Failure logging may expose sensitive error details.
Sanitize or restrict the error information before logging to prevent exposure of sensitive data, especially if logs are accessible externally.
| logger.logRequestFailure({ | |
| client: client?._id, | |
| correlationId: req.headers["x-correlation-id"], | |
| httpVerb: "GET", | |
| routePath: basePath + "/gridftp", | |
| status: "Failure", | |
| description: "Checks authorization", | |
| extra: { | |
| id: client?._id, | |
| is_admin: client?.is_admin, | |
| }, | |
| error: e, | |
| }); | |
| logger.logRequestFailure({ | |
| client: client?._id, | |
| correlationId: req.headers["x-correlation-id"], | |
| httpVerb: "GET", | |
| routePath: basePath + "/gridftp", | |
| status: "Failure", | |
| description: "Checks authorization", | |
| extra: { | |
| id: client?._id, | |
| is_admin: client?.is_admin, | |
| }, | |
| error: { | |
| message: typeof e === "object" && e !== null ? e.message : String(e), | |
| name: typeof e === "object" && e !== null ? e.name : undefined, | |
| }, | |
| }); |
JoshuaSBrown
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to talk about this file together, any existing console log statements either need to be removed, formatted using the same approach you have been using or combined.
Ticket
#1522
Description
Logging improvements to authz_router
Tasks
Summary by Sourcery
Improve observability of the authorization router by integrating structured request logging across its endpoints and enhance test coverage for permission-related routes
Enhancements:
Tests: