Basic Authentication

This module provides support for basic authentication. It is recommended to use basic authentication only with encrypted transport (https), as the credentials (username and password) are provided with every client request.

The passwords are stored on the server side pre hashed with bcrypt.

Example configuration

The following configuration will allow the consumers with username:password foo:key1 and bar:key2, access to example.com/ and paths below. Multiple consumers can be added.

{
    "name": "example",
    "host": "example.com",
    "path": "/*",
    "modules": [
        {
            "order": 0,
            "name": "auth-basic",
            "general": {
                "realm": "Some realm"
            },
            "consumers": {
                "foo": {
                    "password": "$2y$05$j0wkwHcoF8LUkm4crmVEruzsGJpT/VpoUJZWc3A7YQi7XPzG2C0li"
                },
                "bar": {
                    "password": "$2y$05$U1F6lJBNiZdXPfqeZVaU8uy.Z5u7YJmO48.BvelvomKp78TjNeq6W"
                }
            }
        }
    ]
}

Default configuration attributes

Attribute Required Type Description
realm Yes String The realm used for the endpoint.

Consumer configuration attributes

Attribute Required Type Description
password Yes String The password value in bcrypt format.

The bcrypt hashes can be generated using htpasswd:

$ htpasswd -nB foo
New password:
Re-type new password:
foo:$2y$05$pthxvn2t8b9rF9gF1FhvrutHKik/goGxVx5cOZ2fcXwrJ5Nwz5rPe

Please note that the htpasswd spec supported by the Apache HTTPD server version 2.4 supports other encryption formats in addition to bcrypt, but bcrypt is currently recognized as the most secure format.

Response status

Status Description
200 The request was authorized to access the specified resource.
401 Unauthorized.

Response headers

Header Description
WWW-Authenticate Tell the client that basic authentication is needed. Browsers show the password prompt when receiving this header.
X-Auth-Error Any human readable authentication error, if present.
X-Auth-Type The auth type used, will with this module be basic.
X-Auth-User The username of the authorized user.
X-Auth-Id The username of the authorized user.

®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203