271 Commits

Author SHA1 Message Date
Veiko Aasa
92aa66114c
users: Fix unable to delete user
Fixes an issue where confirming user deletion is not submitting the user
edit form.

Also fixes an issue where the user edit submit button is disabled after user
deletion confirmation is cancelled.

Fixes #2513.

Tests performed:
- Deleting a user works.
- All the users module tests pass.
- After cancelling the user deletion confirmation dialog, the user edit
  submit button is clickable.
- On the app pages, submit buttons are disabled when app enabling or disabling
is in progress.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2025-04-15 12:02:15 -07:00
Sunil Mohan Adapa
89bce7a344
app: Add tags to menu and frontpage components
- Add typing information for init methods Info, Shortcut, and Menu to easily
  identify problems.

- Update docstrings for these components.

- Updates test cases to deal with tags instead of short description.

- Update custom shortcuts code to read tags and ignore short description.

- Update API to send tags instead of custom shortcuts.

- OpenVPN special treatment of info.description in Shortcut

Tests:

- All unit tests pass and type checking succeeds.

- All apps show icons with tags in apps and system section.

- In help section cards don't show tags.

- In front page, enabled apps show shortcuts with tags.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-01-09 21:08:10 +05:30
Sunil Mohan Adapa
c45bdf56dd
ui: js: Load all JS files in deferred mode to speed up page load
- This improves page rendering time. If JS files are not loaded in deferred or
async mode, they will halt the page rendering until JS files are loaded from
network.

- 'defer' mode guarantees that the load order is same as the order in which JS
files appeared in the HTML page.

Tests:

- Run at least one function of each affected JS file and ensure that is works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2025-01-07 12:08:51 +02:00
Sunil Mohan Adapa
f2ce5b7afd
users: Drop jQuery code as the library dependency has been removed
Closes: #2484

Tests:

- Functional tests for users app works.

- When updating the user if the delete user is not checked, delete confirmation
dialog is not shown.

- When updating the user if the delete user is checked, delete confirmation
dialog is shown. It can be dismissed and re-shown many times. When confirm
button is clicked, the form is submitted and user is deleted.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2025-01-05 09:51:39 -05:00
Sunil Mohan Adapa
3a0db947b2
system: Add tags to all remaining apps
Tests:

- Visit the system page and notice that tags appear as expected for all items on
the page.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-12-29 22:58:23 -08:00
Veiko Aasa
40e00423a8
users: Restart nslcd service after configuration changes during setup
Fixes an issue where the nslcd configuration option pam_authz_search is not
in effect after the users module setup.

Tests:
  - Remove the pam_authz_search configuration option from /etc/nslcd.conf,
    restart nslcd service, delete plinth.sqlite database to run first setup
    after plinth start, start plinth. Do it twice:
    1) before applying patch, users::test_user_states functional test fails.
    2) after applying patch, users::test_user_states functional test pass.
  - After applying patch, the nslcd service is restarted during module
    upgrade.
  - All the users module tests pass.

Relates to
https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/2594#note_565614.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-12-28 10:13:15 -08:00
Veiko Aasa
c17ef22bd8
users: tests: functional: Use click function from functional libary
Tests:
  - All users tests pass.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Update to reflect the new utility function name]
[sunil: Update some more cases to use the utility]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-12-27 16:43:43 -08:00
Sunil Mohan Adapa
7602cf6172
ui: users: Fix close button for confirmation dialog for Bootstrap 5
- Also place the body content in <p> for improved semantics and suggested by
Bootstrap.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-12-12 12:50:50 +02:00
Sunil Mohan Adapa
95ecf36152
ui: Rename data- attributes to data-bs- for Bootstrap 5
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-12-12 12:48:54 +02:00
Sunil Mohan Adapa
62dad9336b
ui: Use Bootstrap 5 styling for all alerts
- Ensure that .sr-only is replaced with newer classes.

- Ensure that icons are present for all alerts.

- Use flex-box for display of icons on the left center of the alert.

- .close has been renamed to .btn-close.

- &times; is no longer required for close buttons.

Tests:

- Visually verify all the changes by triggering them with code changes.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-12-12 12:38:01 +02:00
Veiko Aasa
df52acc329
users: tests: functional: Check LDAP information is correct after renaming user
Tests performed in stable and testing containers:
  - All the users module tests pass.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-10-23 21:24:35 -07:00
Veiko Aasa
f12e634bc9
users: Delete or move home folder when user is deleted or renamed
On user deletion, user's home folder is also deleted. Admins have an
option to avoid deleting user's home by inactivating the user instead.

This commit also removes user deletion buttons from the user's list
page and adds this option to the user edit page. The user's edit form
asks for a confirmation if the user deletion is requested. This change
also means that the confirmation password is now required to delete a user.

Also:
  - Add a simple username validation to the privileged actions.
  - Functional tests: Create a fixture to login as an admin before every test.
  - Functional tests: Add a test to check that SSH passwordless login works
    after user is renamed to validate correct SSH related path permissions.
  - Privileged tests: Add `test_` prefix to the generated random string which
    makes easier to check and cleanup created home folders.
  - Minor quote fixes.

Tests performed in stable and testing containers:
  - Run all the users module tests twice, no failures in tests.
  - When user is the last admin, both "Active" and "Delete user"
    checkboxes are disabled.

Closes #2451.

[sunil]

- Refactor the JS code:

  - Ensure that DOM elements are lookup after DOM content is loaded.

  - Styling changes. Reduce the number of globals, name the global names
  somewhat more unique.

  - Click the button instead of submitting the form to disable the button.

- Template changes:

  - Add a body for the confirmation dialog to talk about disabling the user and
  deleting the home directory.

  - Change the label of the confirm button to make it more
  explicit (recommendation from many UX guides).

  - Styling.

- Functional tests:

  - Fix visibility checking of an element to use the correct splinter API.

  - Simplify clicking the edit user link.

- Minor update to form checkbox help text.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-10-23 21:13:25 -07:00
Sunil Mohan Adapa
3f954f9549
tests: functional: Create utility to set user preferred locale
- Move it from the users app functional tests file.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-10-16 21:08:25 -07:00
Sunil Mohan Adapa
b5e57c4ffc
security: Remove PAM configuration for 'access' module
- This was supposed to removed in MR #2309 in the commit
253540fb3d12254c920b632cc484be6a79d27229. It was overlooked.

- Version number of users app has not been incremented as it has already been
incremented in this release.

Tests:

- There is no directory /etc/security/access.conf.d.

- There are not directives in /etc/security/access.conf that are not commented
out.

- After applying the patch (assuming previously setup version is 24.20) and
manually removing the destination file, app setup for users app runs. It
succeeds. /etc/pam.d/common-account no longer contains the line 'account
required pam_access.so'.

- After the upgrade, users who are root and non-root are able to login via SSH
and Cockpit. After a reboot, users are able to login via SSH and Cockpit.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-09-25 11:29:10 -04:00
Sunil Mohan Adapa
373ca60f11
users: Increment app version for changes w.r.t. inactive users
- Since previous release 24.20 already has a increment to version 6, users app
version must be incremented in order for the changes related to inactive users
to take effect.

Tests:

- On applying the patches and running the service, upgrade to new app version
runs and succeeds. If there are inactive users presets, then before the setup()
privileged method is run, setup_and_sync_user_states() is run.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-09-24 14:28:25 -07:00
Sunil Mohan Adapa
4b2e065304
users: Set proper class on default password policy object
- Some trivial refactoring.

Tests:

- The default password policy works. Inactive users are unable to login via
console, SSH and cockpit.

- After the app is setup freshly and after it is upgraded from previous version,
the namedobject.schema has been ingested into the OpenLDAP configuration.

- Rerunning setup for users app works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-09-24 13:27:17 -07:00
Veiko Aasa
67b6c0f9e8
users: Inactivate users in LDAP user database
Previously, users were inactivated only in plinth users database. This change
adds ability to inactivate users in LDAP database.

Changes:
- Inactive users in plinth users database are also inactivated in LDAP
  during app upgrade.
- Inactivated users can't login using LDAP password.
- Apache2 single-sign-on module now requires LDAP connection. SSO
  sessions are now invalidated when users are inactivated.
- PAM/nslcd now performs authorization checks against LDAP, which means
  inactivated users can't do passwordless ssh logins and running their
  crontabs are blocked.
- When inactivating a user, all user's processes are killed.

Also, update LDAP diagnostics:
 - Fix LDAP checks returned always passed results.
 - Fix `ou=people` entry doesn't exist in LDAP.
 - Add diagnostics checks for `ou=policies` and `cn=DefaultPPolicy`.

Tests performed:
 - App upgrade works.
 - App upgrade with previously disabled user works, user is inactivated
   also in LDAP.
 - App upgrade with disabled user that doesn't exists in LDAP database works.
 - Increment app version again, to 7, app upgrade works second time.
 - Inactivate user and test logins:
   - can't login using direct LDAP (nextcloud, ejabberd, matrixsynapse)
   - can't login using Apache2 LDAP module (gitweb, ikiwiki, rssbridge,
     transmission)
   - can't login using apache sso module (featherwiki, gitweb, rssbridge,
     sharing, syncthing, tiddlywiki, transmission, wordpress).
   - can't login using ssh with password or passwordless
- Inactivate user and test exsisting sessions:
   - ssh, cockpit and samba sessions are killed.
   - Configure crontab, configured crontab is failing to run after user
     is inactivated.
- All the users app tests pass.

Notes:
- Only Apache2 SSO sessions are disabled. Apps that create their own
  sessions keep working, like nextcloud, ejabberd, matrix-synapse,
  ikiwiki. In the future, we could add a feature that apps can implement
  their own users locking functions.
- When testing inactivated users, users and IP-s can be banned by the system,
  banned IP-s/users can be viewed with commands `fail2ban-client banned` and
  `pam_abl`.
- Existing sessions keep working when deleting a user or removing
  a user from an access group.
- I didn't test e-mail app.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
2024-09-24 13:27:13 -07:00
Sunil Mohan Adapa
125a002fa3
users: Don't cache NSS user indentity information
nscd daemon caches queries made to NSS via glibc. In our case queries to passwd
and group databases are cached. But this leads to many problems.

See: https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/2520

The bug that this MR fixes, that is, the inaccuracy of the authentication data,
is horrible and only acceptable if the caching provides very important
functionality. Already, having to purge nscd caches after modifying user
accounts is not nice.

I believe that we have encountered this bug before and blamed libpam-abl due to
the time sensitive nature of the problem.

nscd itself recommends that it should be used if NSS lookup are expensive (such
as in case of NIS, NIS+ queries according to /etc/init.d/nscd). In case of
FreedomBox, LDAP queries are unlikely to be made using network. LDAP server is
likely always local. I believe we can safely remove nscd by masking and stopping
nscd.service and unscd.service.

Tests:

- After applying the patches, users app setup is re-run. Service nscd is stopped
and masked. unscd is also masked.

- Running 'id tester' shows expected value 'uid=10001(tester) gid=100(users)
groups=100(users),10002(admin)'.

- Adding, removing, renaming a user immediately reflects in 'id <user>'.

- Adding and removing a user from groups immediately reflects in 'id <user>'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-09-21 00:09:22 +03:00
Veiko Aasa
7e7ad62c8b
users: Invalidate nscd cache after nslcd service startup
Fixes an issue where LDAP group membership info is not available long time
after system restart. This can happen when nscd cache is expired and name
service queries are made while nslcd is not yet started. As a result, nscd
group cache contains only local system groups and not LDAP groups. The issue
arises more likely in slow systems where slapd/nslcd startup can take minutes.
Could also depend on how long the device has been shut down before.

Tests performed:
  - stop nscd service, start nslcd service, check form the logs that
nscd reload errors are ignored and nslcd service starts successfully.

  - Test when nscd group cache is invalidated while nslcd is not running.
Run commands:
```
systemctl reload nscd
id tester
systemctl stop nslcd
nscd -i group
id tester
systemctl start nslcd
id tester
```

Result before patch applied.
```
uid=10001(tester) gid=100(users) groups=10002(admin),100(users)
uid=10001(tester) gid=100(users) groups=100(users)
uid=10001(tester) gid=100(users) groups=100(users)
```

Result after patch applied, tester is in the admins group at the end.
```
uid=10001(tester) gid=100(users) groups=10002(admin),100(users)
uid=10001(tester) gid=100(users) groups=100(users)
uid=10001(tester) gid=100(users) groups=10002(admin),100(users)
```

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-09-19 19:50:27 -07:00
Sunil Mohan Adapa
f22d1b31db
users: Mark secret strings in privileged actions
Tests:

- Run affected privileged actions through UI and notice that secret strings are
not logged (except deleting the last admin user).

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-08-11 12:57:43 -04:00
Sunil Mohan Adapa
6e557dd1e9
system: Organize items into sections
Closes: #2161.

- Sections are ordered by importance on which administrator must act after
setting up the system.

- Consistent order across all the languages.

- Update the styling for the section hearers.

  - For system section, make them compact.

  - Make them look like a header text (with underline) rather than a
    divider (like in a menu).

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-03-16 09:17:35 +02:00
Sunil Mohan Adapa
1b09d01575
users: Add email address field during first boot
- Mostly because administrators won't discover the email address field for the
user later on.

- This field is important to be able to run 'reset password' operation.

Tests:

- In stable and testing containers, run first boot wizard. Enter the email
address during the first boot and see that it was saved as part of user account.
Leave the email address blank and it is possible to proceed. User account show
blank email address.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-03-14 21:58:04 +02:00
Sunil Mohan Adapa
9d2a11b874
users: Add email address field when creating/updating user accounts
Closes: #1826.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-03-14 18:07:16 +02:00
Sunil Mohan Adapa
4b09d91f93
*: Add type hints for diagnose method
Helps: #2410.

- Ensure that diagnostics methods and parameters are type checked so that we can
catch any potential issues.

- Move plinth/modules/diagnostics/check.py to plinth/diagnostic_check.py to
avoid many circular dependencies created. This is due to
plinth.modules.diagnostics automatically imported when
plinth.modules.diagnostics.check is imported. Also app.py is already (type)
dependent on diagnostic_check due to diagnose() method. To make the Check
classes independent of diagnostic module is okay.

Tests:

- Run make check-type.

- Run full diagnostics with following apps installed: torproxy, tor.
  - Test to netcat to 9051 in tor works.
  - Test 'port available for internal/external networks' in firewall works.
  - Test 'Package is latest' works.
  - Test 'Access url with proxy' in privoxy works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
[jvalleroy: Also move tests for diagnostic_check]
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
2024-03-09 14:23:33 -05:00
Sunil Mohan Adapa
f9b186e14f
*: Add type hints for app init methods
- This is so that the methods will be checked by mypy. This should help identify
any incorrect initialization of components.

- Remove unused self.repos in GitwebApp.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-03-09 14:22:14 -05:00
Veiko Aasa
ca0479aae2
users: tests: Do not remove LDAP user when testing views
Fixes an issue where the LDAP user 'tester' was removed after testing
test_views.py. It happened when there were two admin users present.

Tested with both stable and testing containers that all the users
module tests pass and a user 'tester' is not removed when
two admin users exists.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-03-08 15:09:40 -08:00
Sunil Mohan Adapa
b36d4419c4
users: Minor refactor when creating django groups
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-03-08 11:28:54 +02:00
Sunil Mohan Adapa
526a3018e4
users: Fix creating users with initial set of groups
Fixes: #2409.

When creating a user if one or more groups is selected, creation fails. This
is because the fields contains group choices as (name, label) tuples instead
of (group_id, label) tuples as expected by the many-to-many field mapping
mechanism in ModelField class. Fix this by using the same mechanism used in
UserUpdateForm, which is to reuse the base class form field (but adjust some
properties).

Tests:

- During first boot
  - Django groups are fully created when form is accessed with blank database
- In user creation/modify form:
  - Label appears are 'Permissions'
  - Choices appear fully and as 'Description (Group name)'
  - Help text is correct.
  - Choices are sorted on group name.
  - Django groups are fully created when form is accessed when a new group is
    added to code.
  - User can have no groups
  - Widget is multiple checkbox widget. Multiple groups can be selected.
  - User is added to proper ldap groups after submission
- In user modify form:
  - If the user is last admin user, admin checkbox is checked and disabled.
  - Current list of groups is accurate shown when form is displayed.
  - Add remove of groups works as expected
- Functional tests for gitweb and users apps pass

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2024-03-08 11:28:54 +02:00
Sunil Mohan Adapa
d32d02ecb5
gitweb, users: Minor fixes for newer pycodestyle
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2024-02-21 20:54:47 -05:00
James Valleroy
3fcd6b9e58
diagnostics: Translate descriptions only in view
Tests:

- Enable all apps, and run diagnostics. Diagnostic descriptions are formatted
  as expected.

- Change the language to Spanish, and view the diagnostic results. Diagnostic
  descriptions are translated as expected.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-01-18 22:19:05 -08:00
James Valleroy
4612df954d
diagnostics: Add parameters to DiagnosticCheck
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-01-18 22:18:47 -08:00
James Valleroy
79f36e6a0c
diagnostics: Add DiagnosticCheck dataclass
- Set unique check_id for each diagnostic check.

- Result is a string-based enumeration. The default value (NOT_DONE) can be
  used for diagnostic checks that have not been completed yet.

- Result is StrEnum so that the return value of check_url can still be used
  directly as a diagnostic result.

Closes: #2375

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-10-07 04:52:13 +09:00
Sunil Mohan Adapa
38ece87c6c
*: Utilize newer 3.10 syntax for type hints
Tests:

- mypy does not show any errors.

- Installing ejabberd app works. Privileged actions run fine.

- Unit tests work.

- No additional testing was done as type annotations don't have any effect at
runtime.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-09-25 20:03:34 -04:00
Sunil Mohan Adapa
2dd00a8f08
*: Fix all typing hint related errors
- Try to mark class variables in component classes.

- Leave typing hints generic, such as 'list' and 'dict' where content is usually
not filled, too complex, or context is unimportant.

- backups: Handle failure for tarfile extraction so that methods are not called
on potentially None valued variables.

- backups: Prevent potentially passing a keyword argument twice.

- dynamicdns: Deal properly with outcome of urlparsing.

- ejabberd: Deal with failed regex match

- email: Fix a mypy compliant when iterating a filtered list.

- tor: Don't reuse variables for different typed values.

- tor: Don't reuse variables for different typed values.

- operation: Return None explicitly.

- operation: Ensure that keyword argument is not repeated.

Tests:

- Where only typing hints were modified and no syntax error came up, additional
testing was not done.

- `mypy --ignore-missing-imports .` run successfully.

- Generate developer documentation.

- Service runs without errors upon start up.

- backups: Listing and restoring specific apps from a backup works.

- backups: Mounting a remote backup repository works.

- NOT TESTED: dynamicdns: Migrating from old style configuration works.

- ejabberd: Verify that setting coturn configuration works.

- email: Test that showing configuration from postfix works.

- tor: Orport value is properly shown.

- transmission: Configuration values are properly set.

- users: Running unit tests as root works.

- operation: Operation status messages are show properly during app install.

- ./setup.py install runs

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-09-25 20:03:24 -04:00
Sunil Mohan Adapa
770974c8ce
sso: Switch to django-axes >= 5.0
- Add explicit dependency on django-ipware >=3. django-axes >= 6 adds
only and optional dependency on django-ipware. Adding explicit dependency make
the behavior safer.

- Depend on django-axes >= 5 where the authentication backend and other features
are available. The new code won't work with older versions. The new approach
uses and authentication backend to deny access to the login form on lockout and
a middleware to redirect user to locked out form when limit of attempts have
been reached.

- Drop old code used for compatibility with django-axes 3.x.

- Suppress verbose and debug messages as django-axes is too chatty.

- Re-implment the CAPTCHA form entirely. In the old style, we have a login form
with CAPTCHA field. That would not work with the new django-axes authentication
middle. On submission of the form, auth.authenticate() will be called. This
call invokes various authentication backends include django-axes authentication
backend. This backend's behavior is to reject all authentication attempts when
the IP is listed in locked table. The new approach is to provide a simple
CAPTCHA form with just the CAPTCHA field. If the form is successfully
validated (correct CAPTCHA is provided), then the lock on the IP address is
reset. The user is then free to perform 3 more attempts to login.

- Update firstboot form to send the request parameter when using
auth.authenticate() method. This needed by Django axes' authentication method
which will be triggered.

Tests:

- Run tests on Debian Bookworm and Debian testing.

- Axes verbose messages and debug messages are not printed on the console when
running FreedomBox in debug mode.

- Only three invalid attempts are allowed at the login page. After the final
incorrect attempt, user is redirected to CAPTCHA page. Visiting the login page
using the URL works but entering the correct credentials still takes the user to
CAPTCHA page.

- CAPTCHA form appears as expected. Clicking the CAPTCHA images downloads the
audio file corresponding to the image. Incorrect CAPTCHA shows an error. Correct
CAPTCHA takes the user to login form where they are able to login with correct
credentials. Entering incorrect credentials 3 times will take the user again to
CAPTCHA page.

- Creating user account during firstboot works.

- Blocked IP address the IP of the client such as 10.42.0.1 and not the local IP
address 127.0.0.1 according the django-axes log messages. While one client IP
address is blocked, another IP is able to login to the same user account that
was attempted by the blocked client.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-08-23 21:47:39 -04:00
Sunil Mohan Adapa
dc9e86d918
users, networks: Use the autofocus HTML attribute sparingly
Using autofocus too much hurts accessibility[1] as screen readers jump to the
autofocused field. Specifically, it should used only when it increases UX
significantly, when the form is the only thing on the page and there is nothing
to read before the field is filled.

- Networks: There is not much improvement to UX by focusing on a radio select.

- Update User Form: there is a statement to be read before the first element is
filled up. Username is changed rarely but it being focused on.

- First boot user account: There is content to be read before filling the form
and this will be skipped by the screen reader.

Links:

1) https://www.boia.org/blog/accessibility-tips-be-cautious-when-using-autofocus

Tests:

- networks: Add new connection form works. The connection type is not
autofocused.

- users: Update user form works. Username is not autofocused.

- users: First boot form works. Username is not autofocused.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-08-23 21:47:31 -04:00
James Valleroy
d5cde45cd8
users: Add diagnostic checks for nsswitch config
Tests:
- Reconfigure libnss-ldapd and disable passwd, group, shadow. Confirm
  that diagnostics are failing.

- Reconfigure libnss-ldapd and enable passwd, group, shadow. Confirm
  that diagnostics are passed.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Use augeas Nsswitch lens]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-07-18 11:00:29 -07:00
James Valleroy
1522f98556
users: Add diagnostics check for nslcd config
Tests:

- Change the values of uri, base, and sasl_mech in /etc/nslcd.conf.
  Confirm that the diagnostics are failing.

- Change the values back to the original. Confirm that the diagnostics
  are passed.

- Remove the uri, base, and sasl_mech lines from /etc/nslcd.conf.
  Confirm that the diagnostics are failing.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Use augeas Nslcd lens]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-07-18 10:59:27 -07:00
Sunil Mohan Adapa
73bc89b916
users: Use drop-in config component for /etc files
Tests:

- Config files are all symlinks in /etc/
- LDAP auth works for /tt-rss-app/

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-06-05 20:30:01 -04:00
Sunil Mohan Adapa
40eecb6446
*: Move modules-enabled files to /usr/share
- This will leave /etc/{plinth,freedombox} empty by default making service more
robust to run across various environments and situations. See systemd's
explanation for more details.

- Use Debian maintainer scripts remove all the existing files in
/etc/plinth/modules-enabled.

- Read from /usr/share/freedombox/modules-enabled then from
/etc/plinth/modules-enabled and finally from /etc/freedombox/modules-enabled.
Later read ones override previously read files. Any file pointing to /dev/null
will mean the module must be ignored.

Tests:

- Clean up /etc/plinth, /etc/freedombox and
/usr/share/freedombox/modules-enabled. Run service and notice that files are
getting loaded from development folder using a debug message.

- Run setup.py and notice that files get installed in
/usr/share/freedombox/modules-enabled/ and in the next run they get loaded from
there.

- Create a override file in /etc/plinth/modules-enabled/transmission and notice
that overriden file gets priority over the one in
/usr/share/freedombox/modules-enabled.

- Link the file /etc/plinth/modules-enabled/transmission to /dev/null and notice
that is not loaded.

- Create another file in /etc/freedombox/modules-enabled/transmission and notice
that it overrides the previous two files.

- All affected modules are loaded.

- Build a new Debian package and ensure that upgrading 23.8 to new version
removes are all configuration files.

- Build developer documentation and test that Tutorial -> Full Code and Tutorial
-> Skeleton sections have been updated with references to
-.../modules-enabled/... paths.

- Install quassel and notice that certificates were copied to /var/lib/quassel
directory. Change domain to another domain and notice that certificates were
copied again to that directory.

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-05-13 07:08:43 -04:00
Sunil Mohan Adapa
d4b21ef1e4
views: Use dedicated view when showing an app with operations
Closes: #2309.

- This prevents processing of AppView when the app is being uninstalled. For at
least two apps, this has failed because the AppView assumes that app and its
dependencies are installed.

- Use a dedicated template as well is simplify app template.

Tests:

- Installing and uninstalling an app works.

- Refreshing the app page during uninstall does not lead to an error for samba
and email apps.

- Unit tests pass.

- Functional tests for samba and email work.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-01-30 20:08:11 -05:00
Sunil Mohan Adapa
7e0b728498
users: tests: Fix privileged tests
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-12-16 10:40:01 -05:00
Sunil Mohan Adapa
253540fb3d
security: Remove restricted access setting and configuration
Closes: #2276.

Functionality all over the system keeps failing due this approach. The latest is
changing hostname in ejabberd Mnesia database fails (#2276). Further, users
connecting FreedomBox to a monitor can't use a GUI.

Tests:

- Without patches, enable restricted access. Apply patches and setup.py install.
Security app is updated. Restricted access is disabled and
/etc/security/access.d/{50freedombox.conf, 10freedombox-security.conf,
10freedombox-performance.conf} are removed. It is possible to login into
non-admin account via SSH.

- On a fresh install, the configuration files are not found.

- Security page does not show 'restrict console logins' option.

- Updating security app setting works. Message 'Configuration updated.' is
shown.

- First boot succeeds. Restrict console login is not enabled.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-12-05 20:47:13 -05:00
Sunil Mohan Adapa
222563a482
*: Use privileged decorator for service actions
Tests:

- DONE: Unit tests work
- DONE: Transmission
  - DONE: Enabling/disabling an app with a daemon works: transmission
  - DONE: Showing the status of whether the app is enabled with daemon
    is-enabled works.
  - DONE: A message is shown if app is enabled and service is not running
  - DONE: Service is stopped and re-started during backup
  - DONE: Adding user to share group during initial setup restarts the service
- Not tested: Enabling/disabling a service with alias works (no such apps)
- DONE: Restarting/try-restarting a service works
- DONE: Masking/unmasking works
  - DONE: rsyslog is masked after initial setup
  - DONE: systemd-journald is try-restarted during initial setup
- DONE: Avahi, email, security initial setup works
  - DONE: Fail2ban is unmasked and enabled
- DONE: Enabling/disabling fail2ban is security app works
- DONE: Enabling/disabling password authentication in SSH works
- ?? Let's encrypt
  - Services are try-restarted during certificate setup, obtain, renew
- Not tested: upgrade pagekite from version 1

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:55 -04:00
Sunil Mohan Adapa
1dcbfce713
users: Use privileged decorator for actions
Tests:

- Functional tests work (failing already)
- DONE: Showing front page shortcuts according to user groups works
  - DONE: Only user who is party of syncthing group is shown syncthing
  - DONE: Admin users are always shown all the apps
- DONE: Syncthing:
  - Not tested: When upgrading from version 2 or below, renaming group works
  - DONE: Syncthing is added to freedombox-share group
- DONE: Initial setup of users app works
  - DONE: freedombox-share group is created
- DONE: Retriving last admin user works
  - DONE: Last admin is not allowed to delete account
- DONE: Creating a new user works
  - DONE: Password is set properly (user can login with 'su - user' after)
  - DONE: Incorrect confirmation password leads to error
  - DONE: Adding the user to groups works (edit page shows correct list of groups)
- DONE: Editing a user works
  - DONE: User is renamed properly
  - DONE: Removing user from groups works
  - DONE: Adding user to new groups works
  - DONE: Providing incorrect auth password results in error message
  - DONE: Enabling/disabling account work (confirm with 'su - user'). See #2277.
- DONE: Updating user password works
  - DONE: New password is set (confirm with 'su - user')
  - DONE: Providing incorrect auth password results in error message
- DONE: Initial user account creation works
  - DONE: User account can be used (confirm with 'su - user')
  - DONE: User is added to admin group
- DONE: Exception while getting SSH keys results in showing empty field
- DONE: Removing a user works
  - DONE: Command provided in a message in users_firstboot.html works for
    deleting users.
- DONE: If an admin users exists when running first wizard, list of admin users
  is shown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:52 -04:00
Sunil Mohan Adapa
12cf5065b0
ssh: Use privileged decorator for actions
Tests:

- Functional tests work
- Updating SSH keys in user edit page sets the SSH keys. File is updated
  properly. Page shows newly set SSH keys.
  - Entering invalid auth credentials throws error
- Enabling/disabling SSH password authentication works.
  - Configuration file is updated.
  - App page shows proper value

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:15 -04:00
Sunil Mohan Adapa
e87752e065
users: tests: functional: Find forms more accurately
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-09-03 17:29:09 -04:00
Sunil Mohan Adapa
900c0d30b9
*: Drop module level app property
module.app property usage is greatly reduced because setup() and force_upgrade()
method are now part of App class instead of at the module level. Remove the
remaining minor cases of usage and drop the property altogether.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:29 -04:00
Sunil Mohan Adapa
75f6abac1e
*: Make setup method part of App class for all apps
- Primary purpose is to complete the App API and allow for multiple apps to be
present in a module without a single clashing setup() method. Secondary
objective is to get rid of SetupHelper instance simple use App instance instead.

- This brings us closer to not needing to implement setup() method for some of
the typical apps.

- Remove default value None for old_version parameter.

  - A valid integer value is always passed to this call.

  - The value of None is undefined.

  - Simplifies the App API slightly.

- Drop setting 'pre', 'post' values to indicate the stage of setup for the App.

  - Simplifies the setup methods significantly. Eliminates a class of
  bugs (some of them seen earlier).

  - The UI can show a simple 'installing...' or progress spinner instead of
  individual stages.

  - There are currently many inconsistencies where many operations are not
  wrapped in helper.call() calls.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:16 -04:00
Sunil Mohan Adapa
22a120d979
*: pylint: Avoid calling super() with arguments
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:46:23 -04:00