user_add silently ignores numeric uid

Bug #1875772 reported by eric gundrum
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Fix Released
High
Unassigned

Bug Description

Given content of 'user-data' such as
```
users:
  - default
  - name: eric
    uid: 1742
  - name: archivist
    uid: '1724'
```
the created account as listed in '/etc/passwd' are
```
eric:x:1000:1000::/home/eric:/bin/bash
archivist:x:1724:1724::/home/archivist:/bin/bash
ubuntu:x:1725:1725:Ubuntu:/home/ubuntu:/bin/bash
```

Notice that account 'eric' has `uid=1000` even though the 'user-data' config specifies `uid: 1742`. No error, warning or other obvious message appears in 'cloud-init.log'.

The relevant source code appears to begin around [line 458 of cloudinit/distros/__init__.py](https://github.com/canonical/cloud-init/blob/7276aa5240b8cb84671a56d795d811f15dfba8e2/cloudinit/distros/__init__.py#L458): `if key in useradd_opts and val and isinstance(val, str)`.

The ubuntu image where this occurs is `ubuntu-20.04-preinstalled-server-arm64+raspi.img.xz`; although I expect it exists everywhere cloud-init version 20.1 is used.

A moderately helpful fix is to add error reporting to the conditional when `isinstance(val, str)` fails. A more user-friendly fix is to simply convert `val` to a string.

Revision history for this message
eric gundrum (ericgundrum) wrote :
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks for filing the bug.

Changed in cloud-init (Ubuntu):
importance: Undecided → High
status: New → Triaged
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 22.1-14-g2e17a0d6-0ubuntu1~22.04.1

---------------
cloud-init (22.1-14-g2e17a0d6-0ubuntu1~22.04.1) jammy; urgency=medium

  * debian/apport-launcher.py: Fix string and whitespace formatting
  * New upstream snapshot.
    - check for existing symlink while force creating symlink (#1281)
      [Shreenidhi Shedi]
    - Do not silently ignore integer uid (#1280) (LP: #1875772)
    - tests: create a IPv4/IPv6 VPC in Ec2 integration tests (#1291)
    - Integration test fix ppa (#1296)
    - tests: on official EC2. cloud-id actually startswith aws not ec2 (#1289)
    - test_ppa_source: accept both http and https URLs (#1292)
      [Paride Legovini]
    - Fix apt test on azure
    - add "lkundrak" as contributor [Lubomir Rintel]
    - Holmanb/integration test fix ppa (#1287)
    - Include missing subcommand in manpage (#1279)
    - Clean up artifacts from pytest, packaging, release with make clean
      (#1277)
    - sources/azure: ensure retries on IMDS request failure (#1271)
      [Chris Patterson]
    - sources/azure: removed unused saveable PPS paths (#1268)
      [Chris Patterson]

 -- Brett Holman <email address hidden> Thu, 24 Feb 2022 16:40:00 -0700

Changed in cloud-init (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.