Skip to content

Commit 5996469

Browse files
tonyandrewmeyererineconalithethird
authored
docs: add charm-user in the charmcraft.yaml file reference (#2195)
The `charm-user` field is documented in the metadata.yaml file reference, but is missing from the charmcraft.yaml file reference, even though it does work there. This PR adds it to that reference. As the docs currently are, it gives the incorrect impression that you cannot use the combined charmcraft.yaml file to specify `charm-user`, and must have separate metadata, actions, and config files. --------- Co-authored-by: Erin Conley <[email protected]> Co-authored-by: Ali UĞUR <[email protected]>
1 parent 6153055 commit 5996469

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

docs/reference/files/charmcraft-sample-charm.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ charm-libs:
4343
version: "1"
4444
- lib: mysql.mysql
4545
version: "0.5"
46+
charm-user: sudoer
4647
config:
4748
options:
4849
name:

docs/reference/files/charmcraft-yaml-file.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,42 @@ and the lib version (in ``"<api version>[.<patch version>]"`` string format).
346346

347347
.. literalinclude:: charmcraft-sample-charm.yaml
348348
:start-at: charm-libs:
349+
:end-before: charm-user:
350+
351+
352+
.. _charmcraft-yaml-key-charm-user:
353+
354+
``charm-user``
355+
--------------
356+
357+
.. important::
358+
359+
``charm-user`` was added in Juju 3.6.0. It's currently only supported by
360+
Kubernetes charms and has no effect on machine charms.
361+
362+
**Status:** Optional. Recommended for Kubernetes charms.
363+
364+
**Purpose:** The ``charm-user`` key allows charm authors to specify that their charm
365+
hook code does not need to be run as root. This key, in combination with ``uid`` + ``gid``
366+
fields in ``containers``, allows the charm to be run rootless. If set to ``root``,
367+
the charm runs as root. If set to ``sudoer`` or ``non-root``, the charm runs as a user
368+
other than root. If the value is ``sudoer``, the charm will be run as a user
369+
with access to sudo to elevate its privileges.
370+
371+
**Structure:** The key consists of a single value. One of ``root``, ``sudoer`` or
372+
``non-root``.
373+
374+
.. code-block:: yaml
375+
376+
# (Optional) What kind of user is required to run the charm code.
377+
# It can be one of root, sudoer or non-root.
378+
# Added in Juju 3.6.0. If not specified, root is assumed.
379+
charm-user: <one of root, sudoer or non-root>
380+
381+
**Example:**
382+
383+
.. literalinclude:: charmcraft-sample-charm.yaml
384+
:start-at: charm-user:
349385
:end-before: config:
350386

351387

docs/reference/files/metadata-yaml-file.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,17 +431,17 @@ Examples:
431431

432432
.. important::
433433

434-
``charm-user`` was added in Juju 3.6.0. Currently is only supported on Kubernetes
435-
charms and has no effect on machine charms.
434+
``charm-user`` was added in Juju 3.6.0. It's currently only supported by
435+
Kubernetes charms and has no effect on machine charms.
436436

437437
**Status:** Optional. Recommended for Kubernetes charms.
438438

439439
**Purpose:** The ``charm-user`` key allows charm authors to specify that their charm
440-
hook code does not need to be run as root. This key, in addition to ``uid`` + ``uid``
441-
fields in ``containers``, allows charms to be run rootless. The value of ``root``
442-
ensures the charm runs as root. Both ``sudoer`` and ``non-root`` will run as a user
443-
other than root. In the case of the value ``sudoer``, the charm will be run as a user
444-
with access to sudo to elevate it's privileges.
440+
hook code does not need to be run as root. This key, in combination with ``uid`` + ``gid``
441+
fields in ``containers``, allows the charm to be run rootless. If set to ``root``,
442+
the charm runs as root. If set to ``sudoer`` or ``non-root``, the charm runs as a user
443+
other than root. If the value is ``sudoer``, the charm will be run as a user
444+
with access to sudo to elevate its privileges.
445445

446446
**Structure:** The key consists of a single value. One of ``root``, ``sudoer`` or
447447
``non-root``.

tests/spread/smoketests/basic/charmcraft-platforms-24.04-all.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ parts:
1212
my-charm:
1313
plugin: charm
1414
source: .
15+
charm-user: sudoer
16+

0 commit comments

Comments
 (0)