mirror of https://github.com/dexidp/dex.git
12 changed files with 168 additions and 12 deletions
@ -0,0 +1,87 @@
|
||||
# External authentication |
||||
|
||||
## Overview |
||||
|
||||
The authproxy connector returns identities based on authentication which your |
||||
front-end web server performs. |
||||
|
||||
The connector does not support refresh tokens or groups at this point. |
||||
|
||||
## Configuration |
||||
|
||||
The following is an example config file that can be used by the external |
||||
connector to authenticate a user. |
||||
|
||||
```yaml |
||||
connectors: |
||||
- type: authproxy |
||||
id: myBasicAuth |
||||
name: HTTP Basic Auth |
||||
``` |
||||
|
||||
The authproxy connector assumes that you configured your front-end web server |
||||
such that it performs authentication for the `/dex/callback/myBasicAuth` |
||||
location and provides the result in the X-Remote-User HTTP header. The following |
||||
configuration will work for Apache 2.4.10+: |
||||
|
||||
``` |
||||
<Location /dex/callback/myBasicAuth> |
||||
AuthType Basic |
||||
AuthName "db.debian.org webPassword" |
||||
AuthBasicProvider file |
||||
AuthUserFile "/etc/apache2/debian-web-pw.htpasswd" |
||||
Require valid-user |
||||
|
||||
# Defense in depth: clear the Authorization header so that |
||||
# Debian Web Passwords never even reach dex. |
||||
RequestHeader unset Authorization |
||||
|
||||
# Requires Apache 2.4.10+ |
||||
RequestHeader set X-Remote-User expr=%{REMOTE_USER}@debian.org |
||||
|
||||
ProxyPass "http://localhost:5556/dex/callback/myBasicAuth" |
||||
ProxyPassReverse "http://localhost:5556/dex/callback/myBasicAuth" |
||||
</Location> |
||||
``` |
||||
|
||||
## Full Apache2 setup |
||||
|
||||
After installing your Linux distribution’s Apache2 package, place the following |
||||
virtual host configuration in e.g. `/etc/apache2/sites-available/sso.conf`: |
||||
|
||||
``` |
||||
<VirtualHost sso.example.net> |
||||
ServerName sso.example.net |
||||
|
||||
ServerAdmin webmaster@localhost |
||||
DocumentRoot /var/www/html |
||||
|
||||
ErrorLog ${APACHE_LOG_DIR}/error.log |
||||
CustomLog ${APACHE_LOG_DIR}/access.log combined |
||||
|
||||
<Location /dex/> |
||||
ProxyPass "http://localhost:5556/dex/" |
||||
ProxyPassReverse "http://localhost:5556/dex/" |
||||
</Location> |
||||
|
||||
<Location /dex/callback/myBasicAuth> |
||||
AuthType Basic |
||||
AuthName "db.debian.org webPassword" |
||||
AuthBasicProvider file |
||||
AuthUserFile "/etc/apache2/debian-web-pw.htpasswd" |
||||
Require valid-user |
||||
|
||||
# Defense in depth: clear the Authorization header so that |
||||
# Debian Web Passwords never even reach dex. |
||||
RequestHeader unset Authorization |
||||
|
||||
# Requires Apache 2.4.10+ |
||||
RequestHeader set X-Remote-User expr=%{REMOTE_USER}@debian.org |
||||
|
||||
ProxyPass "http://localhost:5556/dex/callback/myBasicAuth" |
||||
ProxyPassReverse "http://localhost:5556/dex/callback/myBasicAuth" |
||||
</Location> |
||||
</VirtualHost> |
||||
``` |
||||
|
||||
Then, enable it using `a2ensite sso.conf`, followed by a restart of Apache2. |
||||
@ -0,0 +1,56 @@
|
||||
// Package authproxy implements a connector which relies on external
|
||||
// authentication (e.g. mod_auth in Apache2) and returns an identity with the
|
||||
// HTTP header X-Remote-User as verified email.
|
||||
package authproxy |
||||
|
||||
import ( |
||||
"fmt" |
||||
"net/http" |
||||
"net/url" |
||||
|
||||
"github.com/coreos/dex/connector" |
||||
"github.com/sirupsen/logrus" |
||||
) |
||||
|
||||
// Config holds the configuration parameters for a connector which returns an
|
||||
// identity with the HTTP header X-Remote-User as verified email.
|
||||
type Config struct{} |
||||
|
||||
// Open returns an authentication strategy which requires no user interaction.
|
||||
func (c *Config) Open(id string, logger logrus.FieldLogger) (connector.Connector, error) { |
||||
return &callback{logger: logger, pathSuffix: "/" + id}, nil |
||||
} |
||||
|
||||
// Callback is a connector which returns an identity with the HTTP header
|
||||
// X-Remote-User as verified email.
|
||||
type callback struct { |
||||
logger logrus.FieldLogger |
||||
pathSuffix string |
||||
} |
||||
|
||||
// LoginURL returns the URL to redirect the user to login with.
|
||||
func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (string, error) { |
||||
u, err := url.Parse(callbackURL) |
||||
if err != nil { |
||||
return "", fmt.Errorf("failed to parse callbackURL %q: %v", callbackURL, err) |
||||
} |
||||
u.Path = u.Path + m.pathSuffix |
||||
v := u.Query() |
||||
v.Set("state", state) |
||||
u.RawQuery = v.Encode() |
||||
return u.String(), nil |
||||
} |
||||
|
||||
// HandleCallback parses the request and returns the user's identity
|
||||
func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) { |
||||
remoteUser := r.Header.Get("X-Remote-User") |
||||
if remoteUser == "" { |
||||
return connector.Identity{}, fmt.Errorf("required HTTP header X-Remote-User is not set") |
||||
} |
||||
// TODO: add support for X-Remote-Group, see
|
||||
// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy
|
||||
return connector.Identity{ |
||||
Email: remoteUser, |
||||
EmailVerified: true, |
||||
}, nil |
||||
} |
||||
Loading…
Reference in new issue