-
Notifications
You must be signed in to change notification settings - Fork 1
[DOP-21268] - integration with SSO (Keycloak) #123
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7f3f490
[DOP-21268] - refactor auth configuration settings (add providers)
e8dbb86
[DOP-21268] - implement KeycloakAuthProvider
3e36c68
[DOP-21268] - add docs
3febce0
[DOP-21268] - update User model
3747893
[DOP-21268] - split Settings to SyncmasterSettings, WorkerSettings(Sy…
c089d96
[DOP-21268] - update RTD config
772dc91
[DOP-21268] - make unified logging settings for worker and backend
a0b8f1f
[DOP-21268] - minor fixes
e1efdaa
[DOP-21268] - add KeycloakAuthProvider interaction schema
4748ad7
[DOP-21268] - add SessionSettings
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ build: | |
| - VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH python -m poetry install --no-root --all-extras --with docs --without dev,test | ||
| - VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH python -m poetry show -v | ||
| - python -m pip list -v | ||
| - SYNCMASTER__DATABASE__URL=postgresql+psycopg://fake:[email protected]:5432/fake SYNCMASTER__BROKER__URL=amqp://fake:faket@fake:5672/ python -m syncmaster.backend.export_openapi_schema docs/_static/openapi.json | ||
| - SYNCMASTER__DATABASE__URL=postgresql+psycopg://fake:[email protected]:5432/fake SYNCMASTER__SERVER__SESSION__SECRET_KEY=session_secret_key SYNCMASTER__BROKER__URL=amqp://fake:faket@fake:5672/ SYNCMASTER__CRYPTO_KEY=crypto_key SYNCMASTER__AUTH__ACCESS_TOKEN__SECRET_KEY=fakepython python -m syncmaster.backend.export_openapi_schema docs/_static/openapi.json | ||
|
|
||
| sphinx: | ||
| configuration: docs/conf.py | ||
This file contains hidden or 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 hidden or 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,10 @@ | ||
| .. _backend-auth-custom: | ||
|
|
||
| Custom Auth provider | ||
| ==================== | ||
|
|
||
| You can implement custom auth provider by inheriting from class below and implementing necessary methods. | ||
|
|
||
| .. autoclass:: syncmaster.backend.providers.auth.AuthProvider | ||
| :members: | ||
| :member-order: bysource |
This file contains hidden or 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,82 @@ | ||
| .. _backend-auth-dummy: | ||
|
|
||
| Dummy Auth provider | ||
| =================== | ||
|
|
||
| Description | ||
| ----------- | ||
|
|
||
| This auth provider allows to sign-in with any username and password, and and then issues an access token. | ||
|
|
||
| After successful auth, username is saved to backend database. It is then used for creating audit records for any object change, see ``changed_by`` field. | ||
|
|
||
| Interaction schema | ||
| ------------------ | ||
|
|
||
| .. dropdown:: Interaction schema | ||
|
|
||
| .. plantuml:: | ||
|
|
||
| @startuml | ||
| title DummyAuthProvider | ||
| participant "Client" | ||
| participant "Backend" | ||
|
|
||
| == POST v1/auth/token == | ||
|
|
||
| activate "Client" | ||
| alt Successful case | ||
| "Client" -> "Backend" ++ : login + password | ||
| "Backend" --> "Backend" : Password is completely ignored | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" -> "Backend" : Create user if not exist | ||
| "Backend" -[#green]> "Client" -- : Generate and return access_token | ||
|
|
||
| else User is blocked | ||
| "Client" -> "Backend" ++ : login + password | ||
| "Backend" --> "Backend" : Password is completely ignored | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" x-[#red]> "Client" -- : 401 Unauthorized | ||
|
|
||
| else User is deleted | ||
| "Client" -> "Backend" ++ : login + password | ||
| "Backend" --> "Backend" : Password is completely ignored | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" x-[#red]> "Client" -- : 404 Not found | ||
| end | ||
|
|
||
| == GET v1/namespaces == | ||
|
|
||
| alt Successful case | ||
| "Client" -> "Backend" ++ : access_token | ||
| "Backend" --> "Backend" : Validate token | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" -> "Backend" : Get data | ||
| "Backend" -[#green]> "Client" -- : Return data | ||
|
|
||
| else Token is expired | ||
| "Client" -> "Backend" ++ : access_token | ||
| "Backend" --> "Backend" : Validate token | ||
| "Backend" x-[#red]> "Client" -- : 401 Unauthorized | ||
|
|
||
| else User is blocked | ||
| "Client" -> "Backend" ++ : access_token | ||
| "Backend" --> "Backend" : Validate token | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" x-[#red]> "Client" -- : 401 Unauthorized | ||
|
|
||
| else User is deleted | ||
| "Client" -> "Backend" ++ : access_token | ||
| "Backend" --> "Backend" : Validate token | ||
| "Backend" --> "Backend" : Check user in internal backend database | ||
| "Backend" x-[#red]> "Client" -- : 404 Not found | ||
| end | ||
|
|
||
| deactivate "Client" | ||
| @enduml | ||
|
|
||
| Configuration | ||
| ------------- | ||
|
|
||
| .. autopydantic_model:: syncmaster.backend.settings.auth.dummy.DummyAuthProviderSettings | ||
| .. autopydantic_model:: syncmaster.backend.settings.auth.jwt.JWTSettings |
This file contains hidden or 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,21 @@ | ||
| .. _backend-auth-providers: | ||
|
|
||
| Auth Providers | ||
| ============== | ||
|
|
||
| Syncmaster supports different auth provider implementations. You can change implementation via settings: | ||
|
|
||
| .. autopydantic_model:: keycloak.backend.settings.auth.AuthSettings | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
| :caption: Auth providers | ||
|
|
||
| dummy | ||
| keycloak | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 2 | ||
| :caption: For developers | ||
|
|
||
| custom |
This file contains hidden or 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,81 @@ | ||
| .. _backend-auth-ldap: | ||
|
|
||
| KeyCloak Auth provider | ||
| ================== | ||
|
|
||
| Description | ||
| ----------- | ||
|
|
||
| TODO: | ||
|
|
||
| Strategies | ||
| ---------- | ||
|
|
||
| TODO: | ||
|
|
||
| Interaction schema | ||
| ------------------ | ||
|
|
||
| .. dropdown:: Interaction schema | ||
|
|
||
| .. plantuml:: | ||
|
|
||
| @startuml | ||
| title Keycloak Authorization Flow | ||
| participant "Client (User from Browser)" as Client | ||
| participant "Syncmaster" | ||
| participant "Keycloak" | ||
|
|
||
| == Client Authentication at Keycloak == | ||
| Client -> Syncmaster : Request endpoint that requires authentication (/v1/users) | ||
|
|
||
| Syncmaster x-[#red]> Client : Redirect to Keycloak login URL (if no access token) | ||
|
|
||
| Client -> Keycloak : Callback redirect to Keycloak login page | ||
|
|
||
| alt Successful login | ||
| Client --> Keycloak : Log in with login and password | ||
| else Login failed | ||
| Keycloak x-[#red]> Client -- : Display error (401 Unauthorized) | ||
| end | ||
|
|
||
| Keycloak -> Client : Redirect to Syncmaster to callback endpoint with code | ||
| Client -> Syncmaster : Callback request to /v1/auth/callback with code | ||
| Syncmaster-> Keycloak : Exchange code for access token | ||
| Keycloak --> Syncmaster : Return JWT token | ||
| Syncmaster --> Client : Set JWT token in user's browser in cookies and redirect /v1/users | ||
|
|
||
| Client --> Syncmaster : Redirect to /v1/users | ||
| Syncmaster -> Syncmaster : Get user info from JWT token and check user in internal backend database | ||
| Syncmaster -> Syncmaster : Create user in internal backend database if not exist | ||
| Syncmaster -[#green]> Client -- : Return requested data | ||
|
|
||
|
|
||
|
|
||
| == GET v1/users == | ||
| alt Successful case | ||
| Client -> Syncmaster : Request data with JWT token | ||
| Syncmaster --> Syncmaster : Get user info from JWT token and check user in internal backend database | ||
| Syncmaster -> Syncmaster : Create user in internal backend database if not exist | ||
| Syncmaster -[#green]> Client -- : Return requested data | ||
|
|
||
| else Access token is expired | ||
| Syncmaster -> Keycloak : Get new JWT token via refresh token | ||
| Keycloak --> Syncmaster : Return new JWT token | ||
| Syncmaster --> Syncmaster : Get user info from JWT token and check user in internal backend database | ||
| Syncmaster -> Syncmaster : Create user in internal backend database if not exist | ||
| Syncmaster -[#green]> Client -- : Return requested data and set new JWT token in user's browser in cookies | ||
|
|
||
| else Refresh token is expired | ||
| Syncmaster x-[#red]> Client -- : Redirect to Keycloak login URL | ||
| end | ||
|
|
||
| deactivate Client | ||
| @enduml | ||
|
|
||
| Basic configuration | ||
| ------------------- | ||
|
|
||
| .. autopydantic_model:: syncmaster.settings.auth.keycloak.KeycloakProviderSettings | ||
| .. autopydantic_model:: syncmaster.settings.auth.jwt.JWTSettings | ||
|
|
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ Configuration | |
| database | ||
| broker | ||
| logging | ||
| session | ||
| cors | ||
| debug | ||
| monitoring | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| .. _backend-configuration-server-session: | ||
|
|
||
| Session settings | ||
| ================ | ||
|
|
||
| These settings used to control `Session <https://developer.mozilla.org/en-US/docs/Web/HTTP/Session>`_ options. | ||
|
|
||
| .. autopydantic_model:: syncmaster.backend.settings.server.session.SessionSettings |
This file contains hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| - Implemented ``KeycloakAuthProvider`` for Single Sign-On (SSO) authentication. | ||
| - Implemented ``DummyAuthProvider`` for development and testing environments. | ||
| - Enabled dynamic selection of authentication provider via environment variable SYNCMASTER__AUTH__PROVIDER: | ||
|
|
||
| .. code:: | ||
|
|
||
| # syncmaster.backend.providers.auth.keycloak_provider.KeycloakAuthProvider for Keycloak. | ||
| SYNCMASTER__AUTH__PROVIDER=syncmaster.backend.providers.auth.keycloak_provider.KeycloakAuthProvider | ||
|
|
||
| # syncmaster.backend.providers.auth.dummy_provider.DummyAuthProvider for Dummy authentication. | ||
| SYNCMASTER__AUTH__PROVIDER=syncmaster.backend.providers.auth.dummy_provider.DummyAuthProvider | ||
|
|
||
| - Updated ``User`` model to include ``email``, ``first_name``, ``middle_name``, and ``last_name`` fields. |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| backend/install | ||
| backend/architecture | ||
| backend/auth/index | ||
| backend/openapi | ||
| backend/configuration/index | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.