Skip to content

fix(ug_util): prioritize user-data.users over the default user config#6860

Open
mostafaCamel wants to merge 2 commits intocanonical:mainfrom
mostafaCamel:eng/PR-6703
Open

fix(ug_util): prioritize user-data.users over the default user config#6860
mostafaCamel wants to merge 2 commits intocanonical:mainfrom
mostafaCamel:eng/PR-6703

Conversation

@mostafaCamel
Copy link
Copy Markdown
Contributor

@mostafaCamel mostafaCamel commented May 3, 2026

Proposed Commit Message

fix(ug_util): prioritize user-data.users over the default user config

Fixes GH-6703

Additional Context

Test Steps

.tox/py3/bin/python -m pytest -vv tests/unittests/distros/test_user_data_normalize.py::TestUGNormalize

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

… default user config

Signed-off-by: Mostafa Abdelwahab <mostafa.abdelwahab@canonical.com>
@mostafaCamel mostafaCamel changed the title Add unit test to test precedence behavior between user-data.users and… fix(ug_util): prioritize user-data.users over the default user config May 3, 2026
@mostafaCamel
Copy link
Copy Markdown
Contributor Author

mostafaCamel commented May 3, 2026

The first commit I pushed is failing as expected as I only added the unit test

The expected failure

TOTAL                                                          33026   6291  12224   1597    79%
=========================== short test summary info ============================
FAILED tests/unittests/distros/test_user_data_normalize.py::TestUGNormalize::test_users_dict_override_default_attribute - assert True is False
= 1 failed, 5641 passed, 5 skipped, 13 xfailed, 2 xpassed, 84 warnings in 118.45s (0:01:58) =
py3: exit 1 (129.32 seconds) /home/runner/work/cloud-init/cloud-init> .tox/py3/bin/python -m pytest -vv --cov=cloudinit --cov-branch --color=yes pid=2384
  py3: FAIL code 1 (135.99=setup[6.67]+cmd[129.32] seconds)
  evaluation failed :( (136.04 seconds)
Error: Process completed with exit code 1.

Signed-off-by: Mostafa Abdelwahab <mostafa.abdelwahab@canonical.com>
@mostafaCamel
Copy link
Copy Markdown
Contributor Author

#6703

@mostafaCamel
Copy link
Copy Markdown
Contributor Author

After pushing the code fix, all the unit tests now pass

Copy link
Copy Markdown
Member

@holmanb holmanb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an integration test.

@mostafaCamel
Copy link
Copy Markdown
Contributor Author

mostafaCamel commented May 6, 2026

Note to myself about the integration tests (will work on it the weekend):

  • Declare 2 contansts the python integration: a plain-text password and its hash
    • I first need to run openssl passwd -6 "yourplainpassword" on your terminal to generate the hash and pass it as a constant in the python script
  • 2 ubuntu lxc containers A (with cloud-config.users ["default", {"name": "ubuntu", "hashed_passwd": "superpassword"}]) and B (with cloud-config.users ["default", {"name": "ubuntu", "hashed_passwd": "superpassword", "lock_passwd": False}])
  • confirm that the 2 contianers are up and running ( I don't know if the test helpers have such a function... can skip it given the following steps)
  • grep -E "^ubuntu:!<hashedpassword>: /etc/shadow for container A (and that there is only one occurence) ... notice the exclamation amrk as it indicates the password is locked
  • grep -E "^ubuntu:!<hashedpassword>: /etc/shadow for container B (and that there is only one occurence)
    • No need to confirm there is there is only one occurrence in grep as ^ubuntu: is enough as usernames are unique
  • Console access to container A should fail
  • Console access to container B should succeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants