SSO wwith Authelia Customized
Go to file
Clément Michaud 6438a5e48f
Fix ECONNRESET when LDAP queries fail. (#261)
This commit should fix #225.

In order to avoid stalling LDAP connections, Authelia creates new
sessions for each set of queries bound to one authentication, i.e.,
one session for authentication, emails retrieval and groups
retrieval.
Before this commit, a failing query was preventing the session to
be closed (unbind was not called). Now, unbind is always called
whatever the outcome of the query.

I took the opportunity of this commit to refactor LDAP client in
order to prepare the work on users database stored in a file.
(#233)
2018-08-25 19:22:48 +02:00
client Merge branch 'master' into bootstrap_loading_spinner 2018-07-26 22:30:09 +02:00
example Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
images Update README to reference kubernetes deployment documentation 2018-04-25 08:51:43 +02:00
scripts Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
server Fix ECONNRESET when LDAP queries fail. (#261) 2018-08-25 19:22:48 +02:00
shared Rename redirect query parameter into rd for compatibility with nginx-ingress 2018-04-24 23:03:09 +02:00
test Implement retry mechanism for broken connections to mongo (#258) 2018-08-19 16:51:36 +02:00
.gitignore Fix npm package versions with package-lock.json 2017-10-31 07:37:15 +01:00
.npmignore Add shared/ directory in .npmignore 2017-10-31 07:37:15 +01:00
.travis.yml Replace npm api key to solve publication. (#260) 2018-08-24 23:03:54 +02:00
CHANGELOG.md Add changelog to the project 2018-03-29 23:09:31 +02:00
config.minimal.yml Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
config.template.yml Make session cookie name customizable. (#256) 2018-08-19 13:07:00 +02:00
CONTRIBUTORS.md Add contributors to source and documentation to CONTRIBUTORS.md 2017-11-01 22:13:17 +01:00
docker-compose.dev.yml Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
docker-compose.dockerhub.yml Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
docker-compose.minimal.yml Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
docker-compose.yml Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
Dockerfile Add tests for minimal configuration 2018-08-10 00:12:04 +02:00
Gruntfile.js Implement retry mechanism for broken connections to mongo (#258) 2018-08-19 16:51:36 +02:00
LICENSE Adding README, LICENSE and CONTRIBUTORS files 2016-12-17 20:26:46 +01:00
package-lock.json Fix ECONNRESET when LDAP queries fail. (#261) 2018-08-25 19:22:48 +02:00
package.json Fix ECONNRESET when LDAP queries fail. (#261) 2018-08-25 19:22:48 +02:00
README.md Update README to mention kubernetes in the description 2018-05-02 22:12:33 +02:00

Authelia

license Build Gitter

Authelia is an open-source authentication and authorization server. Authelia brings 2-factor authentication and single sign-on to secure web applications and ease authentication. It has been designed to be a companion of any reverse proxy by helping it handle authentication and authorization requests.

Authelia can be installed on bare-metal using Docker or npm but can also be deployed easily on a Kubernetes cluster and leverages ingress controller and ingress configuration concepts to easily configure authentication and authorization for specific services in your cluster by simply editing your ingress configuration.

Table of Contents

  1. Features summary
  2. Deployment
    1. With NPM
    2. With Docker
    3. With Kubernetes
  3. Getting started
    1. Pre-requisites
    2. Run it!
  4. Features in details
    1. First factor with LDAP and ACL
    2. Second factor with TOTP
    3. Second factor with U2F security keys
    4. Password reset
    5. Access control
    6. Single factor authentication
    7. Session management with Redis
  5. Security
  6. Documentation
    1. Authelia configuration
    2. Wiki
    3. API documentation
  7. Contributing to Authelia
  8. License

Features summary

  • Two-factor authentication using either TOTP - Time-Base One Time password - or U2F - Universal 2-Factor - as 2nd factor.
  • Password reset with identity verification using email.
  • Single and two factors authentication methods available.
  • Access restriction after too many authentication attempts.
  • User-defined access control per subdomain and resource.
  • Support of basic authentication for endpoints protected by single factor.
  • High-availability using a highly-available distributed database and KV store.
  • Compatible with Kubernetes ingress-nginx controller out of the box.

Deployment

If you don't have any LDAP and/or nginx setup yet, I advise you to follow the Getting Started section. That way, you can test it right away without even configuring anything.

Otherwise, here are the available steps to deploy Authelia on your machine given your configuration file is /path/to/your/config.yml. Note that you can create your own the configuration file from config.template.yml at the root of the repo.

With NPM

npm install -g authelia
authelia /path/to/your/config.yml

With Docker

docker pull clems4ever/authelia
docker run -v /path/to/your/config.yml:/etc/authelia/config.yml -v /path/to/data/dir:/var/lib/authelia clems4ever/authelia

where /path/to/data/dir is the directory where all user data will be stored.

With Kubernetes

Please refer to the following README.

Getting started

The provided example is docker-based so that you can deploy and test it very quickly.

Pre-requisites

npm

Make sure you have npm and node installed on your computer.

Docker

Make sure you have docker and docker-compose installed on your machine. For your information, here are the versions that have been used for testing:

docker --version

gave Docker version 17.03.1-ce, build c6d412e.

docker-compose --version

gave docker-compose version 1.14.0, build c7bdf9e.

Available port

Make sure you don't have anything listening on port 8080 (webserver) and 8085 (webmail).

Subdomain aliases

Add the following lines to your /etc/hosts to alias multiple subdomains so that nginx can redirect request to the correct virtual host.

127.0.0.1       home.example.com
127.0.0.1       public.example.com
127.0.0.1       dev.example.com
127.0.0.1       admin.example.com
127.0.0.1       mx1.mail.example.com
127.0.0.1       mx2.mail.example.com
127.0.0.1       single_factor.example.com
127.0.0.1       login.example.com

Run it!

Deploy the Authelia example with one of the following commands:

Build Docker container from current commit:

./scripts/build-dev.sh
./scripts/example-commit/deploy-example.sh

Use provided container on DockerHub:

./scripts/example-dockerhub/deploy-example.sh

After few seconds the services should be running and you should be able to visit https://home.example.com:8080/.

When accessing the login page, a self-signed certificate exception should appear, it has to be trusted before you can get to the target page. The certificate must also be trusted for each subdomain, therefore it is normal to see the exception several times.

Below is what the login page looks like:

Features in details

First factor using an LDAP server

Authelia uses an LDAP server as the backend for storing credentials. When authentication is needed, the user is redirected to the login page which corresponds to the first factor. Authelia tries to bind the username and password against the configured LDAP backend.

You can find an example of the configuration of the LDAP backend in config.template.yml.

Second factor with TOTP

In Authelia, you can register a per user TOTP (Time-Based One Time Password) secret before authenticating. To do that, you need to click on the register button. It will send a link to the user email address stored in LDAP. Since this is an example, the email is sent to a fake email address you can access from the webmail at http://localhost:8085. Click on Continue and you'll get your secret in QRCode and Base32 formats. You can use Google Authenticator to store them and get the generated tokens with the app.

Note: If you're testing with npm, you will not have access to the fake webmail. You can use the filesystem notifier (option available config.template.yml) that will create a file containing the validation URL instead of sending an email. Please only use it for testing.

Second factor with U2F security keys

Authelia also offers authentication using U2F (Universal 2-Factor) devices like Yubikey USB security keys. U2F is one of the most secure authentication protocol and is already available for Google, Facebook, Github accounts and more.

Like TOTP, U2F requires you register your security key before authenticating. To do so, click on the register button. This will send a link to the user email address. Since this is an example, the email is sent to a fake email address you can access from the webmail at http://localhost:8085. Click on Continue and you'll be asking to touch the token of your device to register. Upon successful registration, you can authenticate using your U2F device by simply touching the token. Easy, right?!

Note: If you're testing with npm, you will not have access to the fake webmail. You can use the filesystem notifier (option available config.template.yml) that will create a file containing the validation URL instead of sending an email. Please only use it for testing.

Password reset

With Authelia, you can also reset your password in no time. Click on the Forgot password? link in the login page, provide the username of the user requiring a password reset and Authelia will send an email with an link to the user email address. For the sake of the example, the email is delivered in a fake webmail deployed for you and accessible at http://localhost:8085. Paste the link in your browser and you should be able to reset the password.

Note: If you're testing with npm, you will not have access to the fake webmail. You can use the filesystem notifier (option available config.template.yml) that will create a file containing the validation URL instead of sending an email. Please only use it for testing.

Access Control

With Authelia, you can define your own access control rules for finely restricting user access to some resources and subdomains. Those rules are defined and fully documented in the configuration file. They can apply to users, groups or everyone. Check out config.template.yml to see how they are defined.

Single factor authentication

Authelia allows you to customize the authentication method to use for each sub-domain.The supported methods are either "single_factor" or "two_factor". Please see config.template.yml to see an example of configuration.

It is also possible to use basic authentication to access a resource protected by a single factor.

Session management with Redis

When your users authenticate against Authelia, sessions are stored in a Redis key/value store. You can specify your own Redis instance in config.template.yml.

Security

Authelia uses two mechanism to protect against cookie theft:

  1. session attribute httpOnly set to true make client-side code unable to read the cookie.
  2. session attribute secure ensure the cookie will never be sent over an unsecure HTTP connections.

Since Authelia uses multi-domain cookies to perform single sign-on, an attacker who poisonned a user's DNS cache can easily retrieve the user's cookies by making the user send a request to one of the attacker's IPs.

To mitigate this risk, it's advisable to only use HTTPS connections with valid certificates and enforce it with HTTP Strict Transport Security (HSTS) so that the attacker must also require the certificate to retrieve the cookies.

Note that using HSTS has consequences. That's why you should read the blog post nginx has written on HSTS.

More protections measures

You can also apply the following headers to your nginx configuration for improving security. Please read the documentation of those headers before applying them blindly.

# We don't want any credentials / TOTP secret key / QR code to be cached by
# the client
add_header Cache-Control "no-store";
add_header Pragma "no-cache";

# Clickjacking / XSS protection

# We don't want Authelia's login page to be rendered within a <frame>, 
# <iframe> or <object> from an external website.
add_header X-Frame-Options "SAMEORIGIN";

# Block pages from loading when they detect reflected XSS attacks.
add_header X-XSS-Protection "1; mode=block";

Documentation

Authelia configuration

The configuration of the server is defined in the file config.template.yml. All the details are documented there. You can specify another configuration file by giving it as first argument of Authelia.

authelia config.custom.yml

Wiki

A wiki is available if you need more details about Authelia.

API documentation

There is a complete API documentation generated with apiDoc and embedded in the repo under the doc/ directory. Simply open index.html locally to watch it.

Contributing to Authelia

Follow contributing file.

License

Authelia is licensed under the MIT License. The terms of the license are as follows:

The MIT License (MIT)

Copyright (c) 2016 - Clement Michaud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.