Some checks failed
Codespell / Check for spelling errors (push) Failing after 28s
Ruff / Code linting (push) Failing after 34s
Test execution / Test-all (push) Successful in 1m13s
Codespell / Check for spelling errors (pull_request) Failing after 27s
Ruff / Code linting (pull_request) Failing after 33s
Type annotation (PR) / check (pull_request) Has been cancelled
Describe the policy reference mechanism, the structure of a policy information file and the policy reload endpoint.
523 lines
18 KiB
ReStructuredText
523 lines
18 KiB
ReStructuredText
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 in an external JSON file and can be loaded on
|
||
startup of the service or during runtime of the service. The file should contain
|
||
a JSON-representation of an instance of
|
||
`dump_thing_service.abstract_config.PolicyInfo` (see below for an example)
|
||
|
||
A default location for the policy information of a collection can be configured
|
||
in the `policy_info_location`-property of the collection configuration. If
|
||
the property is set to a URL, the service will try to load the policy information
|
||
from the configured location on startup.
|
||
|
||
The following endpoint allows to trigger a reload of policy information from the
|
||
configured location or from the optional parameter `url`.
|
||
|
||
.. code-block::
|
||
|
||
GET /management/reload/policy_info/{collection}?url
|
||
|
||
The endpoint triggers an immediate reload of a policy configuration. The new
|
||
configuration will become effective immediately, i.e.,
|
||
the next read request in the collection will use the new policy information.
|
||
|
||
The optional parameter `url` overwrites a configured `policy_info_location`-value.
|
||
It can also be used to "attach" policy information to a collection that did
|
||
not yet define policies. If the URL or the policy information file is invalid,
|
||
no changes are made to the current policy information of the collection.
|
||
|
||
The use of the endpoint requires a CURATOR token.
|
||
|
||
in a collection configuration with ``policy_info_location``, 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:: json
|
||
|
||
{
|
||
# Required to enable policy checking. The tag is the key of an
|
||
# entry in the `annotations`-property of a record that defines the
|
||
# policy for this record. The policy system treats the tag as
|
||
# opaque string.
|
||
"policy_annotation_tag": "https://example.org/dumpthings/policy_set"
|
||
|
||
# An optional default policy. If set, all records that do not have
|
||
# an entry with `policy_annotation_tag`-key in their `annotations`-property
|
||
# will be governed by the default policy. The policy system treats
|
||
# the default policy as opaque string.
|
||
"default_policy": "trr379:policy_inm7"
|
||
|
||
# An optional mapping from users to policies that apply to them.
|
||
# Users are identified by the authentication source and the user IDs.
|
||
# For user IDs that are defined in tokens definitions, the authentication
|
||
# source is `config`. For users that are authenticated by an
|
||
# forgejo-authentication source the user ID is the `instance_id`
|
||
# of the authentication source (Note: if no instance_id is provided
|
||
# in a forgejo-authentication source configuration, an MD5-hash of
|
||
# the `url`-property is used. Therefore `instance_id`s should be
|
||
# provided to simplify policy mappings definition)
|
||
|
||
"policy_mapping": [
|
||
|
||
# A user that could be authenticated by the forgejo-authentication
|
||
# source defined above.
|
||
{
|
||
# `auth_source` is the `instance_id` of the forgejo-authentication
|
||
# source defined above.
|
||
"auth_source": "trr379hub",
|
||
"user_id": "c.moench",
|
||
# All policies that hold for the user are given as a list. Policies
|
||
# are treated as opaque strings.
|
||
"authorized_by": [
|
||
"trr379:policy_inm7",
|
||
"trr379:policy_psychoinformatics"
|
||
]
|
||
},
|
||
|
||
# Mapping for a user that is defined in a token configuration
|
||
{
|
||
# `auth_source` is `"config"` because the user is defined in
|
||
# a token configuration.
|
||
"auth_source": "config",
|
||
"user_id": "token_defined_user_1",
|
||
"authorized_by": [
|
||
"inm7:library",
|
||
"inm7:employees",
|
||
]
|
||
}
|
||
]
|
||
}
|
||
|
||
|
||
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
|