Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_passwords: support for FreeBSD #46

Merged
merged 5 commits into from Nov 26, 2019

Conversation

igalic
Copy link
Collaborator

@igalic igalic commented Nov 14, 2019

Add FreeBSD support to cc_set_passwords.
FreeBSD does not come with chpasswd binary, a chpasswd port1 exists
but it's not the same tool than the one from Linux2.

Finally, NetBSD and OpenBSD don't have the chpasswd binary at all, so
an abstraction layer will be needed.

@igalic
Copy link
Collaborator Author

igalic commented Nov 14, 2019

migrated from https://code.launchpad.net/~goneri/cloud-init/+git/cloud-init/+merge/368507
(I'm not seeing a bug for this in launchpad)

from what i understand from @blackboxsw's comment here we still want to have his patch on top of it.

@goneri
Copy link
Contributor

goneri commented Nov 14, 2019

The best is probably to use @blackboxsw patch directly.

The www/chpasswd utility which we depended on for FreeBSD installations
does *not* do the same thing as the equally named Linux utility.

For FreeBSD, we now use the pw(8) utility (which can only process one
user at a time)

Additionally, we abstract expire passwd into a function, and override it
in the FreeBSD distro class.
@igalic
Copy link
Collaborator Author

igalic commented Nov 14, 2019

replaced @goneri's patch with @blackboxsw's.

@igalic
Copy link
Collaborator Author

igalic commented Nov 14, 2019

failing tests:

======================================================================
FAIL: test_no_stages_errors (tests.cloud_tests.testcases.modules.set_password_list.TestPasswordList)
Ensure that there were no errors in any stage.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/canonical/cloud-init/tests/cloud_tests/testcases/base.py", line 137, in test_no_stages_errors
    .format(status[stage]['errors'], stage))
AssertionError: 1 != 0 : errors ["('set-passwords', IndexError('list index out of range',))"] were encountered in stage modules-config

======================================================================
FAIL: test_no_warnings_in_log (tests.cloud_tests.testcases.modules.set_password_list.TestPasswordList)
Unexpected warnings should not be found in the log.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/canonical/cloud-init/tests/cloud_tests/testcases/base.py", line 154, in test_no_warnings_in_log
    [], warnings, msg="'WARN' found inside cloud-init.log")
AssertionError: Lists differ: [] != ["2019-11-14 21:44:02,739 - util.py[WARNIN[272 chars]led"]

Second list contains 2 additional elements.
First extra element 0:
2019-11-14 21:44:02,739 - util.py[WARNING]: Failed to set passwords with chpasswd for ['tom', 'dick', 'harry']

- []
+ ['2019-11-14 21:44:02,739 - util.py[WARNING]: Failed to set passwords with '
+  "chpasswd for ['tom', 'dick', 'harry']",
+  '2019-11-14 21:44:02,844 - util.py[WARNING]: Running module set-passwords '
+  "(<module 'cloudinit.config.cc_set_passwords' from "
+  "'/usr/lib/python3/dist-packages/cloudinit/config/cc_set_passwords.py'>) "
+  'failed'] : 'WARN' found inside cloud-init.log

======================================================================
FAIL: test_shadow_passwords (tests.cloud_tests.testcases.modules.set_password_list.TestPasswordList)
Test shadow passwords.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/canonical/cloud-init/tests/cloud_tests/testcases/base.py", line 309, in test_shadow_passwords
    self.assertEqual(tom_enc, users['tom'])
AssertionError: '$1$S7$bM0noe0bA4njfOL4JNiZy/' != '$1$S7$tT1BEDIYrczeryDQJfdPe0'
- $1$S7$bM0noe0bA4njfOL4JNiZy/
+ $1$S7$tT1BEDIYrczeryDQJfdPe0


----------------------------------------------------------------------
Ran 8 tests in 0.005s

FAILED (failures=3, skipped=2)
2019-11-14 21:44:27,872 - tests.cloud_tests - WARNING - test case: modules/set_password_list failed TestPasswordList.test_no_stages_errors with: AssertionError: 1 != 0 : errors ["('set-passwords', IndexError('list index out of range',))"] were encountered in stage modules-config
2019-11-14 21:44:27,872 - tests.cloud_tests - WARNING - test case: modules/set_password_list failed TestPasswordList.test_no_warnings_in_log with: +  'failed'] : 'WARN' found inside cloud-init.log
2019-11-14 21:44:27,872 - tests.cloud_tests - WARNING - test case: modules/set_password_list failed TestPasswordList.test_shadow_passwords with: 
2019-11-14 21:44:27,872 - tests.cloud_tests - DEBUG - verifying test data for modules/user_groups

Copy link
Collaborator Author

@igalic igalic left a comment

Choose a reason for hiding this comment

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

possible cause for one of the test failures

@@ -179,20 +179,19 @@ def handle(_name, cfg, cloud, log, args):
for line in plist:
u, p = line.split(':', 1)
if prog.match(p) is not None and ":" not in p:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this means you can't have a : in your password

cloudinit/config/cc_set_passwords.py Show resolved Hide resolved
randlist.append("%s:%s" % (u, p))
plist_in.append("%s:%s" % (u, p))
randlist.append(line)
plist_in.append(line)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is not reflected in these lists

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this hunk is now reverted

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Minor changeset should resolve that integration test failure

cloudinit/config/cc_set_passwords.py Outdated Show resolved Hide resolved
when `hashed` was false, the entire `cmd` is turned into `[]`.

Co-Authored-By: Chad Smith <blackboxsw@gmail.com>
@igalic
Copy link
Collaborator Author

igalic commented Nov 26, 2019

huh? i am honestly surprised you're passes now

perhaps i need to add a test for random passwords

Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

Thank you for this work and additional unit tests.

@blackboxsw blackboxsw merged commit b6055c4 into canonical:master Nov 26, 2019
@igalic igalic deleted the fix/fbsd-set_passwords branch November 26, 2019 16:56
paride pushed a commit to paride/cloud-init that referenced this pull request Nov 29, 2019
Allow setting of user passwords on FreeBSD

The www/chpasswd utility which we depended on for FreeBSD installations
does *not* do the same thing as the equally named Linux utility.

For FreeBSD, we now use the pw(8) utility (which can only process one
user at a time)

Additionally, we abstract expire passwd into a function, and override it
in the FreeBSD distro class.

Co-Authored-By: Chad Smith <chad.smith@canonical.com>
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.

None yet

3 participants