diff mbox series

[1/6] devtool/deploy: warn when deploying a recipe with dynamic UID/GID

Message ID 20260406221133.2769152-2-adrian.freihofer@siemens.com
State New
Headers show
Series ide-sdk: various fixes | expand

Commit Message

AdrianF April 6, 2026, 10:10 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

When a recipe inherits useradd.bbclass but does not use
useradd-staticids, pseudo assigns arbitrary UID/GID values during the
build. Package preinst scripts normally handle this by running
useradd/groupadd on the target and then chowning the installed files to
the correct IDs. devtool deploy-target skips those preinst scripts, so
any deployed files that have non-root ownership will land on the target
with the wrong ownership, silently.

Add a warning to deploy() that fires when USERADD_PACKAGES is set and
'useradd-staticids' is absent from USERADDEXTENSION. The warning names
the affected users and groups to make it actionable.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 scripts/lib/devtool/deploy.py | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/scripts/lib/devtool/deploy.py b/scripts/lib/devtool/deploy.py
index 270e9104b2..7866cfbaae 100644
--- a/scripts/lib/devtool/deploy.py
+++ b/scripts/lib/devtool/deploy.py
@@ -157,6 +157,38 @@  def deploy(args, config, basepath, workspace):
         max_process = oe.utils.get_bb_number_threads(rd)
         fakerootcmd = rd.getVar('FAKEROOTCMD')
         fakerootenv = rd.getVar('FAKEROOTENV')
+
+        # Warn if the recipe creates users/groups without static IDs.
+        # Without useradd-staticids, pseudo assigns arbitrary UIDs/GIDs during
+        # the build. The target preinst scripts would normally re-create them
+        # with correct IDs and chown the files, but devtool deploy-target skips
+        # those scripts, so deployed files will have the wrong ownership.
+        useradd_packages = rd.getVar('USERADD_PACKAGES') or ''
+        if useradd_packages:
+            useraddextension = (rd.getVar('USERADDEXTENSION') or '').split()
+            if 'useradd-staticids' not in useraddextension:
+                users = set()
+                groups = set()
+                for pkg in useradd_packages.split():
+                    for param in (rd.getVar('USERADD_PARAM:%s' % pkg) or '').split(';'):
+                        param = param.strip().split()
+                        if param:
+                            users.add(param[-1])
+                    for param in (rd.getVar('GROUPADD_PARAM:%s' % pkg) or '').split(';'):
+                        param = param.strip().split()
+                        if param:
+                            groups.add(param[-1])
+                if users or groups:
+                    items = []
+                    if users:
+                        items.append('users: %s' % ', '.join(sorted(users)))
+                    if groups:
+                        items.append('groups: %s' % ', '.join(sorted(groups)))
+                    logger.warning('Recipe %s creates %s without static UID/GID '
+                                   'assignments (USERADDEXTENSION does not include '
+                                   '"useradd-staticids"). Deployed files may have '
+                                   'incorrect ownership on the target.'
+                                   % (args.recipename, ' and '.join(items)))
     finally:
         tinfoil.shutdown()