38 Commits

Author SHA1 Message Date
Veiko Aasa
f892843ba5
syncthing: Create LDAP group name different from system group
When installing the syncthing app, create a LDAP group named "syncthing-access"
instead of "syncthing", because the app creates the "syncthing" system group
to run the syncthing daemon. Duplicate group names can cause some ambiguity as
described in #2008.

- Rename the existing "syncthing" LDAP and Django group to "syncthing-access".
- Update existing web shares to be accessible with new group name
- Functional tests: Add tests to check access to the syncthing site with a user
in the syncthing-access group and no group.
- Functional tests: Scroll to the edit button before clicking. Fixes some test
failures on a smaller browser window.

Fixes #2008

Tests performed on Debian stable and testing:

- Check that the existing "syncthing" group is renamed after upgrade:
1) Without patch applied, install syncthing, create a user in group "syncthing".
2) Apply patch, update Apache2 config file /etc/apache2/conf-available/syncthing-plinth.conf,
reload Apache2, restart plinth.
3) Check that the created user is now in the "syncthing-access" group and can
access /syncthing site.

- Check that the app upgrade succeeds when there are no users in the syncthing group.

- Create a web share accessible by the 'syncthing' group. Check that after the upgrade,
the share is accessible to a member of syncthing-access group.

- All the syncthing app tests pass.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-01-21 15:47:12 -08:00
Veiko Aasa
0255058656
users: Remove timeout when creating Samba user
Fixes #2000

Tests performed:
- All the users module tests pass
- Create a user, add the user to the freedombox-share group,
check that the user can connect to the Samba Group share.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-12-26 12:59:08 -05:00
Veiko Aasa
dfaf009d3c
users: Require admin credentials when creating or editing a user
This change prevents the plinth user to become a superuser without
knowing an admin password.

Users module and action script:
- User credentials are now required for the subcommands: create-user,
  set-user-password, add-user-to-group (if the group is admin),
  remove-user-from-group (if the group is admin), set-user-status,
  remove-user (if the removed user is the last admin user.
  Note: the web UI doesn't allow to delete last admin user).
- subcommand remove-users requires authentication if the user is last
  admin user. Password must be provided through standard input.
- subcommand remove-group: do not allow to remove group 'admin'
- User credentials must be provided using the argument
  --auth-user and a passsword must be provided through standard input.
- If there are no users in the admin group, no admin password is
  required and if the --auth-user argument is required, it can be an
  empty string.

Users web UI:
- An admin needs to enter current password to create and edit a user
  and to change user's password.
- Show more detailed error text on exceptions when submitting forms.
- Show page title on the edit and create user pages.

Users unit and functional tests:
- Added a configuration parameters to the pytest configuration file
  to set current admin user/password.
- Added a configuration parameter 'ssh_port' to the functional tests.
  You can overwrite this with the FREEDOMBOX_SSH_PORT environment
  variable. Modified HACKING.md accordingly.
- Added an unit test:
     - test changing the password as a non-admin user.
     - test invalid admin password input.
     - test that removing the admin group fails.
- Capture stdout and stderr in the unit tests when calling an action
  script to be able to see more info on exceptions.
- Added functional tests for setting ssh keys and changing passwords
  for admin and non-admin users.
- Added a functional test for setting a user as active/inactive.

Changes during review [sunil]:
- Move uncommon functional step definitions to users module from global. This is
  keep the common functional step definitions to minimal level and promote when
  needed.
- Minor styling changes, flake8 fixes.
- Don't require pampy module when running non-admin tests. This allows tests to
  be run from outside the container on the host machine without python3-pam
  installed.
- Call the confirm password field 'Authorization Password'. This avoid confusion
  with a very common field 'Confirm Password' which essentially means retype
  your password to ensure you didn't get it wrong. Add label explaining why the
  field exists.
- Don't hard-code /tmp path in test_actions.py. Use tmp_path_factory fixture
  provided by pytest.
- Remove unused _get_password_hash() from actions/users.
- Undo splitting ldapgid output before parsing. It does not seem correct and
  could introduce problems when field values contain spaces.

Tests performed:
- No failed unit tests (run with and without sudo).
- All 'users' functional tests pass.
- Creating an admin user during the first boot wizard succeeds.
- Creating a user using the web UI with an empty or wrong admin
  password fails and with the correct admin password succeeds.
- Editing a user using the web UI with an empty or wrong admin
  password fails and with the correct admin password succeeds.
- Changing user's password using the web UI with an empty or wrong
  admin password fails and with the correct admin password succeeds.
- Above mentioned user action script commands can't be run without
  correct credentials.
- Adding the daemon user to the freedombox-share group succeeds when
  installing certain apps (deluge, mldonkey, syncthing, transmission).

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Move uncommon functional step definitions to users module from global]
[sunil: Minor styling changes, flake8 fixes]
[sunil: Don't require pampy module when running non-admin tests]
[sunil: Call the confirm password field 'Authorization Password']
[sunil: Don't hard-code /tmp path in test_actions.py]
[sunil: Remove unused _get_password_hash() from actions/users]
[sunil: Undo splitting ldapgid output before parsing]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-05 00:05:44 -07:00
James Valleroy
1aaf5efb52
users: Avoid error when user's groups cannot be parsed
Add log warnings to help debug if there is a related issue.

May help #1834.

Tested:
- Run action command with valid and invalid username. Warning is printed for
  invalid username.
- Modify the output to remove '='. Warning is printed instead of exception.
- Ensure that warnings messages are output to stderr and not stdout.
- On frontpage.py change the call to get user groups and ensure that that output
  warning messages are not parsed groups.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Drop module logger as root logger is at use]
[sunil: Use %s formatting for logging API]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-05-29 13:01:16 -07:00
Sunil Mohan Adapa
eada506b23
actions/*: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:39:36 +02:00
Veiko Aasa
aa2aa56c46
users: Add tests for the Samba user database
Fix: after renaming a user delete old username from the Samba password database

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-29 16:59:04 -05:00
Veiko Aasa
83cb305026
samba: private shares
- new share types - group and home shares
- users: when creating, deleting or changing user password, update also Samba
  tdbsam backend database
- users: new managed packages - samba-common-bin, tdb-tools
- module page: show current samba users who are in freedombox-share group
- module page: show users who should re-enter their password in the password change page
- fix: use os.path.ismount() from Python standard library to validate a mount point
- fix: samba share permissions, fixes #1729
- fix: delete a share - do not raise an exception if the share doesn't exist
- storage: show samba share type in the directory selection form

Closes #1727

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-20 21:01:12 -05:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Veiko Aasa
b86f3ff675
users: reload Apache2 to flush LDAP cache after user operations
Fixes #1660

Signed-off-by: Veiko Aasa veiko17@disroot.org
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-10-20 11:50:36 -04:00
Veiko Aasa
ed646d84a5
actions: Check with flake8
Also fix flake8 warnings.

Closes: #1613

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil@medhas.org split multi strings differently to avoid spaces]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-10-10 19:08:45 -07:00
Sunil Mohan Adapa
caa266e348
users: Don't fail badly when admin group does not exist
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-08-25 15:52:08 -04:00
Sunil Mohan Adapa
7499b687c8
users: yapf cosmetic changes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-08-25 15:52:00 -04:00
Joseph Nuthalapati
a50b40ee56
Change get-group-users to a simpler implementation
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-07-04 08:28:51 -04:00
Hemanth Kumar Veeranki
b9963a45cd
Restrict removal of last admin user
- Don't allow disabling the only available admin account.
- Don't allow deletion of the only available admin account.
- Don't allow removing admin privileges of the only available admin account.

Signed-off-by: Hemanth Kumar Veeranki <hems.india1997@gmail.com>
Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
2018-06-21 20:09:02 +05:30
Sunil Mohan Adapa
90f2117554
Rename Plinth to FreedomBox in comments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:45 -05:00
Sunil Mohan Adapa
dea4af17fb
Rename Plinth to FreedomBox in license headers
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2018-02-16 20:10:09 -05:00
Sunil Mohan Adapa
2d17f19ae2
users: Add a note about using separate first setup action
Instead of a separate action that is conditionally called for a version number,
we can check if the domain currently configured is what we want and then based
on the value do a reconfiguration. This approach will work better when Plinth
state is reset etc.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-12-14 11:43:23 +05:30
James Valleroy
87eecb7c62
users: Handle upgrade for ldapscripts config
Increment users module version so existing users will get FreedomBox
copy of ldapscripts config file.

Avoid reconfiguration of slapd during module upgrade, because this
will move the existing database.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-12-14 11:43:07 +05:30
James Valleroy
4cbb60ccfe
users: Use own copy of ldapscripts config
Avoid modifying the conffile shipped with ldapscripts.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-12-14 11:42:51 +05:30
Joseph Nuthalapati
32b2ef38c7
Fixes for user groups
- Edit user form fails because a 'wiki' group entry exists in the database
  though the ikiwiki app hasn't been installed yet.
- Register group when a user group is created by an application, so that a
  plinth restart can be avoided.

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-12-10 19:09:58 -05:00
Joseph Nuthalapati
7ce5d1f636
groups: User permissions for access to apps based on LDAP groups
- More user-friendly treatment of groups and their permissions

Closes #690

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-12-10 19:09:55 -05:00
Joseph Nuthalapati
2f67fb49d4
Add framework for user groups per application
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-12-10 19:09:17 -05:00
Sunil Mohan Adapa
7327a6b803
users: After setup, enable and restart slapd and nslcd
Apply the patch present in Debian packaging:

James Valleroy: When testing new image builds, I found users created through
plinth could not login through console or SSH. The reason is that slapd and
nslcd services were not enabled and not running. I don't know what is causing
this situation, so this is just a workaround.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-11-03 18:33:11 +05:30
Sunil Mohan Adapa
ccfe511e4c
users: Minor refactoring
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-10-17 17:39:42 +05:30
Joseph Nuthalpati
396e086727
users: Migrate ldap bash script into actions/users
- Also wrote unit tests in users/tests/test_actions

Signed-off-by: Joseph Nuthalpati <njoseph@thoughtworks.com>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-10-17 09:25:14 +05:30
Sunil Mohan Adapa
56b071858b
users: Restart nscd after setup
The changes made for system login will not be effective until a restart. This
includes SSH login, console login, getent answers, etc.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2017-10-07 07:08:27 -04:00
Sunil Mohan Adapa
e558cdc1e4
users: Keep safety check to start slapd during setup
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-08-29 17:09:10 +05:30
James Valleroy
b19a9f972c
users: Move ldap structure config into normal setup
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-08-29 17:08:09 +05:30
Johannes Keyser
634afef1c9
actions: Make subparsers mandatory, fixes calls without arguments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2017-04-10 11:54:23 +05:30
James Valleroy
1aa767e6bd
users: Move part of LDAP setup to first-run
LDAP admin and basic structure setup requires running slapd. Move this
to first-run so we don't have to start slapd during setup. This should
avoid issues when running setup in a chroot.
2017-01-18 18:40:03 -05:00
Sunil Mohan Adapa
8e28afe160
users: Move dpkg reconfigure to action utils
In the hope that it will be useful to other actions.  Also delete the
named temporary file after configuration.
2016-07-31 10:58:07 +05:30
James Valleroy
6c3d3888c1
Use NamedTemporaryFile for debconf override db 2016-07-30 08:49:37 +05:30
James Valleroy
956416ef37
Configure users module packages after installation
Preseeding settings with debconf won't have any effect if the packages
are already installed. Instead, provide an override database to
dpkg-reconfigure.
2016-07-30 08:49:22 +05:30
James Valleroy
8e96e828d9
security: New module to control login restrictions 2016-07-09 22:41:21 +05:30
James Valleroy
ef40941c7c
Fix quoted values in nslcd config 2016-06-14 06:57:28 -04:00
Sunil Mohan Adapa
f68a757741
users: Reorganize and make idempotent ldap setup
- Break down setup process into methods.

- Make sure that LDAP entity setup is idempotent.

- Peform all entry updates while slapd is running instead of using
  slapadd.

- Start slapd only when necessary.  Shutdown (only) if we have started
  slapd.
2016-05-21 16:06:33 -04:00
James Valleroy
401d3870f6
Move ldapscript setup to users module setup. 2016-05-21 16:06:26 -04:00
James Valleroy
f01575e2ea
Move ldap setup from freedombox-setup to plinth. 2016-05-21 16:06:18 -04:00