Skip to main content

Advanced permission management for Datasette

Project description

datasette-acl

PyPI Changelog Tests License

Advanced permission management for Datasette. Highly experimental.

Installation

Install this plugin in the same environment as Datasette.

datasette install datasette-acl

Usage

This plugin is under active development. It currently only supports configuring permissions for individual tables, controlling the following:

  • insert-row
  • delete-row
  • update-row
  • alter-table
  • drop-table

Permissions are saved in the internal database. This means you should run Datasette with the --internal path/to/internal.db option, otherwise your permissions will be reset every time you restart Datasette.

Managing permissions for a table

The interface for configuring table permissions lives at /database-name/table-name/-/acl. It can be accessed from the table actions menu on the table page.

Permission can be granted for each of the above table actions. They can be assigned to both groups and individual users, who can be added using their actor["id"].

An audit log tracks which permissions were added and removed, displayed at the bottom of the table permissions page.

Controlling who can edit permissions

Users with the new datasette-acl permission will have the ability to access a UI for setting permissions for groups on a table.

To configure the root user to have this permission, add the following to your Datasette configuration:

permissions:
  datasette-acl:
    id: root

Alternatively you can start Datasette running like this:

datasette mydata.db --root --internal internal.db \
  -s permissions.datasette-acl.id root

Dynamic groups

You may wish to define permission rules against groups of actors based on their actor attributes, without needing to manually add those actors to a group. This can be achieved by defining a dynamic group in the datasette-acl configuration.

Dynamic groups are defined in terms of allow blocks. The following configuration defines two dynamic groups - one called admin that contains all users with "is_admin": true in their attributes, and another called sales that explicitly lists the users with "sales" as one of the values in their department array.

plugins:
  datasette-acl:
    dynamic-groups:
      admin:
        is_admin: true
      sales:
        department: ["sales"]

Any time an actor has their permissions checked they will be dynamically added to or removed from these groups based on the current value of their actor attributes.

Table creator permissions

If you allow regular users to create tables in Datasette, you may want them to maintain a level of "ownership" over those tables, such that other users are unable to modify those tables without the creator's permission.

The `table-creator-permissions' setting can be used to automatically configure permissions for the actor who created a table.

Enable that like this:

plugins:
  datasette-acl:
    table-creator-permissions:
    - alter-table
    - drop-table
    - insert-row
    - update-row
    - delete-row

Development

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

cd datasette-acl
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

python -m pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette_acl-0.2a0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

datasette_acl-0.2a0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file datasette_acl-0.2a0.tar.gz.

File metadata

  • Download URL: datasette_acl-0.2a0.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for datasette_acl-0.2a0.tar.gz
Algorithm Hash digest
SHA256 b82776fd598550c551c5e753cdfdb6240b20b041eeea662ebfb9a90f9d05a256
MD5 a3a2e756bbf0242e67c946bbb9edd58f
BLAKE2b-256 11e24712bfa1e34e028880789cd2cf892015f8f17e8b2a4eb581ee2ed2697845

See more details on using hashes here.

File details

Details for the file datasette_acl-0.2a0-py3-none-any.whl.

File metadata

File hashes

Hashes for datasette_acl-0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfce651d9202f00a383c7f5aab3aa277fa19a9ab4f7de9d3d42479d578e349ff
MD5 f601a7bc1bfd182662751ac24e50b1a8
BLAKE2b-256 8f10d6ab898f648d67dc427310a03d21b302ff480301cc84aca5c05b47fdd309

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page