Skip to content

Conversation

@megatnt1122
Copy link
Collaborator

@megatnt1122 megatnt1122 commented Nov 13, 2025

Ticket

#1522

Description

Logging improvements to authz_router

Tasks

  • - A description of the PR has been provided, and a diagram included if it is a new feature.
  • - Formatter has been run
  • - CHANGELOG comment has been added
  • - Labels have been assigned to the pr
  • - A reviwer has been added
  • - A user has been assigned to work on the pr
  • - If new feature a unit test has been added

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:

  • Integrate structured request logging into authz_router for gridftp, perm/check, and perm/get routes, capturing start, success, and failure events
  • Refactor client and result variable declarations and introduce a basePath constant to support consistent log metadata

Tests:

  • Add unit tests for perm/check and perm/get endpoints, covering successful authorization checks and error cases

JoshuaSBrown and others added 30 commits January 13, 2025 22:52
* 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
…ollection-endpoint-browse

Revert "[DLT-1110] Mapped Collection Endpoint Browse (1/4)"
megatnt1122 and others added 13 commits October 28, 2025 09:14
…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>
@megatnt1122 megatnt1122 self-assigned this Nov 13, 2025
@megatnt1122 megatnt1122 added Component: Database Relates to database microservice / data model Type: Refactor Imlplementation change, same functionality Priority: Low Lower priority work. labels Nov 13, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 13, 2025

Reviewer's Guide

This 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 endpoint

sequenceDiagram
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
Loading

Sequence diagram for logging in /perm/check endpoint

sequenceDiagram
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
Loading

Sequence diagram for logging in /perm/get endpoint

sequenceDiagram
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
Loading

Class diagram for new logger usage in authz_router

classDiagram
class Logger {
  +logRequestStarted(params)
  +logRequestSuccess(params)
  +logRequestFailure(params)
}
class Router {
  +get(path, handler)
}
Router --> Logger: uses
Loading

File-Level Changes

Change Details Files
Added structured logging to authz_router routes
  • Imported the logger module and defined a basePath variable
  • Moved client declaration outside try blocks to enable reuse
  • Instrumented each endpoint with logRequestStarted, logRequestSuccess, and logRequestFailure calls capturing client, correlationId, HTTP verb, route path, status, description, extra metadata, and errors
core/database/foxx/api/authz_router.js
Extended unit tests for perm endpoints
  • Added tests for /perm/check confirming granted=true for valid scenarios
  • Added tests for /perm/get covering successful permission retrieval and output type
  • Added a failure test for /perm/get with an invalid id parameter
core/database/foxx/tests/authz_router.test.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 119 to 131
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,
});
Copy link
Contributor

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.

Suggested change
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,
},
});

Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown left a 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.

@megatnt1122 megatnt1122 deleted the refactor-DAPS-1522-Authz-Router-Logging-Improvements branch November 24, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Database Relates to database microservice / data model Priority: Low Lower priority work. Type: Refactor Imlplementation change, same functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants