Metadata-Version: 2.5
Name: trytond_strings_xo_web
Version: 8.0.0.4
Summary: Xen Orchestra Self-Service Portal
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: orchestra,portal,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-keycloak-auth<8.1,>=8.0
Requires-Dist: trytond-strings-xo<8.1,>=8.0
Requires-Dist: trytond-web-user<8.1,>=8.0
Requires-Dist: trytond<8.1,>=8.0
Provides-Extra: test
Requires-Dist: trytond-strings-xo-compute<8.1,>=8.0; extra == 'test'
Description-Content-Type: text/x-rst

Xen Orchestra Self-Service Portal
=================================

The ``strings_xo_web`` module is the Tryton side of the Xen Orchestra
self-service portal.  It complements the ``strings_xo`` suite with the
portal configuration of a Xen Orchestra server, a read-only REST API
consumed by the ``fe_strings_xo`` flask_portal module and the
self-service provisioning of new virtual machines.

Features
--------

- **Portal visibility**: a *Self-Service Portal* flag on every Xen
  Orchestra server marks the servers whose virtual machines are offered
  to the web users.
- **Read-only REST API**: the ``/<database>/xo/`` endpoints publish the
  portal servers, the virtual machines owned by the authenticated
  identity and the availability status of the inventory.  A request may
  present either the legacy ``web.user`` bearer session or a Keycloak
  access token verified by ``keycloak_auth`` (see below).
- **Self-service provisioning**: a web user requests a virtual machine
  built from one of the templates approved by the operator, choosing the
  resource set, the network, the size of the disks and a cloud-init
  document.  The request is stored and executed against Xen Orchestra by
  the scheduled action of the module.
- **Quota policy**: the requests are checked against a provisional quota
  policy which limits the number of machines a web user may own and the
  size of the machines and disks the portal creates (see the
  *Configuration* section).
- **Fail closed ownership**: a web user only ever sees the virtual
  machines it owns or those of the Xen Orchestra resource sets it is
  granted; when the ownership of a virtual machine cannot be established
  the portal returns an empty inventory instead of exposing every
  machine.
- **Security**: a dedicated ``Xen Orchestra Web User`` group carries the
  read access of the portal — on the servers and the provisioning
  requests declared by this module, on the virtual machines and the
  templates declared by ``strings_xo_compute`` — and the server secrets
  stay protected by the field level access rights of the ``strings_xo``
  module; the API never serialises a secret field.

Virtual machine inventory
-------------------------

The ``xo.vm`` model is provided by the ``strings_xo_compute`` module
(Heptapod issue #645).  Because the portal must remain installable while
the compute inventory is being built, ``strings_xo_compute`` is *not* a
dependency of this module:

- when ``xo.vm`` is not installed, ``GET /<database>/xo/vms`` answers an
  empty list, ``GET /<database>/xo/inventory`` reports
  ``available: false`` and the provisioning endpoints answer with a
  ``503``;
- once the compute module is installed, the machines owned by the web
  user are listed automatically, restricted to the portal enabled
  servers, and the approved templates are offered for provisioning.

The module therefore declares ``strings_xo_compute`` as an *extras
depend*: an installation may leave it out, while the test environment of
the module installs it and exercises the inventory path against the real
``xo.vm`` model.

Approved templates
------------------

A template is approved for self-service provisioning when it carries the
*Approved Template Tag* of a server whose *Self-Service Provisioning*
flag is checked.  The templates are therefore approved from Xen
Orchestra itself, by tagging them, without any synchronisation of an
additional model.

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

A caller may only provision into the Xen Orchestra resource sets stored
on its identity record, one per line; an empty list denies every
machine.  The legacy session path reads them on the ``web.user`` record,
the Keycloak token path on the ``res.user`` record (issue #805).  The
resource sets also widen the inventory scope, so that a machine created
in one of them becomes visible to its requester even before an ownership
field is mirrored.

The resource set of a created machine is provisional: it is sent to Xen
Orchestra with the creation, until the ``strings_xo_access`` module owns
the ``xo.acl.resource.set`` records in RC (Heptapod issue #660).

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

After installing the module, open *Xen Orchestra > Servers* and check
*Self-Service Portal* on the servers that should be offered to the web
users; check *Self-Service Provisioning* on the servers the portal may
create machines on, and adapt *Approved Template Tag* if the templates
are not tagged ``self-service``.  The Xen Orchestra resource sets of a
web user are entered on *Web Users*; those of a caller authenticated by
the portal with a Keycloak access token are entered on *Users*, on the
*Self-Service* page (issue #805).

The provisional quota policy is read from the ``[strings_xo_web]``
section of the trytond configuration file::

    [strings_xo_web]
    provisioning_max_vms = 5
    provisioning_max_cpu = 8
    provisioning_max_memory_mb = 16384
    provisioning_max_disk_gb = 200

A limit of ``0`` disables the self-service provisioning entirely.  The
policy is provisional by design: the ``strings_xo_access`` module
replaces it with the ``xo.acl.resource.set`` policies in RC (Heptapod
issue #665).

The portal module itself is declared to the Flask Portal through the
``flask_board.cfg`` file of the module (section
``[portal:fe_strings_xo]``), with the ``features_provisioning`` flag
enabled.

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

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

Models
------

- ``xo.server`` — extended with the *Self-Service Portal*, *Self-Service
  Provisioning* and *Approved Template Tag* fields.
- ``web.user`` — extended with the Xen Orchestra resource sets of the
  web user (the legacy session path).
- ``res.user`` — extended with the Xen Orchestra resource sets of a
  caller authenticated with a Keycloak access token (issue #805).
- ``strings_xo_web.provisioning`` — the self-service provisioning
  requests, executed by the scheduled action of the module.

REST API
--------

All the endpoints are mounted under ``/<database>/xo/`` and require an
``Authorization: Bearer <token>`` header.

- ``GET /<database>/xo/servers`` — the portal enabled servers.
- ``GET /<database>/xo/vms`` — the virtual machines of the
  authenticated identity.
- ``GET /<database>/xo/vms/<id>`` — a single virtual machine.
- ``GET /<database>/xo/inventory`` — the inventory status.
- ``GET /<database>/xo/templates`` — the approved templates.
- ``GET /<database>/xo/provisioning`` — the provisioning requests of the
  authenticated web user.
- ``GET /<database>/xo/provisioning/options`` — the resource sets
  granted to the web user and the provisional quota policy.
- ``POST /<database>/xo/vms`` — request a virtual machine built from an
  approved template.

Authentication
--------------

Two credentials are accepted, and which one a request presents decides
the authentication path (issue #805, see
``keycloak_auth/doc/adoption.rst``):

- a **Keycloak access token** (a JSON Web Token) is verified by the
  ``keycloak_auth`` module: the identity it names is resolved to an
  active ``res.user`` by exact, case-sensitive ``login``, nothing is
  provisioned on the way, and a request that presents no acceptable
  credential is answered with the JSON ``401`` of the helper.  The view
  then runs with the access checks of that user, and the virtual machine
  scope is the one granted to the resolved ``res.user``.
- a **``web.user.session`` key** issued by trytond's ``web_user`` login
  system keeps taking the session path, unchanged: the key resolves the
  ``web.user`` and the scope is the one of that record.

The new path is opt-in through the credential itself: a session key is a
hexadecimal string and can never carry the dots of a JSON Web Token, so
the two cannot be confused and the portal keeps using its session keys
until it migrates.  The keycloak path is offered on the four read
endpoints ``/xo/servers``, ``/xo/inventory``, ``/xo/vms`` and
``/xo/vms/<id>``; the remaining endpoints keep their session-only
authentication.

A caller resolved from a Keycloak token has no ``web.user`` record, so
its Xen Orchestra resource sets are entered on its ``res.user`` record
(*Self-Service* page of the user form).  The read access of that user on
the Xen Orchestra inventory is enforced by ``ir.model.access``: an
operation its rights deny is answered with ``403``.

Access model
------------

The identity a request resolves — the ``web.user`` of the session path
as well as the ``res.user`` of the Keycloak path — has to be a member of
the ``Xen Orchestra Web User`` group (*Administration > Users > Groups*),
which carries only read access.  The group is defined by the
``strings_xo`` base module, because this module and ``strings_xo_compute``
both grant it access and neither of the two may depend on the other
(Heptapod issue #822):

- ``xo.server`` and ``strings_xo_web.provisioning`` are granted by this
  module;
- ``xo.vm`` and ``xo.vm.template`` are granted read-only by
  ``strings_xo_compute``, which owns them.

No write, create or delete is granted to the group: the provisioning
request of a portal user is created by the privileged route of this
module and the machine it asks for by the scheduled action, which runs
with the privileges of the system user.  An identity that is a member of
no group reads nothing, and a read its rights deny is answered with
``403`` by the token path.
