-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
306 additions
and
24 deletions.
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
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,44 @@ | ||
# Authentication mechanisms for HORAO | ||
|
||
There are 3 configurations that need to be applied, the first is peer authentication using a shared secret. | ||
The second and third are user authentication that need to be configured for regular users and administrators. | ||
Both users and administrators will need to use the same Open ID Connect provider. | ||
Basic information requested is only email, identification of administrators is done by the roles custom claim (so the OIDC provider needs to support this, and needs to be configured, like https://claims.idp.example.com/role). | ||
|
||
## Peer authentication | ||
All instances of `HORAO` that form one cluster need to be able to authenticate each other. This is done using a shared secret that is stored in the `.env` file. The shared secret is used to sign the messages that are exchanged between the instances. The shared secret is stored in the `.env` file as follows: | ||
```dotenv | ||
PEER_SECRET=abracadabra | ||
``` | ||
Peer synchronization is done using the `PEERS` environment variable. This is a comma separated list of peers that need to be synchronized. The peers are identified by their IP address. The `PEERS` environment variable is stored in the `.env` file as follows: | ||
```dotenv | ||
PEERS=10.0.0.1,some.host.somewhere | ||
``` | ||
These are comma separated values that are used to identify the peers that need to be synchronized. | ||
The synchronization happens over the 'synchronize' endpoint on the API. | ||
|
||
There is a 'PEER_STRICT' that defaults to 'True'. This means that the peers origin needs to be matched to the value supplied in the 'PEERS' environment variable. If 'PEER_STRICT' is set to 'False' then the origin of the peer is not checked. | ||
|
||
## Open ID Connect parts | ||
The following variables need to be set in the `.env` file: | ||
```dotenv | ||
OAUTH_NAME=openidc | ||
OAUTH_CLIENT_ID=client_id | ||
OAUTH_CLIENT_SECRET=client_secret | ||
OAUTH_SERVER_METADATA_URL=https://idp.example.com/.well-known/openid-configuration | ||
OAUTH_BASE_URL=https://idp.example.com | ||
OAUTH_AUTHORIZE_URL=https://idp.example.com/authorize | ||
OAUTH_AUTHORIZE_PARAMS={} | ||
OAUTH_ACCESS_TOKEN_URL=https://idp.example.com/token | ||
OAUTH_REQUEST_TOKEN_URL=None | ||
OAUTH_ROLE_URI=https://claims.idp.example.com/role | ||
``` | ||
The `OAUTH_CLIENT_ID` and `OAUTH_CLIENT_SECRET` are the client id and client secret that are provided by the Open ID Connect provider. | ||
|
||
### Administrators | ||
Administrators are identified by the roles custom claim. The roles custom claim is used to identify the administrators. The roles custom claim is stored in the `.env` file as follows: | ||
```dotenv | ||
ADMINISTRATOR_ROLE=administrator | ||
``` | ||
### Users | ||
If the roles custom claim is not present, or the user does not have the administrator role, then the user is considered a regular user. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# -*- coding: utf-8 -*-# | ||
"""API definitions.""" | ||
from horao.api.alive_controller import is_alive | ||
from .alive_controller import is_alive | ||
from .authenticate import login, logout | ||
from .synchronization import synchronize |
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,35 @@ | ||
import os | ||
|
||
from authlib.integrations.starlette_client import OAuth # type: ignore | ||
from starlette.requests import Request | ||
from starlette.responses import RedirectResponse | ||
|
||
|
||
async def login(request: Request): | ||
redirect_uri = request.url_for("auth") | ||
oauth_role_uri = os.getenv("OAUTH_ROLE_URI", "role") | ||
oauth_settings = { | ||
"name": os.getenv("OATH_NAME", "openidc"), | ||
"client_id": os.getenv("OAUTH_CLIENT_ID"), | ||
"client_secret": os.getenv("OAUTH_CLIENT_SECRET"), | ||
"server_metadata_url": os.getenv("OAUTH_SERVER_METADATA_URL", None), | ||
"api_base_url": os.getenv("OAUTH_API_BASE_URL", None), | ||
"authorize_url": os.getenv("OAUTH_AUTHORIZE_URL", None), | ||
"authorize_params": os.getenv("OAUTH_AUTHORIZE_PARAMS", None), | ||
"access_token_url": os.getenv("OAUTH_ACCESS_TOKEN_URL", None), | ||
"access_token_params": os.getenv("OAUTH_ACCESS_TOKEN_PARAMS", None), | ||
"request_token_url": os.getenv("OAUTH_REFRESH_TOKEN_URL", None), | ||
"request_token_params": os.getenv("OAUTH_REFRESH_TOKEN_PARAMS", None), | ||
"client_kwargs": os.getenv( | ||
"OAUTH_CLIENT_KWARGS", {"scope": f"openid email {oauth_role_uri}"} | ||
), | ||
} | ||
oauth = OAuth() | ||
filtered_settings = {k: v for k, v in oauth_settings.items() if v is not None} | ||
client = oauth.register(filtered_settings) | ||
return await client.authorize_redirect(request, redirect_uri) | ||
|
||
|
||
async def logout(request: Request): | ||
request.session.pop("user", None) | ||
return RedirectResponse(url="/") |
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
Oops, something went wrong.