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 Topic/support nginx auth request #43

Closed
wants to merge 3 commits into from

Conversation

gimpf
Copy link
Contributor

@gimpf gimpf commented Nov 23, 2019

by far not ready yet

PoC technically works (tested w/radicale on nginx), but there's a lot of work still to be done:

  • to support non-human clients, sso-auth endpoint needs support for sso-session via basic-auth or http-header (Android calendars don't do form login dance) ...
  • ... which means "generate app-key" support in whawty-auth admin
  • sessions need sensible expiration times
  • sessions need to be persistent whawty-auth restarts
  • session cookie should use public-key crypto, so that sso-login and sso-auth endpoints can reside on different servers w/o sharing of secret keys
  • somebody who's able to type might want to add a single automated test for all of this
  • ?redir= argument must support whitelists (we do not want to leak successful login to potentially any adversary)

Not strictly necessary, but I think useful in practice and as a showcase: whawty-auth admin page should be able to use the sso-login/auth mechanism.

Other stuff is more optional and can be added later:

  • sensible common login page between whawty-auth sso-login and admin
  • list of active sessions per user, incl. support for cancelation ...
  • ... which means session blacklists in the auth endpoint

and likely other stuff

New optional endpoints:
- sso-auth-addr: usable as target for auth_request queries by nginx,
  checks the 'sso' cookie for login-state
- sso-login-addr: provides a simplistic login form, sets the 'sso'
  cookie

Badly hacked components:
- all endpoints get the session-store injected (reusing the pre-existing
  session store for this, although it's not really suitable because
  sessions are transient to the server lifetime, and expiration is
  hardcoded, it works for a prototype)
- example nginx config, to be used within a server block
- regular whawty-auth admin page login-form is badly hacked to support
  different base-paths
@gimpf gimpf requested a review from equinox0815 November 23, 2019 11:27
@gimpf
Copy link
Contributor Author

gimpf commented Nov 23, 2019

Also, I just saw that with a bit of JS you can make nginx use an oauth2 server as auth_request endpoint.

With some hackery this means a single oauth2 endpoint used for auth_request with some bad hacks around it could support apps with oauth2 support, as well as some older stuff that barely knows what x-remote-user means.

So, solving issue #10 would be better.

@equinox0815
Copy link
Member

Yey but this needs the nginx javascript module which is not built by default and is not included in debian packages.

Probably the js code can be rewritten using lua?

@gimpf
Copy link
Contributor Author

gimpf commented Nov 23, 2019

Definitely: It's only there for parsing the JSON request, as OAuth2 always responds with 200 and embeds the auth-result, whereas with auth_request we need 200 vs. 401 vs. 403.

@equinox0815
Copy link
Member

actually what about this: https://github.com/sto/ngx_http_auth_pam_module
It is included in the debian packages: https://packages.debian.org/buster/libnginx-mod-http-auth-pam

@gimpf
Copy link
Contributor Author

gimpf commented Nov 23, 2019

Basically, yeah, why not. But then:

Please tell me that this is not undefined behavior: https://github.com/sto/ngx_http_auth_pam_module/blob/d9286fc7b52e1a3584da2cb20423f912ec99169f/ngx_http_auth_pam_module.c#L234

ctx is proved false at this line, but ctx->passwd seems still to try to dereference this.

I don't understand what's going on there.

What I actually tried to find: because all browser vendors refused to make HTTP-integrated authorization properly usable (e.g. have a log-out button), I want to integrate a form-based login, not basic auth. Documentation is bare-bones, or I'm blind, but it seems like this uses HTTP auth only.

BTW, auth-endpoint behind a proxy can make use of authentication caching rather easily. With a low-enough setting, this would still re-authenticate against whawty at every human initiated request, but signifcantly reduce the load against the backend without us having to do any caching; given that web apps love to make 100s of request for just about everything, this seems nice.

@equinox0815
Copy link
Member

Yeah you are right. So let's implement Oauth2 then.

@equinox0815
Copy link
Member

@gimpf fyi: I have a new need for something similar to what you proposed here. But in this case i also need to support authenticating against LDAP. Since i was not satisfied with the way Luzifer/nginx-sso handles things i created whawty/nginx-sso. You might want to take a look.

@equinox0815
Copy link
Member

Now that whawty.nginx-sso is released i will closed this PR.

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.

2 participants