-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin) Add authorization provider in snuba admin (#2301)
The admin relies on a proxy to perform authentication and authorization. This is not great for two reasons: it would by default allow everybody if the proxy was misconfigured while failing open (blocking everybody) would be safer. it does not allow to decide which features to show depending on roles. This adds an abstraction to performa authorization before each server request on the admin UI. This abstraction has multiple implementations for multiple authorization providers. The default is NOOP and allows everything through. The next to be implemented is IAP, then we can add one for basic HTTP auth useful on prem.
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Callable | ||
|
||
from snuba import settings | ||
|
||
|
||
class UnauthorizedException(Exception): | ||
pass | ||
|
||
|
||
auth_provider = Callable[[], str] | ||
|
||
# This function takes the Flask request and authorizes it. | ||
# If the request is valid it would return the user id. | ||
# If not it will raise UnauthorizedException | ||
# | ||
# TODO: provide a more structured representation of the User that | ||
# includes the role at least. | ||
def authorize_request() -> str: | ||
provider_id = settings.ADMIN_AUTH_PROVIDER | ||
provider = AUTH_PROVIDERS.get(provider_id) | ||
if provider is None: | ||
raise ValueError("Invalid authorization provider") | ||
return provider() | ||
|
||
|
||
def passthrough_authorize() -> str: | ||
return "unknown" | ||
|
||
|
||
def iap_authorize() -> str: | ||
raise NotImplementedError | ||
|
||
|
||
AUTH_PROVIDERS = { | ||
"NOOP": passthrough_authorize, | ||
"IAP": iap_authorize, | ||
} |
This file contains 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
This file contains 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