Skip to content

ENH: Add Authorization Based on API Keys#31

Merged
zdomke merged 15 commits intomainfrom
zdomke/key-auth
Mar 25, 2026
Merged

ENH: Add Authorization Based on API Keys#31
zdomke merged 15 commits intomainfrom
zdomke/key-auth

Conversation

@zdomke
Copy link
Copy Markdown
Contributor

@zdomke zdomke commented Feb 26, 2026

Description

Add dependencies for checking API Key authorization for all necessary endpoints. Check read access and write access as each is needed. Nearly all endpoints are covered with either read or write permissions. Below are the endpoints that are left open:

  • /
    • Returns basic API information (message, path to docs, path to health, version)
  • /health
    • Simply returns {"status": "healthy"} to signify the API is up
  • /v1/health/heartbeat
    • Returns basic API health info (time of last heartbeat, time that API has been alive)
  • /v1/api-keys/bootstrap
    • Self-sealing opening allows for generation of an initial API Key
    • Does not work if there are other active keys

Add special dependencies for checking API Key authorization for WebSockets. WebSockets handle headers differently and have different error code structures/codes.

Also I moved the Response Models for the /health route to their own file in app/schemas/health.py.

Motivation

Closes #21

Where Has This Been Documented?

Waiting on #22

Screenshots

OpenAPI docs showing auth is required for endpoints

Screenshot 2026-02-26 at 16 17 17

Pre-merge checklist

  • Code works interactively
  • Code contains descriptive docstrings
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions

@zdomke zdomke self-assigned this Feb 26, 2026
@zdomke zdomke marked this pull request as ready for review February 27, 2026 00:31
@zdomke zdomke requested review from a team and shaikhhasib February 27, 2026 00:31
@zdomke
Copy link
Copy Markdown
Contributor Author

zdomke commented Feb 27, 2026

Note that this branch is based on #29

@zdomke zdomke force-pushed the zdomke/key-auth branch 2 times, most recently from d6f1a45 to 90bec6f Compare March 24, 2026 17:59
Copy link
Copy Markdown
Contributor

@shilorigins shilorigins left a comment

Choose a reason for hiding this comment

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

All tests in test_dependencies.py are passing, but I'm getting test_api/test_api_keys.pyfailures for tests that passed in #29. Did you rerun the full suite?

@zdomke
Copy link
Copy Markdown
Contributor Author

zdomke commented Mar 25, 2026

All tests in test_dependencies.py are passing, but I'm getting test_api/test_api_keys.pyfailures for tests that passed in #29. Did you rerun the full suite?

Oh good catch. I should have noticed this.

What happened is that I had to wrap all of the api_key endpoints in these envelope objects (see 0bee7fb) so that the frontend & backend could interact. In doing this I forgot to update the tests themselves. I will update the tests now, knowing that both commits should be reverted when I work on slaclab/react-squirrel#77.

Base automatically changed from zdomke/api-keys to main March 25, 2026 20:40
Copy link
Copy Markdown
Contributor

@shilorigins shilorigins left a comment

Choose a reason for hiding this comment

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

Woohoo!

@zdomke zdomke merged commit 301c550 into main Mar 25, 2026
1 check passed
@zdomke zdomke deleted the zdomke/key-auth branch March 25, 2026 21:41
@zdomke zdomke restored the zdomke/key-auth branch March 25, 2026 23:03
@zdomke zdomke deleted the zdomke/key-auth branch March 26, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] - API Key Validation for API Access

2 participants