-
-
Notifications
You must be signed in to change notification settings - Fork 307
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 support for forward auth #1341
Open
sgmitchell
wants to merge
7
commits into
fallenbagel:develop
Choose a base branch
from
sgmitchell:fw-auth
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−17
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
37c0eda
feat: add forward-auth support
Janhouse b114c23
docs: add forward-auth config example
Janhouse 6e51386
feat(auth): add option for forward authentication when behind a trust…
sgmitchell e200875
chore: pnpm i18n:extract
sgmitchell 020dc2d
fix: pin pnpm version in docker builds
sgmitchell 18d67a1
style: rename file from pr comments
sgmitchell 98c002b
refactor: undo dockerfile changes
sgmitchell 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
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,74 @@ | ||
# Forward auth | ||
|
||
You can use [forward-auth](https://doc.traefik.io/traefik/middlewares/http/forwardauth/) mechanism to log into Jellyseer. | ||
|
||
This works by passing the authenticated user e-mail in `X-Forwarded-User` header by the auth server, therefore enabling single-sign-on (SSO) login. | ||
|
||
:::warning | ||
The user has to exist, it will not be created automatically. | ||
::: | ||
|
||
:::info | ||
If the user has no email set, the username will also work | ||
::: | ||
|
||
## Example with Goauthentik and Traefik | ||
|
||
This example assumes that you have already configured an `application` and `provider` for Jellyseer in Authentik, and added the `provider` to the `outpost`. | ||
|
||
We now have to create a scope mapping that will pass the `X-Forwarded-User` header containing user e-mail to Jellyseerr application. | ||
|
||
### Create scope mapping | ||
|
||
In Authentik go to `Customization > Propperty Mappings` and create `Scope Mapping`: | ||
|
||
* Name: `jellyseerr-forwardauth` | ||
* Scope: `ak_proxy` | ||
* Expression: | ||
|
||
```py | ||
return { | ||
"ak_proxy": { | ||
"user_attributes": { | ||
"additionalHeaders": { | ||
"X-Forwarded-User": request.user.email | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Add the scope mapping to provider scopes | ||
|
||
In authentik go to `Applications > Providers`, edit your `jellyseer` provider: | ||
|
||
* Under `Advanced protocol settings` - `Available scopes` select the `jellyseerr-forwardauth` scope that was created in the previous step and add it to the `Selected scopes` list | ||
* Save the changes by clicking the `Update` button | ||
|
||
### Create the forward-auth middleware in Traefik | ||
|
||
Now you have to define the forward-auth middleware in Traefik and attach it to the `jellyseerr` router. Authentik also requires to set up login page routing so it could redirect properly to Authentik. | ||
|
||
```yml | ||
labels: | ||
- traefik.enable=true | ||
|
||
# Forward auth middleware | ||
- traefik.http.middlewares.auth-authentik.forwardauth.address=http://authentik-server:9000/outpost.goauthentik.io/auth/jellyseerr | ||
- traefik.http.middlewares.auth-authentik.forwardauth.trustForwardHeader=true | ||
- traefik.http.middlewares.auth-authentik.forwardauth.authResponseHeaders=X-Forwarded-User | ||
|
||
# Router for jellyseerr | ||
- traefik.http.routers.jellyseerr.rule=Host(`jellyseerr.domain.com`) | ||
- traefik.http.routers.jellyseerr.entrypoints=websecure | ||
- traefik.http.routers.jellyseerr.middlewares=auth-authentik@docker | ||
# Service for jellyseerr | ||
- traefik.http.services.jellyseerr.loadbalancer.server.port=5055 | ||
- traefik.http.routers.jellyseerr.service=jellyseerr | ||
|
||
# Router for login pages | ||
- traefik.http.routers.jellyseerr-auth.rule=Host(`jellyseerr.domain.co`) && PathPrefix(`/outpost.goauthentik.io/`) | ||
- traefik.http.routers.jellyseerr-auth.entrypoints=websecure | ||
# Service - reference the authentik outpost service name | ||
- traefik.http.routers.jellyseerr-auth.service=authentik@docker | ||
``` |
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
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
gauthier-th marked this conversation as resolved.
Show resolved
Hide resolved
|
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,18 @@ | ||
import type { NextPageContext } from 'next/dist/shared/lib/utils'; | ||
import type { GetServerSidePropsContext, PreviewData } from 'next/types'; | ||
import type { ParsedUrlQuery } from 'querystring'; | ||
|
||
export const getAuthHeaders = ( | ||
ctx: NextPageContext | GetServerSidePropsContext<ParsedUrlQuery, PreviewData> | ||
) => { | ||
return ctx.req && ctx.req.headers | ||
? { | ||
...(ctx.req.headers.cookie && { | ||
cookie: ctx.req.headers.cookie, | ||
}), | ||
...(ctx.req.headers['x-forwarded-user'] && { | ||
'x-forwarded-user': ctx.req.headers['x-forwarded-user'] as string, | ||
}), | ||
} | ||
: undefined; | ||
}; |
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.
All the changes in this file are just copied straight from #580. I'm not sure how this file is used or if there is a better way to generate this spec
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.
You should add this inside the
securitySchemes
section ofcomponents
(line 1956), with something like this inside:I'm not an expert in this kind of spec either, so if someone could confirm it would be nice.
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.
Gotcha. So since that's already in place, I think this file is probably good?
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.
I think it is too. But it doesn't hurt to have another check.