-
-
Notifications
You must be signed in to change notification settings - Fork 724
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
feat: Add OIDC_CLIENT_SECRET and other changes for v2 #4254
Merged
michael-genson
merged 27 commits into
mealie-recipes:mealie-next
from
cmintey:server-side-oidc
Oct 5, 2024
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c9723eb
initial impl
cmintey e76b1fe
working implementation
cmintey a5f387a
refine implementation
cmintey 06ae181
hide client secret from logging and set session secret
cmintey 1867194
allow admin users to sign in without the users group
cmintey 26c3775
update docs
cmintey 7832e19
execute callback earlier and reset url on failure
cmintey 21bc5b7
remove oidc api
cmintey d33f153
add claims check and remove async from authenticate method
cmintey 46e5808
add unit tests
cmintey 4cd3345
exclude session secret from logs
cmintey 08a9c79
enable PKCE
cmintey 46fa494
update auth config
cmintey 45935cc
only go to direct login on failure or user logout action
cmintey c9adc6b
fix group claims requirements
cmintey f30b900
update api docs
cmintey feddea6
update e2e docker
cmintey f48a91d
update lock file
cmintey 30c6c06
set secure cookie
cmintey c13cc71
fix test
cmintey a7938e2
Merge remote-tracking branch 'upstream/mealie-next' into server-side-…
cmintey c51b72e
update lock file and api docs
cmintey b9fc128
fix doc links
cmintey c82f30d
Merge remote-tracking branch 'upstream/mealie-next' into server-side-…
cmintey 0dc2249
remove unused env var for signing algorithm
cmintey 962e629
fallback to OIDC_USER_CLAIM for username creation
cmintey ac47712
Merge branch 'mealie-next' into server-side-oidc
boc-the-git 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 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
96 changes: 96 additions & 0 deletions
96
docs/docs/documentation/getting-started/authentication/oidc-v2.md
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,96 @@ | ||
# OpenID Connect (OIDC) Authentication | ||
|
||
:octicons-tag-24: v2.0.0 | ||
|
||
!!! note | ||
Breaking changes to OIDC Authentication were introduced with Mealie v2. Please see the below for [migration steps](#migration-from-mealie-v1x). | ||
|
||
Looking instead for the docs for Mealie :octicons-tag-24: v1.x? [Click here](./oidc.md) | ||
|
||
Mealie supports 3rd party authentication via [OpenID Connect (OIDC)](https://openid.net/connect/), an identity layer built on top of OAuth2. OIDC is supported by many Identity Providers (IdP), including: | ||
|
||
- [Authentik](https://goauthentik.io/integrations/sources/oauth/#openid-connect) | ||
- [Authelia](https://www.authelia.com/configuration/identity-providers/open-id-connect/) | ||
- [Keycloak](https://www.keycloak.org/docs/latest/securing_apps/#_oidc) | ||
- [Okta](https://www.okta.com/openid-connect/) | ||
|
||
## Account Linking | ||
|
||
Signing in with OAuth will automatically find your account in Mealie and link to it. If a user does not exist in Mealie, then one will be created (if enabled), but will be unable to log in with any other authentication method. An admin can configure another authentication method for such a user. | ||
|
||
## Provider Setup | ||
|
||
Before you can start using OIDC Authentication, you must first configure a new client application in your identity provider. Your identity provider must support the OAuth **Authorization Code flow with PKCE**. The steps will vary by provider, but generally, the steps are as follows. | ||
|
||
1. Create a new client application | ||
- The Provider type should be OIDC or OAuth2 | ||
- The Grant type should be `Authorization Code` | ||
- The Client type should be `private` (you should have a **Client Secret**) | ||
|
||
2. Configure redirect URI | ||
|
||
The redirect URI(s) that are needed: | ||
|
||
1. `http(s)://DOMAIN:PORT/login` | ||
2. `https(s)://DOMAIN:PORT/login?direct=1` | ||
1. This URI is only required if your IdP supports [RP-Initiated Logout](https://openid.net/specs/openid-connect-rpinitiated-1_0.html) such as Keycloak. You may also be able to combine this into the previous URI by using a wildcard: `http(s)://DOMAIN:PORT/login*` | ||
|
||
The redirect URI(s) should include any URL that Mealie is accessible from. Some examples include | ||
|
||
http://localhost:9091/login | ||
https://mealie.example.com/login | ||
|
||
3. Configure allowed scopes | ||
|
||
The scopes required are `openid profile email` | ||
|
||
If you plan to use the [groups](#groups) to configure access within Mealie, you will need to also add the scope defined by the `OIDC_GROUPS_CLAIM` environment variable. The default claim is `groups` | ||
|
||
## Mealie Setup | ||
|
||
Take the client id and your discovery URL and update your environment variables to include the required OIDC variables described in [Installation - Backend Configuration](../installation/backend-config.md#openid-connect-oidc). | ||
|
||
### Groups | ||
|
||
There are two (optional) [environment variables](../installation/backend-config.md#openid-connect-oidc) that can control which of the users in your IdP can log in to Mealie and what permissions they will have. Keep in mind that these groups **do not necessarily correspond to groups in Mealie**. The groups claim is configurable via the `OIDC_GROUPS_CLAIM` environment variable. The groups should be **defined in your IdP** and be returned in the configured claim value. | ||
|
||
`OIDC_USER_GROUP`: Users must be a part of this group (within your IdP) to be able to log in. | ||
|
||
`OIDC_ADMIN_GROUP`: Users that are in this group (within your IdP) will be made an **admin** in Mealie. Users in this group do not also need to be in the `OIDC_USER_GROUP` | ||
|
||
## Examples | ||
|
||
Example configurations for several Identity Providers have been provided by the Community in the [GitHub Discussions](https://github.com/mealie-recipes/mealie/discussions/categories/oauth-provider-example). | ||
|
||
If you don't see your provider and have successfully set it up, please consider [creating your own example](https://github.com/mealie-recipes/mealie/discussions/new?category=oauth-provider-example) so that others can have a smoother setup. | ||
|
||
|
||
## Migration from Mealie v1.x | ||
|
||
**High level changes** | ||
|
||
- A Client Secret is now required | ||
- CORS is no longer a requirement since all authentication happens server-side | ||
- A user will be successfully authenticated if they are part of *either* `OIDC_USER_GROUP` or `OIDC_ADMIN_GROUP`. Admins no longer need to be part of both groups | ||
- ID Token signing algorithm is now inferred using the `id_token_signing_alg_values_supported` metadata from the discovery URL | ||
|
||
### Changes in your IdP | ||
|
||
**Required** | ||
|
||
- You must change the Mealie client in your IdP to be **private**. The option is different for every provider, but you need to obtain a **client secret**. | ||
|
||
**Optional** | ||
|
||
- You may now also remove the `OIDC_USER_GROUP` from your admin users if you so desire. Users within the `OIDC_ADMIN_GROUP` will now be able to successfully authenticate with only that group. | ||
- You may remove any CORS configuration. i.e. configured origins | ||
|
||
### Changes in Mealie | ||
|
||
**Required** | ||
|
||
- After obtaining the **client secret** from your IdP, you must add it to Mealie using the `OIDC_CLIENT_SECRET` environment variable or via [docker secrets](../installation/backend-config.md#docker-secrets). This secret will not be logged on startup. | ||
|
||
**Optional** | ||
|
||
- Remove `OIDC_SIGNING_ALGORITHM` from your environment. It will no longer have any effect. |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This states that you can use a Docker secret for the
OIDC_CLIENT_SECRET
, but that doesn't seem to work in practice. I don't see whereOIDC_CLIENT_SECRET
is read from a file in this PR (which is how Docker secrets work). Am I missing something?