dump-things-service/docs/configuration.rst
Christian Monch 48697365d9
Some checks failed
Codespell / Check for spelling errors (push) Failing after 42s
Codespell / Check for spelling errors (pull_request) Failing after 42s
Ruff / Code linting (push) Successful in 51s
Ruff / Code linting (pull_request) Successful in 53s
Type annotation (PR) / check (pull_request) Failing after 1m20s
Test execution / Test-all (push) Successful in 1m27s
refactor: rename authorized_for to authorized_by
The configuration property that maps policies to
users is now called `authorized_by` to reflect
that a policy is matching and granting the
user access,
2026-10-02 08:46:39 +02:00

456 lines
15 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Configuration
=============
General Concepts
----------------
Each Dump Things Service instance maintains a persistent configuration. The
configuration is stored in a private area of the *storage root* and will be
loaded when a Dump Things Service instance is started.
Providing an initial configuration
..................................
If the persistent configuration is empty, for example, because the service is
started on an empty ``<storage root>``, an initial configuration can be
provided by configuration files:
1. via a configuration file in ``<storage root>/.dumpthings.yaml``, or
2. a configuration file can be passed to the command line with the ``-c/--config``
option.
Performing dynamic configuration changes
........................................
Every Dump Things Service instance (since version 6) supports dynamic
reconfiguration via administration API endpoints. That means, a server can be
started with an empty configuration and the configuration can be modified at
runtime.
If a Dump Things Service instance is started with an empty configuration,
the command line option ``--admin-token-hash`` has to be provided.
This option will establish a "bootstrap" administrator token in the
Dump Things Server instance that can be used to access the
administration endpoints.
Note: the bootstrap administrator token does not become part of the persisted
configuration. That means, it will not be represented in a configuration dump,
i.e., in the result of ``GET /admin_tokens``.
Elements of the configuration
-----------------------------
Dump Things Service instances have three main configuration elements:
- Collections
- Tokens
- Administrator Tokens
A Dump Things Service instance has administration endpoints for all three
configuration elements, which allow to create, modify, and delete
these elements. Any change to the configuration is persisted immediately and
will be effective for all subsequent requests to the service.
All configuration changes are audited (see :doc:`audit` for details). The
audit log is stored in the storage root at the path
``<storage root>/__dumpthings__/config_audit``.
Configuration modification model
--------------------------------
A Dump Things Service instance maintains an internal representation of the
current configuration. The persistent configuration is kept up-to-date with
the internal configuration.
If, for example, a collection is added via the administration
interface, the service will add the collection to its internal configuration
representation. It will then persist the new configuration and updated its
internal state to "activate" the new configuration.
In other words if the administrator interface is used to add a collection, a
token, or an administrator-token, the element will be added to the already
existing configuration elements. If an element is removed via the administration
interface, this element will be removed from the internal configuration, while
all other configuration elements remain unchanged.
To determine the current configuration of the service, the administrator API
provides endpoints to read collection configurations, token configurations, and
admin token configurations.
To modify an existing configuration element, the administrator can fetch its
current state, modify it, and ``PUT`` it back to the service.
The tool ``dump-things-download-config`` (see :doc:`commands`) can be used to
fetch the current configuration of a running Dump Things Service instance and
write it to a configuration file (see :ref:`config_file:`). This file can be
used, for example, to create a Dump Things Service with an identical
configuration at another location.
For a detailed description of the configuration endpoints see :doc:`endpoints`.
.. _config_file:
Configuration File Structure
-----------------------------
A configuration file (version 2) has the following top-level structure:
.. code-block:: yaml
type: collections # must be "collections"
version: 2 # must be 2
collections:
<collection-name>:
...
tokens:
<token-name>:
...
admin_tokens:
<admin-token-name>:
...
Collections
-----------
Each entry under ``<collection-name>`` defines a collection. The following keys
are supported:
``schema`` (required)
URL of the `LinkML <https://linkml.io>`_ schema for this collection.
``default_token`` (required)
Name of the token to use when no token is provided by a client. All
permissions in the default token are OR-ed with any client-provided token.
Note: a token of the given name must be defined in the ``tokens`` section
of the configuration file. At least the default token must be created before
a collection can be created. Although tokens reference collections, tokens
can always be created because their creation does check whether referenced
collections exist yet.
``curated`` (required)
Path to the curated area of the collection. This should be a relative path,
which will be interpreted relative to the storage root.
``incoming`` (required if tokens with write access exist for the collection)
Path to the incoming area. Required if the collection has any tokens with
write access associated to it.
This should be a relative path, which will be interpreted relative to the
storage root.
``backend`` (optional)
Storage backend configuration. If omitted, ``record_dir+stl`` is used.
See :doc:`backends` for details.
``use_classes`` (optional)
List of LinkML class names that should receive store/validate endpoints
(the classes must be subclasses of ``Thing``). All other classes defined
in the schema are ignored.
``ignore_classes`` (optional)
List of LinkML class names to exclude from store/validate endpoints
(the classes must be subclasses of ``Thing``).
``auth_sources`` (optional)
List of authentication source configurations. See :doc:`authentication`.
``submission_tags`` (optional)
Tags for an optional automated annotation of submitted records (see
`Submission Annotation Tags`_ below).
``audit_backends`` (optional)
List of audit-backend configurations. See `Audit Backends`_ below.
``policy_annotation_tag`` (optional)
Key for the policy annotation tag. If the key is found in the
``annotation``-property of a record, its value is interpreted as policy
that controls access to the record (if an ``sqlite``-backend) is
used.
If ``policy_annotation_tag`` is not set, the policy mechanism is ignored
in this collection.
``default_policy`` (optional)
Default policy for records in this collection. If ``policy_annotation_tag``
is set, and a record does not have a policy annotation, the default policy
is used. If ``default_policy`` is not set, records without a policy
annotation are considered public. Policies are opaque strings, which are
compared verbatim in ``sqlite``-backends.
``policy_mapping`` (optional)
Mapping from users to policies. If access to a record is guarded by a policy,
the user will only be able to access (or "see") the record, if the policy
is present in the set of policies that are mapped to the user.
See `Policy Mappings`_ below.
Example
^^^^^^^
.. code-block:: yaml
collections:
personal_records:
default_token: no_access
schema: https://concepts.datalad.org/s/demo-research-information/unreleased.yaml
curated: curated
incoming: incoming
use_classes:
- Organization
- Person
- Project
Authentication Sources
^^^^^^^^^^^^^^^^^^^^^^
Authentication configuration is described in :doc:`authentication`. If no
authentication sources are defined for a collection, a ``config`` source is
used by default, that means, the service will use the tokens that are
configured in the configuration file.
Submission Annotation Tags
^^^^^^^^^^^^^^^^^^^^^^^^^^
The service might annotate uploaded records with a submitter ID and a
submission time (version below 6 will always annotate submitted records,
version 6 and higher will only annotate submitted records, if the query
parameter ``add_submission_tag`` is set to ``true``.
By default, the following tags are used for submission annotation:
- Submitter ID: ``http://purl.obolibrary.org/obo/NCIT_C54269``
- Submission time: ``http://semanticscience.org/resource/SIO_001083``
Override these defaults per collection with ``submission_tags``:
.. code-block:: yaml
collections:
collection_1:
...
submission_tags:
submitter_id_tag: schema:user_id
submission_time_tag: schema:time
Audit Backends
^^^^^^^^^^^^^^
The service supports audit logs of changes made via the curation interface.
Configure them per collection with ``audit_backends``:
.. code-block:: yaml
collections:
collection_1:
...
audit_backends:
- type: gitaudit
path: /path/to/audit-log-dir
auto_flush_timeout: 60 # seconds (default: 60, minimum: 1)
Currently the only supported audit backend type is ``gitaudit``. A ``gitaudit``
backend stores changes in a bare Git repository at ``path``.
After ``auto_flush_timeout`` seconds without new entries the current changeset
is committed.
Use ``dump-things-gitaudit-report`` to display the audit log and
``dump-things-gitaudit-rebuild-index`` to rebuild its index (see :doc:`commands`).
Policy Mappings
^^^^^^^^^^^^^^^
The service allows to assign a set of policies to each user.
If a record is annotated with a policy that is in the set of the user's policies,
or a default policy which is in the user's set of policies is defined,
the user is allowed to see and access the record.
Policy mappings are configured per collection with ``policy_mapping``, which
contains a list of user -> policy mappings. Each user is identified by an
authentication source and a user ID. The authentication source ``config`` if
the user ID is defined by a token that is directly defined in the collection.
If the user is authenticated via a forgejo authentication source, the
``instance_id`` of the forgejo authentication source will be the authentication
source.
The following is an example for a policy mapping for two users, one defined
by a token in the configuration and one authenticated via a forgejo
authentication source that has the ``instance_id`` ``forgejo_1.example.com``:
.. code-block:: yaml
collections:
collection_1:
...
policy_mapping:
- auth_source: config
user_id: token_1_user
authorized_by:
- policy_1
- policy_2
- auth_source: forgejo_1.example.com
user_id: forgejo_user_1
authorized_by:
- policy_2
- policy_3
Collection-and-Token: a Chicken-and-Egg Problem
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In configuration files, collections reference tokens and tokens reference collections.
This can create a chicken-and-egg problem when creating new collection and
new tokens dynamically. This is resolved by allowing tokens to refer to
collections that are not created. In other words:
Create tokens first, then create collections.
Reserved Collection Names
^^^^^^^^^^^^^^^^^^^^^^^^^
The following collection names are reserved and must **not** be used:
- ``api``
- ``collections``
- ``tokens``
- ``admin_tokens``
- ``__dump_things__``
Tokens
------
Each entry under ``tokens`` defines a token. The following keys are supported:
``representation`` (required)
The plain-text value the client must supply in the ``X-DumpThings-Token``
HTTP header. If ``hashed`` is ``True`` this must be the SHA-256 hex digest
of the plain-text token.
``hashed`` (optional, default: ``False``)
If ``True``, the representation is treated as a SHA-256 hash.
Use the command ``dump-things-hash-token`` (see :doc:commands) to compute the correct hash.
``user_id`` (required)
An identifier that is added as an annotation to each uploaded record.
``collections`` (required)
Mapping from collection name to per-collection rights.
Per-collection rights
^^^^^^^^^^^^^^^^^^^^^
Each collection entry inside a token has:
``mode``
Access mode. Available modes (in the following list "own incoming area"
refers to the incoming area that is associated with the token and the
collection):
- ``NOTHING`` – no access.
- ``READ_CURATED`` – read the curated area only.
- ``READ_COLLECTION`` – read curated data and own incoming area.
- ``WRITE_COLLECTION`` – read curated data, read own incoming area, write to own incoming area.
- ``READ_SUBMISSIONS`` - read own incoming area.
- ``WRITE_SUBMISSIONS`` – read and write own incoming area.
- ``SUBMIT`` - read curated area only, write to own incoming area.
- ``SUBMIT_ONLY`` - write to own incoming area.
- ``CURATOR`` - curator-level access: read & write to curated area, read & write to all incoming areas.
``incoming_label``
Label that defines the subdirectory (aka zone) in the incoming area for this token and collection.
Multiple tokens can share the same label, which means they share a zone.
Example
^^^^^^^
.. code-block:: yaml
tokens:
basic_access:
representation: anonymous
hashed: False
user_id: anonymous_user
collections:
rooms_and_buildings:
mode: READ_CURATED
incoming_label: ''
contributor_bob:
representation: bob
user_id: Bob
collections:
rooms_and_buildings:
mode: WRITE_COLLECTION
incoming_label: new_rooms_and_buildings
Tips & Tricks
-------------
Same Backend for Incoming and Curated Areas
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can configure the service so that incoming records are immediately visible
in the curated area by setting the final incoming path to equal the curated
path:
.. code-block:: yaml
collections:
datamgt:
default_token: anon_read
curated: datamgt/curated
incoming: datamgt
tokens:
trusted-submitter-token:
user_id: trusted_submitter
collections:
datamgt:
mode: WRITE_COLLECTION
incoming_label: curated # datamgt/curated == curated path
Migrating to Version 6 from Version <=5
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Start the version 6 server on the same storage root as the version 5 server.
The version 6 server will automatically migrate the configuration from
``<storage root>/.dumpthings.yaml`` from the version 5 format to the new
format and persist it. Use the ``-c/--config`` option on first start to
initialise the persisted configuration from a different file than
``<storage root>/.dumpthings.yaml``.
Once started, the configuration is stored in the internal database and the
file ``<storage_root>/.dumpthings.yaml`` or the ``-c`` option can be omitted
on subsequent starts:
.. code-block:: bash
dump-things-service /path/to/storage -c /path/to/old-config.yaml