feat(#11967): Enable API access token requirement configuration#11977
Open
purvanshjoshi wants to merge 5 commits intocBioPortal:masterfrom
Open
feat(#11967): Enable API access token requirement configuration#11977purvanshjoshi wants to merge 5 commits intocBioPortal:masterfrom
purvanshjoshi wants to merge 5 commits intocBioPortal:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements a first pass at making API access-token usage configurable and enforceable, and adds supporting infrastructure for test performance (remote ClickHouse) and release/testing documentation.
Changes:
- Adds
api.access.token.requiredwiring into the API security filter chain and token authentication filter. - Introduces basic MDC enrichment for token-authenticated users (
user,auth_method). - Adds an option to run ClickHouse tests against a remote “frozen” database and documents the workflow.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/test/java/org/cbioportal/infrastructure/repository/clickhouse/AbstractTestcontainers.java |
Allows bypassing Testcontainers ClickHouse in favor of remote ClickHouse via system properties. |
src/main/java/org/cbioportal/application/security/token/TokenAuthenticationFilter.java |
Adds “token required” behavior and MDC population on successful token auth. |
src/main/java/org/cbioportal/application/security/config/ApiSecurityConfig.java |
Injects api.access.token.required and passes it into the token filter DSL/filter construction. |
docs/development/Release-Procedure.md |
Documents updating the frozen ClickHouse test DB during releases that change ClickHouse schema/data. |
docs/Testing.md |
Documents how to run tests against a remote frozen ClickHouse database. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/test/java/org/cbioportal/infrastructure/repository/clickhouse/AbstractTestcontainers.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cbioportal/application/security/token/TokenAuthenticationFilter.java
Show resolved
Hide resolved
src/main/java/org/cbioportal/application/security/token/TokenAuthenticationFilter.java
Show resolved
Hide resolved
src/main/java/org/cbioportal/application/security/token/TokenAuthenticationFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/org/cbioportal/application/security/config/ApiSecurityConfig.java
Show resolved
Hide resolved
6620e5d to
8383195
Compare
f4c7bc6 to
a705ee0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #11967
Context & Motivation
As discussed in #11967, we aim to improve the visibility and tracking of API usage across cBioPortal instances. Currently, many API endpoints can be accessed without authentication (depending on methods), making it difficult to attribute high-volume requests to specific users or analyze usage patterns.
This PR implements the foundational configuration and enforcement logic to require API access tokens for requests to
/api/**. It also introduces basic User Identity logging, setting the stage for further enhancements (Datadog integration) to be implemented in collaboration with @Annu881.Describe changes proposed in this pull request:
1. Configuration (ApiSecurityConfig.java)
api.access.token.required(default:false).application.propertieswithout affecting existing deployments that rely on the default behavior.2. Enforcement Logic (TokenAuthenticationFilter.java)
accessTokenRequiredflag.true: If the flag is enabled and a request to a protected endpoint lacks anAuthorizationheader, the filter now returnstrue. This triggers the authentication attempt, which will subsequently fail (throwingBadCredentialsExceptionor similar) and result in a401 Unauthorizedresponse, effectively blocking unauthenticated access.false: Retains existing behavior (only attempts authentication if a token header is present).3. User Identity Logging (TokenAuthenticationFilter.java)
user: The authenticated username (e.g., email or user ID).auth_method: Set to"token".Collaboration
Checks
Any screenshots or GIFs?
N/A (Backend configuration change)
Notify reviewers
@dippindots @Annu881