@@ -47,6 +47,85 @@ stored once.
4747This `blog post <https://blogs.gnome.org/alexl/2017/10/02/on-application-sizes-and-bloat-in-flatpak/ >`_
4848explains the underlying structure of a Flatpak repository in more detail.
4949
50+ Conditional permission system
51+ -----------------------------
52+
53+ Since Flatpak 1.17.0, conditional permissions allow permissions to be
54+ granted only when certain runtime conditions are satisfied, with
55+ fallback to unconditional grants for compatibility with older versions.
56+
57+ Permissions are internally represented as:
58+
59+ - unconditionally allowed or denied
60+ - a reset flag indicating whether the current layer overrides rules
61+ from lower layers
62+ - a set of conditional rules under which the permission may be allowed
63+
64+ For example:
65+
66+ - ``--socket=NAME `` unconditionally allows the permission and resets any
67+ previously defined rules for that permission
68+ - ``--nosocket=NAME `` unconditionally denies the permission and resets
69+ any previously defined rules
70+ - ``--socket-if=NAME:CONDITION `` adds a conditional rule without
71+ resetting existing rules
72+
73+ Conditions may be negated using ``! ``.
74+
75+ Multiple conditional rules can be specified for the same permission. In
76+ this case, the permission is granted if any condition evaluates to true.
77+
78+ Duplicate conditions are ignored. The order of conditions does not
79+ affect evaluation.
80+
81+ If no conditional rules are present, the permission is granted only if
82+ it is unconditionally allowed.
83+
84+ If conditional rules are present, the permission is granted if any
85+ condition evaluates to true, and denied otherwise, unless it is also
86+ unconditionally allowed.
87+
88+ If an unconditional entry follows a conditional entry for the same
89+ grant in commandline flags, the earlier unconditional entry is treated
90+ as backwards compatibility fallback and does not affect the final
91+ permission state. So the following is effectively treated as
92+ ``--socket-if=x11:!has-wayland `` in Flatpak versions supporting
93+ conditional permissions::
94+
95+ --socket=x11
96+ --socket-if=x11:!has-wayland
97+
98+ Permissions are written to metadata using the following rules:
99+
100+ - Unconditionally allowed permissions are written as ``NAME ``
101+ - Unconditionally denied permissions are written as ``!NAME ``
102+ - Conditionally allowed permissions are written as:
103+
104+ - unconditional ``NAME `` entry for compat
105+ - ``if:NAME:CONDITION `` entries
106+
107+ If the permission resets previously defined rules, an explicit ``!NAME ``
108+ entry is written first, followed by the unconditional ``NAME `` entry and
109+ then the ``if:NAME:CONDITION `` entries. This is omitted when saving an
110+ application's own metadata, as opposed to overrides.
111+
112+ When parsing metadata, a non-negated unconditional ``NAME `` entry
113+ appearing before a ``if:NAME:CONDITION `` entry is treated as a
114+ compatibility fallback and does not affect the final permission
115+ state. Eg. ``sockets=x11;if:x11:!has-wayland; `` is effectively treated
116+ as ``if:x11:!has-wayland `` in Flatpak versions supporting
117+ conditional permissions.
118+
119+ The ``fallback-x11 `` socket, on pre-1.17 Flatpak versions implicitly
120+ granted ``x11 `` access and at runtime X11 access was suppressed when
121+ Wayland was available, while on newer Flatpak (1.17+) it is internally
122+ converted to the conditional syntax ``if:x11:!has-wayland ``. When saving
123+ the metadata, Flatpak converts ``if:x11:!has-wayland `` back to
124+ ``fallback-x11 `` only when it is the sole conditional on ``x11 ``. If
125+ additional conditionals are present, the new syntax is written directly
126+ and older Flatpak versions will not understand the conditional entries.
127+ A conditional grant for ``fallback-x11 `` is not allowed.
128+
50129Underlying technologies
51130-----------------------
52131
0 commit comments