Skip to content
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

[Wip] prepare deployment #20

Closed
wants to merge 11 commits into from
Closed

[Wip] prepare deployment #20

wants to merge 11 commits into from

Conversation

lebaudantoine
Copy link
Collaborator

@lebaudantoine lebaudantoine commented Jan 25, 2024

Purpose

Prepare project deployment in staging.

Proposal

We've introduced a Docker image for the frontend, which serves Next static build output using Nginx.
Some updates have been made to the production settings.

* rename client people-front to people
* add a client secret shared with the backend
* add allowed redirect uris
* disable implicit flow and enable Authorization Code flow without PCKE
* sign userinfo endpoint to return application/jwt content
Backend and Frontend send requests to Keycloak through Nginx.

Thus, all requests from frontend and backend shared a same host
when received by Keycloak.

Otherwise, the flow is initiated from http://localhost:8080. When the Backend
calls token endpoint from Keycloak container at http://keycloak:8080,
the JWT token issuer and sender are mismatching.
force login to bypass authorization checks when necessary.

Note: Generating a session cookie through OIDC flow
is not supported while testing our API.
Integrate 'mozilla-django-oidc' dependency, to support
Authorization Code flow, which is required by Agent Connect.

Thus, we provide a secure back channel OIDC flow, and return
to the client only a session cookie.

Done:
* Replace JWT authentication by Session based authentication in DRF
* Update Django settings to make OIDC configurations easily editable
* Add 'mozilla-django-oidc' routes to our router
* Implement a custom Django Authentication class to adapt 'mozilla-django-oidc' to our needs

'mozilla-django-oidc' routes added are:
* /authenticate
* /callback (the redirect_uri called back by the Idp)
* /logout

Todo in dedicated PR:
* Configure redis to manage these session cookies
* Test and adjust code if necessary when the session cookie expires
* Test and adjust code if necessary when the user logout
Instead of interacting with Keycloak, the frontend navigate to the
/authenticate endpoint, which starts the Authorization code flow.

When the flow is done, the backend redirect back to the SPA,
passing a session cookie and a csrf cookie.

Done:
* Query GET user/me to determine if user is authenticated yet
* Remove Keycloak js dependency, as all the OIDC logic is handled by the backend
* Store user's data instead of the JWT token

Todo in a dedicated PR:
* Implement the home screen with the SSO login buton
* Handle Logout properly
* Intercept 401 and 403 error properly
The local deployment of the Production image through docker-compose was
failing due to issues in the Django configurations, influenced by Joanie.

The bug stemmed from a dependency on a development-specific package
(drf-spectacular-sidecar) while attempting to run the application in
production mode.

Changes Made:
- Introduced new Django settings for local demo environments.
- Uncommented the nginx configuration to address the production image
  deployment issues.
Updated to Node Image version 20 to align with the upcoming frontend image.
To facilitate deployment on Kubernetes, we've introduced a Docker image for the
frontend. The Next project is built, and its static output is served using an
Nginx reverse proxy.

Since DevOps lacks a certified cold storage solution (e.g., S3) for serving
static files, we've opted to containerize the frontend as a quick workaround for
deploying staging environments.
Enabled Dockerflow Django app by activating liveness probes. The previously
unavailable routes such as `__heartbeat__` and `__lbheartbeat__` are now
accessible. New endpoints include:
* GET /__version__
* GET /__heartbeat__
* GET /__lbheartbeat__
Found typos, fixed them.
@lebaudantoine lebaudantoine changed the base branch from main to al-sso February 15, 2024 18:13
@lebaudantoine lebaudantoine changed the base branch from al-sso to main February 15, 2024 18:13
@lebaudantoine lebaudantoine changed the title 🔧(project) prepare deployment [Wip] prepare deployment Feb 15, 2024
@lebaudantoine lebaudantoine removed the request for review from rouja February 15, 2024 18:14
@lebaudantoine lebaudantoine marked this pull request as ready for review February 15, 2024 18:14
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.

1 participant