Skip to main content

datasette-auth-passwords

PyPI Changelog License

Datasette plugin for authenticating access using passwords

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-auth-passwords

Demo

A demo of this plugin is running at https://datasette-auth-passwords-demo.datasette.io/

The demo is configured to show the public.db database to everyone, but the private.db database only to logged in users.

You can log in at https://datasette-auth-passwords-demo.datasette.io/-/login with username root and password password!.

Usage

This plugin works based on a list of username/password accounts that are hard-coded into the plugin configuration.

First, you'll need to create a password hash. There are three ways to do that:

Now add the following to your metadata.json:

{
    "plugins": {
        "datasette-auth-passwords": {
            "someusername_password_hash": {
                "$env": "PASSWORD_HASH_1"
            }
        }
    }
}

The password hash can now be specified in an environment variable when you run Datasette. You can do that like so:

PASSWORD_HASH_1='pbkdf2_sha256$...' \
    datasette -m metadata.json

Be sure to use single quotes here otherwise the $ symbols in the password hash may be incorrectly interpreted by your shell.

You will now be able to log in to your instance using the form at /-/login with someusername as the username and the password that you used to create your hash as the password.

You can include as many accounts as you like in the configuration, each with different usernames.

datasette hash-password

The plugin exposes a new CLI command, datasette hash-password. You can run this without arguments to interactively create a new password hash:

datasette hash-password
Password: 
Repeat for confirmation: 
pbkdf2_sha256$260000$1513...

Or if you want to use it as part of a script, you can add the --no-confirm option to generate a hash directly from a value passed to standard input:

echo 'my password' | datasette hash-password --no-confirm
pbkdf2_sha256$260000$daa...

Specifying actors

By default, a logged in user will result in an actor block that just contains their username:

{
    "id": "someusername"
}

You can customize the actor that will be used for a username by including an "actors" configuration block, like this:

{
    "plugins": {
        "datasette-auth-passwords": {
            "someusername_password_hash": {
                "$env": "PASSWORD_HASH_1"
            },
            "actors": {
                "someusername": {
                    "id": "someusername",
                    "name": "Some user"
                }
            }
        }
    }
}

HTTP Basic authentication option

This plugin defaults to implementing login using an HTML form that sets a signed authentication cookie.

You can alternatively configure it to use HTTP Basic authentication instead.

Do this by adding "http_basic_auth": true to the datasette-auth-passwords block in your plugin configuration.

This option introduces the following behaviour:

  • Account usernames and passwords are configured in the same way as form-based authentication
  • Every page within Datasette - even pages that normally do not use authentication, such as static assets - will display a browser login prompt
  • Users will be unable to log out without closing their browser entirely

There is a demo of this mode at https://datasette-auth-passwords-http-basic-demo.datasette.io/ - sign in with username root and password password!

Using with datasette publish

If you are publishing data using a datasette publish command you can use the --plugin-secret option to securely configure your password hashes (see secret configuration values).

You would run the command something like this:

datasette publish cloudrun mydatabase.db \
    --install datasette-auth-passwords \
    --plugin-secret datasette-auth-passwords root_password_hash 'pbkdf2_sha256$...' \
    --service datasette-auth-passwords-demo

This will allow you to log in as username root using the password that you used to create the hash.

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-auth-passwords
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Metadata

Release files for datasette-auth-passwords 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datasette-auth-passwords 1.1.1
File Size Uploaded Provenance Actions
datasette_auth_passwords-1.1.1.tar.gz 8.3 kB Without provenance Details for datasette_auth_passwords-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datasette-auth-passwords 1.1.1
File Interpreter ABI Platform Actions
datasette_auth_passwords-1.1.1-py3-none-any.whl Python 3 none any Details for datasette_auth_passwords-1.1.1-py3-none-any.whl

Total release size: 16.0 kB

Release files / datasette_auth_passwords-1.1.1.tar.gz

Download URL datasette_auth_passwords-1.1.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
403a53cb6a29617e91ea3de212dd54e7270c2bdb3e9e8dba350d540e1c5adfca
BLAKE2b-256 checksum
How to use checksums
41272e613ed17c92effac6d3a23c9b16bb983fcaa56a223f62ead61070f37f83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / datasette_auth_passwords-1.1.1-py3-none-any.whl

Download URL datasette_auth_passwords-1.1.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95a933214fbd8ad1218d11bc37a17e074c66141e593ce202cf0f45cd3562c734
BLAKE2b-256 checksum
How to use checksums
3a2533eff736b8ebeacbd69bd323f8b52348686150ef67228b119936343c967b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.5

Security for datasette-auth-passwords 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page