Bug 2103933

Summary: osbuild-composer cannot add a user with a given gid
Product: Red Hat Enterprise Linux 8 Reporter: Christophe Besson <cbesson>
Component: osbuild-composerAssignee: Image Builder team <osbuilders>
Status: MODIFIED --- QA Contact: Release Test Team <release-test-team>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.6CC: amepatil, atodorov, obudai, prjagtap, sbarcomb, sujagtap, thozza
Target Milestone: rcKeywords: Reproducer, Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: osbuild-composer-82-1.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christophe Besson 2022-07-05 10:24:23 UTC
Description of problem:
The documentation mentions we can specify a GID but it does not work.
"""
The GID is optional and must already exist in the image, be created by a package, or be created by the blueprint [[customizations.group]] entry. 
"""

Version-Release number of selected component (if applicable):
osbuild-composer-46.3-1.el8_6.x86_64
osbuild-53-2.el8.noarch

How reproducible:
Always

Steps to Reproduce:
1. Push the below blueprint

name = "unexisting-group"
description = "reproducer unexisting group"
version = "0.0.1"
modules = []
groups = []
distro = ""

[[customizations.group]]
name = "foo"
gid = 9045

[[customizations.user]]
name = "foo"
description = "foo user"
password = "$6$R4EexOTlkvDDwsK8$WkL4pU.JGHSO9LmpI/SMKYbunZU.t7BYLsZs1B9m0SeOH4RBICGlbScNRl0jUri3CBwasAd/sdZMkDp4SGoBq."
home = "/home/foo"
shell = "/usr/bin/bash"
groups = ["foo", "wheel"]
uid = 9045
gid = 9045

2. Compose an image


Actual results:
# composer-cli compose log ca09da9b-2e1f-4d0d-84d6-42d2c767c052 | tail -n17
Stage org.osbuild.users
Output:
[/usr/lib/tmpfiles.d/journal-nocow.conf:26] Failed to resolve specifier: uninitialized /etc detected, skipping
All rules containing unresolvable specifiers will be skipped.
useradd: group '9045' does not exist
Traceback (most recent call last):
  File "/run/osbuild/bin/org.osbuild.users", line 171, in <module>
    r = main(args["tree"], args["options"])
  File "/run/osbuild/bin/org.osbuild.users", line 160, in main
    useradd(tree, name, uid, gid, groups, description, home, shell, password)
  File "/run/osbuild/bin/org.osbuild.users", line 103, in useradd
    subprocess.run(["chroot", root, "useradd", *arguments, name], check=True)
  File "/usr/lib64/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['chroot', '/run/osbuild/tree', 'useradd', '--uid', '9045', '-o', '--gid', '9045', '--groups', 'foo,wheel', '--comment', 'foo user', '--home-dir', '/home/foo', '--create-home', '--shell', '/usr/bin/bash', '--password', '$6$R4EexOTlkvDDwsK8$WkL4pU.JGHSO9LmpI/SMKYbunZU.t7BYLsZs1B9m0SeOH4RBICGlbScNRl0jUri3CBwasAd/sdZMkDp4SGoBq.', 'foo']' returned non-zero exit status 6.

Expected results:
org.osbuild.groups executed before org.osbuild.users ?

Comment 3 Ondřej Budai 2022-11-21 13:19:45 UTC
The group's name currently cannot be the same as the name of the user. Is there an option for you to omit the group customization entirely? The group "foo" should be created anyway, because it's the primary group for the user "foo".