-
-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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
oauth2_proxy: add nginx vhost module #42775
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,64 @@ | ||
{ pkgs, config, lib, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.oauth2_proxy.nginx; | ||
in | ||
{ | ||
options.services.oauth2_proxy.nginx = { | ||
proxy = mkOption { | ||
type = types.string; | ||
default = config.services.oauth2_proxy.httpAddress; | ||
description = '' | ||
The address of the reverse proxy endpoint for oauth2_proxy | ||
''; | ||
}; | ||
virtualHosts = mkOption { | ||
type = types.listOf types.string; | ||
default = []; | ||
description = '' | ||
A list of nginx virtual hosts to put behind the oauth2 proxy | ||
''; | ||
}; | ||
}; | ||
config.services.oauth2_proxy = mkIf (cfg.virtualHosts != [] && (hasPrefix "127.0.0.1:" cfg.proxy)) { | ||
enable = true; | ||
}; | ||
config.services.nginx = mkMerge ((optional (cfg.virtualHosts != []) { | ||
recommendedProxySettings = true; # needed because duplicate headers | ||
}) ++ (map (vhost: { | ||
virtualHosts.${vhost} = { | ||
locations."/oauth2/" = { | ||
proxyPass = cfg.proxy; | ||
extraConfig = '' | ||
proxy_set_header X-Scheme $scheme; | ||
proxy_set_header X-Auth-Request-Redirect $request_uri; | ||
''; | ||
}; | ||
locations."/oauth2/auth" = { | ||
proxyPass = cfg.proxy; | ||
extraConfig = '' | ||
proxy_set_header X-Scheme $scheme; | ||
# nginx auth_request includes headers but not body | ||
proxy_set_header Content-Length ""; | ||
proxy_pass_request_body off; | ||
''; | ||
}; | ||
locations."/".extraConfig = '' | ||
auth_request /oauth2/auth; | ||
error_page 401 = /oauth2/sign_in; | ||
|
||
# pass information via X-User and X-Email headers to backend, | ||
# requires running with --set-xauthrequest flag | ||
auth_request_set $user $upstream_http_x_auth_request_user; | ||
auth_request_set $email $upstream_http_x_auth_request_email; | ||
proxy_set_header X-User $user; | ||
proxy_set_header X-Email $email; | ||
|
||
# if you enabled --cookie-refresh, this is needed for it to work with auth_request | ||
auth_request_set $auth_cookie $upstream_http_set_cookie; | ||
add_header Set-Cookie $auth_cookie; | ||
''; | ||
|
||
}; | ||
}) cfg.virtualHosts)); | ||
} |
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.
Are there cases where this can be something other than
config.services.oauth2_proxy.httpAddress
?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.
@yorickvP
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.
yes, when the proxy runs on another system.