17 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
75a46962f0
module_loader, web_framework: Update console log messages
- Drop message for initialization of each app. This was removed earlier but was
reintroduced during init() refactoring. There is not much use for these messages
and the noise they generate hide some important messages relating to domains
added.

- Print lists in a better way for humans.

- Add a log message after all the initialization is completed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-09-27 09:54:09 -04:00
Sunil Mohan Adapa
e5177289dc
web_framework: Don't create Django secret key when listing depends
This allows --list-dependencies to run without having to write to disk.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:57 -04:00
Sunil Mohan Adapa
28fe8c8c3e
web_framework: Split initialization into two parts
A simple Django configuration does not need to create the database whereas DB
migration requires creating the database.

In some operations such as listing dependencies, we can skip running the second
part and so writing to database will no longer be necessary during such
operations.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:55 -04:00
Sunil Mohan Adapa
f2d43737fa
web_framework: Reduce verbosity of DB migration process
During provisioning of container/VM, we need to run --list-dependencies. When
run without --develop, they are unable to create database. When run with
--develop, the output from the database migration process is messing up the
output meant for stdin as it is outputting to stdout instead stderr. Reduce
verbosity even in debug mode to fix this.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-06-04 18:19:36 +03:00
Sunil Mohan Adapa
61545d1b8d
web_framework: Cleanup expired sessions every week
Currently, sessions are created as files in /var/lib/plinth/sessions. If a user
does not logout, the sessions remains there ever after expiry. Cleanup these
accumulating files by running a cleanup job every week.

Adding django.contrib.sessions to apps list necessary to ensure that
'clearsessions' management command is available. This creates an empty database
table for session storage but is harmless.

Tests performed:

- When run with the change for first time, migration is run for
django.contrib.sessions app.

- Change the scheduled interval to 30 seconds in the code. Login as a user. A
new session file is created in data/var/lib/plinth/sessions. Forward the system
clock by at least 2 weeks. The session expires. Within 30 seconds the file is
also removed.

- Login, then remove the django-secret.key. In 30 seconds we see a message that
the session data is corrupt. Advance the clock by at least 2 weeks. The session
file is removed and the message about session data is no longer printed.

- Repeat for system level plinth after `./setup.py install` and `sudo -u plinth
plinth`.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-24 18:04:26 -05:00
Sunil Mohan Adapa
fd345aca80
web_framework: Generate and retain a secret key
- Secret is important for various functions of Django. There is no impact on
existing installations due to the change. Improves the security of existing
functions in minor ways and will be useful in future usage of Django.

- Create the file in /var/lib/plinth/ with 0o600 permissions.

- Make git ignore the file in code folder.

- Don't copy the file during './setup.py install' operation.

Impact to users after upgrade:

- All existing sessions will get logged out. This is because SECRET_KEY is used
to generate user session hash that is used to logout users when their password
changes.

Tests performed:

- Run development version of service. File should get created in
data/var/lib/plinth/django-secret.key. Permissions should be 0o600.

- Run again, the file should not be overwritten. Printing
django.conf.settings.SECRET_KEY should match the one in the file.

- Run `setup.py install`. This should not install django-secret.key in
/var/lib/plinth.

- Run `sudo -u plinth plinth`. This should create the secret key file in
/var/lib/plinth/django-secret.key. Permissions on the file should be 0o600.
Ownership should be plinth:plinth.

- Remove the file in both cases, a fresh new file should get created with new key.

- Truncate the file to less than 128 chars, the existing file should get
overwritten with new key.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-24 18:04:20 -05:00
Sunil Mohan Adapa
837e8fc6e1
web_framework: Separate out Django settings into module
This allows for many cases of having to deal with Django objects such as models.

- Allows all modules including ones with models to be imported by Sphinx.

- Run most of the management commands using django-admin.

- Make it simpler to import all modules on REPL interactive Python shells.

Does not change any of the settings that we are passing to Django for
configuration.

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-22 15:51:41 -05:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Sunil Mohan Adapa
4956a2a63a
web_framework: Set the timezone to UTC
This is needed to ensure that all the time/date values stored in the database
are UTC. A timezone change in the settings should not make the database values
inconsistent.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-10 18:13:01 -05:00
Alice Kile
eb83e00011
fix formatting issues
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-12-07 13:08:35 -05:00
Sunil Mohan Adapa
b0d797a84a
Minor yapf and isort changes
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-07-21 09:06:04 -04:00
Sunil Mohan Adapa
0f807bcd48
sso: Use new features of axes, log axes messages
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-07-21 09:05:58 -04:00
Sunil Mohan Adapa
dc9ab52edc
axes: Minor fixes to configuration for IP blocking
- Use the X-Forwarded-For header only if specified in the configuration. This
  makes FreedomBox safe to use when not behind a reverse proxy server (although
  we are unlikely to do this).

- When fetching the IP address to reset after successful login, use the
  X-Forwarded-For header only if specified in the configuration.

- Minor flake8 refactorings.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-01-28 17:17:32 -05:00
James Valleroy
de2f1437ea
django: Remove deprecated AXES_BEHIND_REVERSE_PROXY
Closes #1244

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-01-23 16:24:16 -08:00
Sunil Mohan Adapa
1faee11d4d
django: Use Argon2 password hash
Passwords will be automatically upgraded for each user on login.

Usernames not yet upgraded are vulnerable to user enumeration attack due to
difference in password check timing.

No need to add build dependency on python3-argon2 because tests use a different
Django configuration which does not use argon2 hash.

Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2019-01-13 14:46:15 -05:00
Sunil Mohan Adapa
7ee4d13dce Show Gujarati in the list of UI languages
- Explicitly setup the list of Django languages. Keep them sorted by language
  code.

- Fallback to language name when Django can't provide locale language name.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-01-09 14:52:02 +05:30
Sunil Mohan Adapa
40ecce554f main: Separate out Django setup into a separate module
This has less to do with abstraction than to do with modularization.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2019-01-09 14:52:02 +05:30