Metadata-Version: 2.5
Name: trytond_strings_xo_access
Version: 8.0.0.3
Summary: Xen Orchestra Access
Author: Clemens Hupka
Maintainer-email: Clemens Hupka <clemens.hupka@backend.at>
License-Expression: GPL-3.0-or-later
License-File: COPYRIGHT
License-File: LICENSE
Keywords: access,orchestra,rbac,tryton,virtualization,xcp-ng,xen
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Plugins
Classifier: Framework :: Tryton
Classifier: Topic :: Office/Business
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Requires-Dist: trytond-company<8.1,>=8.0
Requires-Dist: trytond-strings-xo<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Description-Content-Type: text/x-rst

Xen Orchestra Access
====================

The ``strings_xo_access`` module owns the access model of the Xen
Orchestra integration.  It mirrors the accounts and the groups of a Xen
Orchestra instance into Tryton, holds the *resource sets* the suite
grants its identities, and owns the *authentication tokens* external
callers present to the Xen Orchestra API.  Xen Orchestra remains the
authority on the instances and on the permission it gives an account,
so the module authors the part of an account that is an access
decision — its permission — and mirrors the rest.

Features
--------

- **Identity mirror**: the ``users`` and the ``groups`` collections of
  the REST API v0 are mirrored as searchable records, the groups being
  synchronised before the users so that the members of a group are
  resolved once both collections have been pulled.  An account or a
  group Xen Orchestra no longer reports is deactivated rather than
  deleted.
- **Explicit user mapping**: an account is mapped to a ``res.user``
  explicitly, by hand or with the *Create Tryton User* button, which
  derives the login from the email address of the account and grants the
  created user the self-service portal.  The mapping is never derived
  from the email address alone: a record matched by a value that is not
  an explicit link would let the holder of an account of another
  identity provider into the Tryton account of somebody else.
- **Authored permission**: the permission of an account is the property
  the module authors, through a ``PATCH`` of the account in Xen
  Orchestra; every other property of an account belongs to Xen Orchestra
  and to the identity provider that authenticates it.
- **Resource sets**: the sets are authored in Tryton — the subjects they
  are granted to, which are the mirrored accounts and groups and the
  Tryton groups of the portal, and the objects they cover, which are the
  identifiers of the pools, the templates, the storage repositories and
  the networks of the instance — and published to Xen Orchestra on
  demand, where they become the self-service sets Xen Orchestra
  enforces when one of its users creates a machine.  A set is created on
  its first publication and written on every later one, so a grant
  withdrawn in Tryton is withdrawn in Xen Orchestra, and withdrawing it
  destroys it there at once.
- **Token lifecycle**: an authentication token is provisioned for an
  account, renewed before it expires and revoked; the identifier of a
  token *is* its secret, so the secret is encrypted at rest, masked in
  every read result and protected by the field-level access rights of
  the module.  A renewal revokes the token it replaces before it
  provisions a fresh one, so that a failure never leaves a token the
  module cannot name valid in Xen Orchestra.
- **Audit trail**: every change of the access model is recorded as an
  ``xo.acl.change`` record telling apart a change reported by a
  synchronisation, a change made by a user and one made by an operation
  of the module.  The records are immutable, so the trail cannot be
  rewritten.
- **Security**: dedicated access rights reusing the ``strings_xo``
  groups, the provisioning, the renewal, the revocation and the
  publication restricted to the administration groups, and a field-level
  access right keeping the secret of a token out of the reach of a
  non-administrator.  A user outside the administration groups reads the
  access model of the instances of its company and changes nothing of
  it; filing an access request is the one thing such a user may create,
  and it decides nothing.
- **Self-service policy**: the quotas a resource set enforces, the
  approval workflow for the requests it does not grant, and the
  enforcement hooks the self-service portal consumes.

Identity mirror
---------------

An account is identified in Xen Orchestra by its email address and, for
the accounts that are not identified by it, by a user name; the module
stores both, together with the name parts, the permission and the
authentication providers Xen Orchestra reports.  A permission the module
does not describe is not mirrored, so that an account Xen Orchestra
gives a permission a later version adds does not fail the
synchronisation; the permission of that account is then left as it is.

A group carries its name and the accounts Xen Orchestra reports for it.
The membership is resolved by the post-synchronisation hook of the
server and is never written back: a membership Xen Orchestra holds is
never dropped by a write issued from Tryton.

Resource sets
-------------

A resource set names the subjects it is granted to and the objects it
covers.  The subjects are the mirrored accounts and groups and the
Tryton groups of the self-service portal, which lets a set be granted to
the portal users of a Tryton group without mirroring them as Xen
Orchestra accounts; an account or a group Xen Orchestra does not know
yet is left out of the publication, since Xen Orchestra cannot grant a
set to a subject it does not hold.

The objects are the identifiers of the pools, the templates, the storage
repositories and the networks of the instance, entered one per line and
copied into the set as they are.  The sets are not mirrored: they are
authored in Tryton, published with the *Publish* button and withdrawn
with the *Withdraw* button, which destroys the set in Xen Orchestra
while the record is kept, so that the same subjects can be granted it
again by publishing it afresh.

Self-service policy
-------------------

A resource set also carries the policy the self-service portal applies
to the identities it is granted to: its **quotas** and whether a request
against it is **privileged**.  The quotas cap the number of machines the
set may hold and the size of the machine a request asks for — its
virtual processors, its memory, the size of its disks and the number of
networks it may be plugged into — where a limit of ``0`` means no limit
and the *Enforce Quotas* flag of the set is what turns the enforcement
on.  A set whose *Requires Approval* flag is checked makes every request
against it privileged.

A self-service request the policy does not grant is not refused
outright: it is filed as an **access request** and decided by an
administrator, who approves or refuses it.  An approved request covers a
later request made for the same resource set and the same identity when
it grants at least the same amounts, so that an approval is neither
wider nor longer lived than what was decided.  Filing a request is not
an access decision, so the Xen Orchestra users may create one; deciding
it is, so only the administration groups may write it.

The policy is enforced through the hooks of the ``policy`` module —
``policy``, ``usage``, ``evaluate``, ``check``, ``request_approval`` and
``check_approved`` — which are the surface the self-service portal
consumes.  The hooks fail closed: an unknown identifier resolves to no
policy, and a quota that cannot be counted because the compute inventory
is not installed is an error rather than an allowance.

Authentication tokens
---------------------

A token is what an external caller presents to the Xen Orchestra API in
place of a password.  It is provisioned for an account that is mirrored
from Xen Orchestra, with the validity Xen Orchestra is configured with:
the module reads the expiration Xen Orchestra reports rather than asking
for one.

The identifier of a token is its secret, and Xen Orchestra reports it
only when the token is created.  The module therefore stores it
encrypted and never requests it again; the field it is held in is masked
in every read result and protected by the field-level access rights of
the module.  The *Renew* button revokes the selected tokens in Xen
Orchestra before it provisions a fresh one for the same account, and the
*Revoke* button destroys them and marks them as revoked.  The scheduled
action of the module marks the tokens whose expiration has passed as
expired, Xen Orchestra having stopped honouring them.

Access audit
------------

The changes of the access model are recorded as ``xo.acl.change``
records, under *Xen Orchestra > Access > Access Changes*.  A record
carries the date, the company, the actor — empty when the change was
reported by a synchronisation — the source of the change, the model, the
name and the Xen Orchestra identifier of the changed record, the action
and, as JSON, the fields the change modifies with the value they held
before it and the value they hold after it.  Only the fields that
differ are recorded, so a write touching no access decision leaves the
trail untouched.

Configuration
-------------

After installing the module, the access model is managed under *Xen
Orchestra > Access*:

- *Users* — the mirrored accounts, their permission and the Tryton user
  they are mapped to.  The *Create Tryton User* button creates the
  mapped user and grants it the self-service portal.
- *Groups* — the mirrored groups and the accounts Xen Orchestra reports
  for them.
- *Resource Sets* — the sets granted to the identities of the suite,
  with the *Publish* and *Withdraw* buttons.
- *Authentication Tokens* — the tokens of the accounts, with the
  *Provision*, *Renew* and *Revoke* buttons.
- *Access Changes* — the audit trail, which is read-only.

The accounts and the groups of a server are also listed on the *Users*
and the *Groups* page of its form.  The whole mirror is refreshed by the
*Xen Orchestra: Synchronise* scheduled action of the ``strings_xo`` base
module.

Security groups
---------------

- *Xen Orchestra* (``group_strings_xo``) — the operators: read-only
  access on the whole access model, including the audit trail.
- *Xen Orchestra Administration* (``group_strings_xo_admin``) — the
  administrators: full access, including the buttons provisioning,
  renewing and revoking a token and publishing and withdrawing a
  resource set.

The audit trail is never writable by any group, including the
administrators, and the secret of a token is denied to every group but
the administrators.

Dependencies
------------

- Tryton modules: ``ir``, ``res``, ``company``, ``strings_xo``.

Models
------

- ``xo.user`` — ``XOUser``: an account of a Xen Orchestra instance.
- ``xo.user-xo.group`` — ``XOUserGroup``: the membership of a group.
- ``xo.group`` — ``XOGroup``: a group of a Xen Orchestra instance.
- ``xo.acl.resource.set`` — ``XOACLResourceSet``: what the suite grants
  an identity, published to Xen Orchestra as a self-service set.
- ``xo.acl.resource.set-xo.user`` — ``XOACLResourceSetUser``: an account
  a set is granted to.
- ``xo.acl.resource.set-xo.group`` — ``XOACLResourceSetGroup``: a group
  a set is granted to.
- ``xo.acl.resource.set-res.group`` — ``XOACLResourceSetResGroup``: a
  Tryton group a set is granted to.
- ``xo.access.token`` — ``XOAccessToken``: an authentication token of an
  account.
- ``xo.acl.change`` — ``XOACLChange``: one change of the access model.
- ``xo.server`` — extended with the accounts and the groups of the
  server.

Cron Jobs
---------

- *Xen Orchestra: Expire Authentication Tokens*
  (``xo.access.token|cron_expire_tokens``) — marks the tokens whose
  expiration has passed as expired.  It ticks every 60 minutes and can
  be deactivated in *Administration > Scheduled Actions*.
