@@ -472,6 +472,103 @@ Note that these should not have subpaths in them unless the value
472472of the subpath can be consistently pre-determined. Block device naming
473473depends on the kernel/fstab configuration and cannot be pre-determined.
474474
475+ Conditional permissions
476+ -----------------------
477+
478+ Since 1.17.0, Flatpak supports conditional permissions which allows
479+ them to be granted only when certain runtime conditions are satisfied
480+ and fallback otherwise. The intention of the system is to allow
481+ users or developers to specify tighter permission grants (as they are
482+ added in new Flatpak versions) while fallback to older grants for
483+ backwards compatibility at run time.
484+
485+ .. note ::
486+
487+ Older Flatpak versions will fail when encountering unknown
488+ commandline options, while unrecognized metadata entries will be
489+ silently ignored.
490+
491+ Flatpak manifests using conditional flags (for example,
492+ ``--socket-if= `` etc.) will require Flatpak 1.17.0 or newer to
493+ build and attempting to build them with older Flatpak versions will
494+ produce an error.
495+
496+ The following flags are available to specify conditional
497+ permissions in CLI and in Flatpak manifests::
498+
499+ --socket-if=
500+ --device-if=
501+ --share-if=
502+ --allow-if=
503+
504+ The syntax of all the options are ``--socket-if=PERMISSION:CONDITION ``
505+ and so on where ``PERMISSION `` is the available grants for that flag
506+ (e.g., those listed for ``--socket= ``). Conditions can be negated by
507+ prefixing with ``! ``. The following conditions are supported:
508+
509+ - ``true `` - Always evaluates to true
510+ - ``false ``- Always evaluates to false
511+ - ``has-input-device `` - True if the Flatpak version supports
512+ ``--device=input ``
513+ - ``has-wayland `` - True if the current desktop session supports
514+ Wayland
515+
516+ Multiple conditionals can be specified for the same grant, in which
517+ case the permission is granted if any condition matches. If no
518+ conditional rule evaluates to ``true ``, the grant is denied
519+ unless it is also unconditionally allowed. Duplicate conditions are
520+ ignored.
521+
522+ Examples
523+ `````````
524+
525+ #. The unconditional grant ``--socket=x11 `` can be tightened using
526+ conditional permissions to ``--socket-if=x11:!has-wayland ``. This
527+ allows access to X11 only when a Wayland desktop session is not
528+ available. To preserve backwards compatibility, the following
529+ pattern can be used::
530+
531+ --socket=x11
532+ --socket-if=x11:!has-wayland
533+
534+ This allows older Flatpak versions which do not understand the
535+ conditional permissions function by allowing X11 access always
536+ while newer Flatpak, which understands the conditional system will
537+ allow X11 access only when the session is not Wayland.
538+
539+ #. If an application requires only access to ``input `` device permission,
540+ the following flags can be used to move away from ``--device=all ``
541+ to ``--device=input ``::
542+
543+ --device=all
544+ --device-if=all:false
545+ --device-if=input:has-input-device
546+
547+ This allows older Flatpak versions which do not understand the
548+ ``input `` device permission to function by having the broader
549+ ``all `` access, while newer Flatpak versions which understand the
550+ conditional system will deny ``all `` due to
551+ ``--device-if=all:false `` and allow only ``input `` due to
552+ ``--device-if=input:has-input-device ``.
553+
554+ To explicitly deny a permission that might be granted through runtime
555+ metadata or overrides ``--nosocket=NAME, --unshare=NAME `` etc. can be
556+ used::
557+
558+ --nosocket=x11
559+
560+ This denial can be combined with conditional grants to remove
561+ unconditional access while allowing conditional access::
562+
563+ --nosocket=x11
564+ --socket=x11
565+ --socket-if=x11:!has-wayland
566+
567+ This denies unconditional X11 access but allows X11 conditionally when
568+ Wayland is unavailable. Older Flatpak versions will see only the final
569+ ``--socket=x11 `` grant and allow X11 unconditionally, while newer
570+ versions recognise the conditional logic and evaluates it at runtime.
571+
475572.. rubric :: Footnotes
476573
477574.. [#f1 ] This is not necessarily required, but without it the X11 shared
0 commit comments