Skip to content

[MNT] Disable authentication by default#229

Merged
alyssadai merged 3 commits intomainfrom
disable-auth-by-default
Mar 4, 2026
Merged

[MNT] Disable authentication by default#229
alyssadai merged 3 commits intomainfrom
disable-auth-by-default

Conversation

@alyssadai
Copy link
Copy Markdown
Contributor

@alyssadai alyssadai commented Mar 4, 2026

Changes proposed in this pull request:

Checklist

This section is for the PR reviewer

  • PR has an interpretable title with a prefix ([ENH], [FIX], [REF], [TST], [CI], [MNT], [INF], [MODEL], [DOC]) (see our Contributing Guidelines for more info)
  • PR has a label for the release changelog or skip-release (to be applied by maintainers only)
  • PR links to GitHub issue with mention Closes #XXXX
  • Tests pass
  • Checks pass

For new features:

  • Tests have been added

For bug fixes:

  • There is at least one test that would fail under the original bug conditions.

Summary by Sourcery

Set API authentication to be disabled by default and clean up related tests.

Bug Fixes:

  • Ensure missing client ID does not cause errors when authentication is disabled by default.

Enhancements:

  • Change default authentication configuration to be disabled unless explicitly enabled via NB_ENABLE_AUTH.
  • Add a test to verify the default authentication and client ID settings.

Tests:

  • Add a test for default authentication settings and remove an obsolete warning filter from an existing security test.

@alyssadai alyssadai added release Create a release when this PR is merged pr-patch Incremental feature improvement, will increment patch version when merged (0.0.+1) labels Mar 4, 2026
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 4, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Default authentication behavior is changed to be disabled unless explicitly enabled via NB_ENABLE_AUTH, and tests are updated to validate the new defaults and remove an obsolete warning filter.

Flow diagram for NB_ENABLE_AUTH-based authentication toggle

flowchart TD
  A[Start_API_process] --> B[Read_environment_variable_NB_ENABLE_AUTH]
  B --> C{Is_NB_ENABLE_AUTH_set?}
  C -- No_unset --> D[Use_default_value_False]
  C -- Yes_set --> E[Convert_value_to_lowercase]
  D --> F[AUTH_ENABLED_is_False]
  E --> G{Value_equals_string_true?}
  G -- Yes --> H[AUTH_ENABLED_is_True]
  G -- No --> F

  subgraph Request_handling
    I[Incoming_API_request] --> J{AUTH_ENABLED_is_True?}
    J -- Yes --> K[Enforce_authentication_and_validate_token]
    J -- No --> L[Bypass_authentication_checks]
    K --> M[Return_response]
    L --> M
  end

  F --> I
  H --> I
Loading

File-Level Changes

Change Details Files
Change default authentication configuration to be opt-in via environment variable.
  • Update AUTH_ENABLED so that it defaults to False when NB_ENABLE_AUTH is unset or not explicitly set to 'true'.
  • Leave CLIENT_ID environment-based configuration unchanged.
  • Retain existing Auth0 JWKS URL and related constants without modification.
app/api/security.py
Extend security tests to cover new default auth behavior and clean up obsolete warning filter.
  • Add a test ensuring AUTH_ENABLED is False and CLIENT_ID is None by default, with a note about future robustness improvements.
  • Keep existing tests for behavior when auth is enabled and missing client ID, relying on fixtures/env overrides.
  • Remove a now-unnecessary pytest warning filter that suppressed unrelated startup warnings from a test.
tests/test_security.py

Assessment against linked issues

Issue Objective Addressed Explanation
#226 Set default value of internal variable AUTH_ENABLED to False when NB_ENABLE_AUTH environment variable is unset.

Possibly linked issues


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
Copy Markdown

@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.

We've reviewed this pull request using the Sourcery rules engine

Copy link
Copy Markdown
Contributor

@surchs surchs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alyssadai for the quick fix!

🧑‍🍳

Comment thread tests/test_security.py
Comment thread tests/test_security.py
@alyssadai alyssadai merged commit 623b581 into main Mar 4, 2026
10 checks passed
@alyssadai alyssadai deleted the disable-auth-by-default branch March 4, 2026 18:26
@neurobagel-bot
Copy link
Copy Markdown
Contributor

neurobagel-bot bot commented Mar 4, 2026

🚀 PR was released in v0.8.1 🚀

@neurobagel-bot neurobagel-bot bot added the released This issue/pull request has been released. label Mar 4, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.17%. Comparing base (2116354) to head (ebfce8c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   98.37%   98.17%   -0.20%     
==========================================
  Files          30       30              
  Lines         984      987       +3     
==========================================
+ Hits          968      969       +1     
- Misses         16       18       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-patch Incremental feature improvement, will increment patch version when merged (0.0.+1) release Create a release when this PR is merged released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change default value of NB_ENABLE_AUTH to False

2 participants