summaryrefslogtreecommitdiff
path: root/Documentation/kdbus/kdbus.policy.xml
blob: 67324163880a6c62fcaf9945827f4f24fbe28b4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<refentry id="kdbus.policy">

  <refentryinfo>
    <title>kdbus.policy</title>
    <productname>kdbus.policy</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>kdbus.policy</refentrytitle>
    <manvolnum>7</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>kdbus.policy</refname>
    <refpurpose>kdbus policy</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Description</title>

    <para>
      A kdbus policy restricts the possibilities of connections to own, see and
      talk to well-known names. A policy can be associated with a bus (through a
      policy holder connection) or a custom endpoint. kdbus stores its policy
      information in a database that can be accessed through the following
      ioctl commands:
    </para>

    <variablelist>
      <varlistentry>
        <term><constant>KDBUS_CMD_HELLO</constant></term>
        <listitem><para>
          When creating, or updating, a policy holder connection. See
          <citerefentry>
            <refentrytitle>kdbus.connection</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><constant>KDBUS_CMD_ENDPOINT_MAKE</constant></term>
        <term><constant>KDBUS_CMD_ENDPOINT_UPDATE</constant></term>
        <listitem><para>
          When creating, or updating, a bus custom endpoint. See
          <citerefentry>
            <refentrytitle>kdbus.endpoint</refentrytitle>
            <manvolnum>7</manvolnum>
          </citerefentry>.
        </para></listitem>
      </varlistentry>
    </variablelist>

    <para>
      In all cases, the name and policy access information is stored in items
      of type <constant>KDBUS_ITEM_NAME</constant> and
      <constant>KDBUS_ITEM_POLICY_ACCESS</constant>. For this transport, the
      following rules apply.
    </para>

    <itemizedlist>
      <listitem>
        <para>
          An item of type <constant>KDBUS_ITEM_NAME</constant> must be followed
          by at least one <constant>KDBUS_ITEM_POLICY_ACCESS</constant> item.
        </para>
      </listitem>

      <listitem>
        <para>
          An item of type <constant>KDBUS_ITEM_NAME</constant> can be followed
          by an arbitrary number of
          <constant>KDBUS_ITEM_POLICY_ACCESS</constant> items.
        </para>
      </listitem>

      <listitem>
        <para>
          An arbitrary number of groups of names and access levels can be given.
        </para>
      </listitem>
    </itemizedlist>

    <para>
      Names passed in items of type <constant>KDBUS_ITEM_NAME</constant> must
      comply to the rules of valid kdbus.name. See
      <citerefentry>
        <refentrytitle>kdbus.name</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for more information.

      The payload of an item of type
      <constant>KDBUS_ITEM_POLICY_ACCESS</constant> is defined by the following
      struct. For more information on the layout of items, please refer to
      <citerefentry>
        <refentrytitle>kdbus.item</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>.
    </para>

    <programlisting>
struct kdbus_policy_access {
  __u64 type;
  __u64 access;
  __u64 id;
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>type</varname></term>
        <listitem>
          <para>
            One of the following.
          </para>

          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_POLICY_ACCESS_USER</constant></term>
              <listitem><para>
                Grant access to a user with the UID stored in the
                <varname>id</varname> field.
              </para></listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_POLICY_ACCESS_GROUP</constant></term>
              <listitem><para>
                Grant access to a user with the GID stored in the
                <varname>id</varname> field.
              </para></listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_POLICY_ACCESS_WORLD</constant></term>
              <listitem><para>
                Grant access to everyone. The <varname>id</varname> field
                is ignored.
              </para></listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>access</varname></term>
        <listitem>
          <para>
            The access to grant. One of the following.
          </para>

          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_POLICY_SEE</constant></term>
              <listitem><para>
                Allow the name to be seen.
              </para></listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_POLICY_TALK</constant></term>
              <listitem><para>
                Allow the name to be talked to.
              </para></listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_POLICY_OWN</constant></term>
              <listitem><para>
                Allow the name to be owned.
              </para></listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>id</varname></term>
        <listitem><para>
           For <constant>KDBUS_POLICY_ACCESS_USER</constant>, stores the UID.
           For <constant>KDBUS_POLICY_ACCESS_GROUP</constant>, stores the GID.
        </para></listitem>
      </varlistentry>

    </variablelist>

    <para>
      All endpoints of buses have an empty policy database by default.
      Therefore, unless policy rules are added, all operations will also be
      denied by default. Also see
      <citerefentry>
        <refentrytitle>kdbus.endpoint</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>.
    </para>
  </refsect1>

  <refsect1>
    <title>Wildcard names</title>
    <para>
      Policy holder connections may upload names that contain the wildcard
      suffix (<literal>".*"</literal>). Such a policy entry is effective for
      every well-known name that extends the provided name by exactly one more
      level.

      For example, the name <literal>foo.bar.*</literal> matches both
      <literal>"foo.bar.baz"</literal> and
      <literal>"foo.bar.bazbaz"</literal> are, but not
      <literal>"foo.bar.baz.baz"</literal>.

      This allows connections to take control over multiple names that the
      policy holder doesn't need to know about when uploading the policy.

      Such wildcard entries are not allowed for custom endpoints.
    </para>
  </refsect1>

  <refsect1>
    <title>Privileged connections</title>
    <para>
      The policy database is overruled when action is taken by a privileged
      connection. Please refer to
      <citerefentry>
        <refentrytitle>kdbus.connection</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for more information on what makes a connection privileged.
    </para>
  </refsect1>

  <refsect1>
    <title>Examples</title>
    <para>
      For instance, a set of policy rules may look like this:
    </para>

    <programlisting>
KDBUS_ITEM_NAME: str='org.foo.bar'
KDBUS_ITEM_POLICY_ACCESS: type=USER, access=OWN, ID=1000
KDBUS_ITEM_POLICY_ACCESS: type=USER, access=TALK, ID=1001
KDBUS_ITEM_POLICY_ACCESS: type=WORLD, access=SEE

KDBUS_ITEM_NAME: str='org.blah.baz'
KDBUS_ITEM_POLICY_ACCESS: type=USER, access=OWN, ID=0
KDBUS_ITEM_POLICY_ACCESS: type=WORLD, access=TALK
    </programlisting>

    <para>
      That means that 'org.foo.bar' may only be owned by UID 1000, but every
      user on the bus is allowed to see the name. However, only UID 1001 may
      actually send a message to the connection and receive a reply from it.

      The second rule allows 'org.blah.baz' to be owned by UID 0 only, but
      every user may talk to it.
    </para>
  </refsect1>

  <refsect1>
    <title>TALK access and multiple well-known names per connection</title>
    <para>
      Note that TALK access is checked against all names of a connection. For
      example, if a connection owns both <constant>'org.foo.bar'</constant> and
      <constant>'org.blah.baz'</constant>, and the policy database allows
      <constant>'org.blah.baz'</constant> to be talked to by WORLD, then this
      permission is also granted to <constant>'org.foo.bar'</constant>. That
      might sound illogical, but after all, we allow messages to be directed to
      either the ID or a well-known name, and policy is applied to the
      connection, not the name. In other words, the effective TALK policy for a
      connection is the most permissive of all names the connection owns.

      For broadcast messages, the receiver needs TALK permissions to the sender
      to receive the broadcast.
    </para>
    <para>
      Both the endpoint and the bus policy databases are consulted to allow
      name registry listing, owning a well-known name and message delivery.
      If either one fails, the operation is failed with
      <varname>errno</varname> set to <constant>EPERM</constant>.

      For best practices, connections that own names with a restricted TALK
      access should not install matches. This avoids cases where the sent
      message may pass the bloom filter due to false-positives and may also
      satisfy the policy rules.

      Also see
      <citerefentry>
        <refentrytitle>kdbus.match</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>.
    </para>
  </refsect1>

  <refsect1>
    <title>Implicit policies</title>
    <para>
      Depending on the type of the endpoint, a set of implicit rules that
      override installed policies might be enforced.

      On default endpoints, the following set is enforced and checked before
      any user-supplied policy is checked.
    </para>

    <itemizedlist>
      <listitem>
        <para>
          Privileged connections always override any installed policy. Those
          connections could easily install their own policies, so there is no
          reason to enforce installed policies.
        </para>
      </listitem>
      <listitem>
        <para>
          Connections can always talk to connections of the same user. This
          includes broadcast messages.
        </para>
      </listitem>
    </itemizedlist>

    <para>
      Custom endpoints have stricter policies. The following rules apply:
    </para>

    <itemizedlist>
      <listitem>
        <para>
          Policy rules are always enforced, even if the connection is a
          privileged connection.
        </para>
      </listitem>
      <listitem>
        <para>
          Policy rules are always enforced for <constant>TALK</constant> access,
          even if both ends are running under the same user. This includes
          broadcast messages.
        </para>
      </listitem>
      <listitem>
        <para>
          To restrict the set of names that can be seen, endpoint policies can
          install <constant>SEE</constant> policies.
        </para>
      </listitem>
    </itemizedlist>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <simplelist type="inline">
      <member>
        <citerefentry>
          <refentrytitle>kdbus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.bus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.endpoint</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.fs</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.item</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.message</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.name</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.pool</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
    </simplelist>
  </refsect1>
</refentry>