Skip to content

update to fully disable auth #10

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

Closed
wants to merge 2 commits into from
Closed

update to fully disable auth #10

wants to merge 2 commits into from

Conversation

cholmes
Copy link
Member

@cholmes cholmes commented May 23, 2025

Hey, not sure if this is the right approach, it's just what cursor gave to me. But if I just set the config.yaml file to 'auth_disabled: true' then it still was requiring auth. The readme said you can disable authentication by editing the app/core/auth.py, but I wasn't sure what to do to disable there. So perhaps this just could be a readme fix to explain how to disable the authentication there. But this seemed to work, and uses the config yaml file to disable it.

@cholmes cholmes requested a review from Copilot May 23, 2025 22:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the authentication mechanism to allow for disabling auth via the config.yaml file. The changes include:

  • Modifying the security scheme initialization to conditionally disable auto error handling based on configuration.
  • Adjusting the verify_auth dependency to manually raise an error when credentials are absent and auth is enabled.

# Create two security schemes:
# 1. When auth is enabled: Required bearer token
# 2. When auth is disabled: Optional bearer token
security = HTTPBearer(auto_error=not get_settings().auth_disabled)
Copy link
Preview

Copilot AI May 23, 2025

Choose a reason for hiding this comment

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

Initializing the HTTPBearer instance at module import using get_settings() may capture stale configuration if the settings are updated at runtime. Consider instantiating HTTPBearer within a dependency function or another runtime context to ensure it uses the latest configuration.

Suggested change
security = HTTPBearer(auto_error=not get_settings().auth_disabled)
def get_security() -> HTTPBearer:
"""
Dynamically create an HTTPBearer instance based on the current configuration.
"""
return HTTPBearer(auto_error=not get_settings().auth_disabled)

Copilot uses AI. Check for mistakes.

@m-mohr
Copy link
Collaborator

m-mohr commented May 26, 2025

Oh, I didn't see this before I started fixing it myself today.
The way it works now, is that it doesn't disable auth, but accepts a dummy Bearer token, which for example could be:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJndWVzdCIsIm5hbWUiOiJHdWVzdCIsImlhdCI6MTc0ODIxNzYwMCwiZXhwaXJlcyI6OTk5OTk5OTk5OX0.lJIkuuSdE7ihufZwWtLx10D_93ygWUcUrtKhvlh6M8k
The important part is that the sub in the JWT ist set to "guest".

@m-mohr m-mohr closed this May 26, 2025
@cholmes
Copy link
Member Author

cholmes commented May 27, 2025

Ok cool, will try it out.

@cholmes
Copy link
Member Author

cholmes commented May 27, 2025

Ok, didn't get so far.

The important part is that the sub in the JWT ist set to "guest".

What does this mean? Sorry for the complete naivety, I've not worked with JWT's much at all, and have always struggled to get bearer tokens to work.

I tried setting auth_disabled: true and changing secret_key to be the long string in the comment. And then I tried:

% http GET http://0.0.0.0:8000/projects --auth-type bearer --auth eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJndWVzdCIsIm5hbWUiOiJHdWVzdCIsImlhdCI6MTc0ODIxNzYwMCwiZXhwaXJlcyI6OTk5OTk5OTk5OX0.lJIkuuSdE7ihufZwWtLx10D_93ygWUcUrtKhvlh6M8k

HTTP/1.1 401 Unauthorized
content-length: 47
content-type: application/json
date: Tue, 27 May 2025 03:36:32 GMT
server: uvicorn
www-authenticate: Bearer

{
    "detail": "Invalid authentication credentials"
}

And I'm also not sure what I do if authorization is not disabled? Like where am I supposed to get the token to then make the subsequent requests?

thanks!

@m-mohr
Copy link
Collaborator

m-mohr commented May 27, 2025

I guess I should add more documentation around this.

For your attempt, you were not meant to change secret_key. Keep it as is and just use the long cryptic string as Bearer token. That should work.

"Authentication enabled" pretty much doesn't work right now as we didn't decide on an auth mechanism yet, so there's no endpoint for it yet. We could use OIDC or a custom HTTP Basic based implementation...

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.

2 participants