41 Commits

Author SHA1 Message Date
fliu
da1e4ed505
container: Add support for retrieving GPG keys using wget
- Check for errors when running the provisioning script.

- Check for errors when installing missing packages.

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-07-31 15:16:52 -07:00
James Valleroy
de856b0d9c
container: Update for bookworm images
Switch to new GPG key fingerprint.

Test:
- Can bring up stable container.

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2023-07-31 11:18:04 -07:00
Joseph Nuthalapati
e5880c3a6e
container: Add support for ARM64 containers
The script detects the system architecture of the Debian machine and
picks the appropriate container images to download and run.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-07-17 20:58:13 -04:00
Sunil Mohan Adapa
e048e6814c
container: Increase wait time to accommodate slower architectures
This is for arm64 boards like Raspberry Pi and cross-arch VMs.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-03-26 10:07:13 -04:00
Sunil Mohan Adapa
fa1711f84f
container: Fix resizing disk image containing multiple partitions
Closes: #2324.

The arm64 image contains two partitions in a GPT partition table. First is the
EFI partition and the second is the root partition. The container script
currently assumes that there will only be one partition in the image file. Fix
this by picking up the partition number of the last partition and resizing that.
GPT partition table also requires relocating the second copy of the partition
table to the end before partition resize can succeed.

Tests:

- Create testing containers in arm64 and amd64 architectures.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-03-26 10:07:08 -04:00
Joseph Nuthalapati
344c491f7b
container: Drop free tag from image URLs
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-12-12 08:27:27 -05:00
Sunil Mohan Adapa
66c1ddc404
upgrades: Use privileged decorator for actions
Tests:

- DONE: Functional tests work
- DONE: Initial setup works
  - DONE: Automatic upgrades are enable by default
  - DONE: apt preferences have been updated
- DONE: Enabling backports works
  - DONE: Configuration file is created
  - DONE: Correct status is shown in the app page
- DONE: Enabling/disabling automatic upgrades works
  - DONE: Configuration file is updated
  - DONE: Correct status is shown in the app page
- DONE: Manual triggering of updates work
  - DONE: Log is shown properly in the app page
- DONE: Checking for distribution upgrade works
- DONE: Distribution upgrade from stable to testing works
  - DONE: When running on btrfs distribution, snapshot is created before.
  - DONE: Snapshots will be disable before upgrade and re-enabled later.
  - DONE: When searx is enabled before upgrade, it's uwsgi will be disabled and
    re-enabled later.
  - Failures due to freedombox package not being the latest version (with the
    changes).
- DONE: Development Vagrant box
  - DONE: Automatic updates are disabled during development setup
- DONE: Development Container
  - DONE: Automatic updates are disabled during development setup
  - DONE: On stable, backports are enabled when running tests

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:53:33 -04:00
Sunil Mohan Adapa
6f5410931e
actions: Use separate IPC for communicating results
Currently privileged actions use stdout for returning the results. If any of the
sub-processes accidentally output to stdout, decoding errors occur. Prevent this
by opening a pipe to the privileged action and returning the output in that
pipe.

Tests:

- Run unit tests
- Functional tests for other apps pass

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:50:37 -04:00
Veiko Aasa
2f1feeadf1
container: Show default values in command help
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
[sunil: Use the default formatter on all the subparsers]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-08-23 11:19:42 -07:00
Veiko Aasa
7f959ad304
container: Display help message when no args are passed
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
2022-08-23 10:51:41 -07:00
Veiko Aasa
12d02fecfb
container: Ignore flake8 error 'line too long' in bash script text
Also add container script to flake8 test in gitlab-ci.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
2022-08-09 19:48:22 +03:00
Cosmin Humeniuc
bd71f9667c
container: Add IdentitiesOnly option to SSH
- Invoke ssh with the 'IdentitiesOnly` option enabled in order to
force the use of the configured authentication identity. This is
needed in situations where ssh-agent offers many different identities.

Closes #2243

Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2022-08-09 19:48:22 +03:00
Sunil Mohan Adapa
3c7bc4a192
*: pylint: Explicitly specify encoding when open a file
This is recommended by PEP-0597: https://peps.python.org/pep-0597/

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-07-04 19:45:57 -04:00
Sunil Mohan Adapa
c10b10aa31
container: Show executed commands when setting up/running tests
- This allows the user to understand the wrapper script and skip/adapt it when
necessary.

- Debug any issues with the script.

- Maintain consistency with the philosophy of the rest of the container script.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-04-30 12:11:38 -07:00
Joseph Nuthalapati
ca8c5bba4c
tests: functional: Get rid of dependency on xvfb
This removes the dependencies xvfb and pytest-xvfb.

--splinter-headless can be used as a substitute for running tests in
headless mode.

[sunil: Edit description as running run-tests starts plinth in container]
[sunil: Retain the xauth command]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2022-04-30 12:09:53 -07:00
Sunil Mohan Adapa
e89b0ee276
container: Avoid a warning that interactive mode is intended
Currently, with recent version of systemd on host machine, running './container
up' results in the following warning thrown many times. Fix this.

  Console mode 'pipe' selected, but standard input/output are connected to an
  interactive TTY. Most likely you want to use 'interactive' console mode for
  proper interactivity and shell job control. Proceeding anyway.

Tests:

- With systemd version 248 on host machine, run './container up' and notice that
warning is no longer printed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-01-16 09:22:12 -05:00
Sunil Mohan Adapa
9bd1f80d5c
*: Always pass check= argument to subprocess.run()
- Avoid flake8 warnings.

- Makes the call more explicitly readable in case an exception is expected but
check=True is not passed by mistake.

Tests:

- Many tests are skipped since the changes are considered trivial.
check=False is already the default for subprocess.run() method.

- actions/package: Install an app when it is not installed.

- actions/upgrade: Run manual upgrades.

- actions/users: Change a user password. Login. Create/remove a user.

- actions/zoph: Restore a database.

- container: On a fresh repository, run ./container up,ssh,stop,destroy for a
testing container.

- plinth/action_utils.py: Enable/disable an app that has a running service.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-10-11 14:34:40 -04:00
Sunil Mohan Adapa
9faeedbf8f
tests: Drop installation of pytest-bdd
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-10-11 06:29:01 -04:00
Sunil Mohan Adapa
0e22eb6c6e
container: Fix the update command for new web server
Closes: #2109.

We moved from Nginx to Apache on ftp.freedombox.org. This changed the datetime
format in the index pages we were relying on to find the difference with local
image. Update this datetime format.

Tests:

- Run ./container update with an old image already in the .container directory.
New image will be downloaded and verified.

- Run ./container update immediately after downloading the latest image. No new
download is done.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-09-11 20:41:16 -04:00
James Valleroy
9a5a362f50
container: Update stable image for bullseye
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
[sunil: Use the bullseye/ directory for more URL stability]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-09-05 09:04:58 -07:00
Fioddor Superconcentrado
426cdefd71
container: freedombox-develop callable from anywhere
Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
2021-08-30 16:45:28 -07:00
Fioddor Superconcentrado
0a2091a366
container: Don't fail if there's no fbx network
Display debugging info if the reason for failure is different.

Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com>
[sunil: Indentation, fix pylint message]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2021-08-30 16:44:33 -07:00
Sunil Mohan Adapa
02ea2106bc
container: Use keyserver.ubuntu.com as the default keyserver
Closes: #2091.

To avoid current issues with keys.gnupg.net.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-08-18 22:41:14 -04:00
fliu
26b6bbcb52
container script: Must convert env. var. string to a Path object
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2021-03-30 21:06:58 +03:00
Aditya Pratap Singh
c1f2b32b94 container: Work in the absence of systemd in PATH, for eg. in Arch
Closes: #2072
2021-03-27 09:34:22 -07:00
Joseph Nuthalapati
1fca2465aa
container: distribution as environment variable
Allow distribution to be passed as an environment variable.

Fixes #1914

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-03-07 07:41:27 -05:00
Veiko Aasa
d6455419d9
container script: Various improvements
- Install bash-completion when provisioning container, makes terminal
  usage more comfortable.
- Increase default container image size to 16G, so that a distribution
  upgrade fits well.
- Check free disk space on host before expanding disk image.
- Make pytest coverage reports writable to the fbx user, closes  #2010.
- run-tests command:
   - Use DEBIAN_FRONTEND=noninteractive when upgrading packages.
   - Do not install sshpass as provision script already installs it.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2021-01-25 19:51:57 -05:00
Veiko Aasa
fd296ad063 dev-container: Add command to print container IP address
Add './container ip' command to print current IP address of the container.
Useful when running container related scripts on host machine.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
2021-01-07 15:53:13 +01:00
Veiko Aasa
fc7696d181
dev-container: 'up' command: Show banner also when container is already running
Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Fioddor Superconcentrado <fioddor@gmail.com>
2021-01-07 14:28:45 +01:00
Veiko Aasa
2317239d8d
dev-container: Add subcommand to run tests
- Add new subcommand `run-tests` to the ./container script and the --pytest-args
  argument to pass additional arguments to the pytest command.
- Runs tests as root.
- Add new parameters to the SSH command:
  - -Y Enable X11 forwarding to be able to run a browser GUI on a container.
  - -C Use traffic compression so the X11 GUI is not laggy.
  - -t Force pseudo-terminal allocation to enable colors on terminal.
  - Use the LogLevel=error option to suppress some warning messages.
- Update module markers in the pytest.ini file.
- Increase the default container disk size to 12G.
- Update HACKING.md to run unit and functional tests.

PROVISION_SCRIPT:
- Explicitly install sshpass as requirement for tests, needed on Debian
  stable.
- Ensure that geckodriver.log and .pytest_cache/ exist and are others-writable.

Closes #1901

Tests performed:
- Run unit tests on stable, testing and unstable containers, no failed tests.
- Run functional tests on stable and testing containers, no regressions.
[ fioddor: Some failing tests. All of them unrelated to the changes
           introduced. Impact restricted to development tools; the product
           hasn't been changed.]

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: Fioddor Superconcentrado <fioddor@gmail.com>
2021-01-05 17:34:23 +01:00
Veiko Aasa
819520466a
container: Assign virtual network interface to trusted firewall zone
If firewalld is running, the virtual network interface created by
systemd-nspawn gets assigned to the home zone by default. Because
of this, DHCP server is not availabe for the container and most
of the incoming ports are closed.

This commit assigns the network interface created by systemd-nspawn to
the trusted network zone if firewalld is running, so that all network
connections are accepted.

Signed-off-by: Veiko Aasa veiko17@disroot.org
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-10-05 11:44:38 -07:00
Joseph Nuthalapati
2416d87398
container: Handle edge cases with container update
Fix update command failing when image files do not exist.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-09-30 15:49:37 +03:00
Joseph Nuthalapati
d3fd77008e
container: Use builds with build-deps included
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-09-05 16:58:31 -07:00
Veiko Aasa
5e77cf9b6b
container: Randomize btrfs partition UUID
Fixes #1910

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-08-08 09:24:06 -04:00
Sunil Mohan Adapa
866fa6cde3
container: unstable: Handle interface naming for systemd < 245
systemd-nspawn versions < 245 seem to truncate the interface name from
've-fbx-unstable' to 've-fbx-unstabl'.

See:

 - https://github.com/systemd/systemd/pull/12865
 - https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/1856

Tests:

- On Debian Buster with systemd version 241, start testing and unstable
containers. For testing the interface name is ve-fbx-testing and for unstable it
is ve-fbx-unstabl. The containers are brought up and provisioned successfully.
Running 'nmcli c show fbx-${distribution}-shared' shows the correct interface
name assigned.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-07-22 12:11:21 +03:00
Joseph Nuthalapati
2773c4737e
container: Add unstable distribution
Related freedombox-team/infrastructure!38

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-07-22 12:10:58 +03:00
Joseph Nuthalapati
7d143c9ef2
container: Remove external depenceny - dateutil
Used a function from the standard library instead.

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-07-11 11:57:55 +03:00
Joseph Nuthalapati
359a0acd1a
container: Add option to update the container image
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-07-11 11:57:12 +03:00
Sunil Mohan Adapa
91c4d6742e
cfg: In develop mode, use /var/lib for DB and sessions
- Only effects develop mode.

- To primarily avoid writing to the source code directory. Multiple containers
or VMs using the source folder won't fight with the database file (the overlay
file system plan is not working out well for containers #1873).

- In the earlier days, we used to allow running from source code directory
without even doing ./setup.py install. Currently it is not possible anyway. We
pretty much install freedombox package before running from source directory.

- If the build process itself learns not to write to source directory, then
containers/VMs won't have to write to source directory at all.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-28 21:01:53 -04:00
Sunil Mohan Adapa
7f7f4cfb52
container: Remove sqlite3 file early enough
During --list-dependencies if an old sqlite3 file is present with gitweb
enabled, then a2enconf -c gitweb-freedombox-auth get executed. In this case,
setting up apache2 module fails because authpubtkt tokens are not yet generated
but they are being referred to in the configuration files.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-06-25 01:21:39 +03:00
Sunil Mohan Adapa
2e5a1857f7
container: Add script to manage systemd-nspawn containers for dev.
Inspired by: https://salsa.debian.org/vexch/plinth/snippets/391

This script creates a simple container using systemd-nspawn for developing
FreedomBox. It has many advantages over running a VM using Vagrant. RAM is
allocated to processes in the container as needed without any fixed limit. Also
RAM does not have to be statically allocated so it is typically much lighter
than running an VM. There is no hardware emulation when running a container with
same architecture, so processes run as fast as they would on the host machine.

Environment: The script will run only run on hosts having systemd-nspawn and
network-manager installed, typical GNU/Linux distributions. It has been
primarily developed and tested on Debian Buster but should work on most modern
GNU/Linux distributions.

Disk image: systemd-nspawn accepts not only a directory for starting a container
but also a disk image. This disk image is loop-back mounted and container is
started from that mounted directory. The partition to use is determined by
looking at the boot flag in the partition table. This happens to work well with
all existing FreedomBox images. In future, we may be able to run different
architectures in this manner.

After downloading, the disk image is expanded along with the partition and file
system inside so that development can be done without running into disk space
issues. Expanding the disk does not immediately consume disk space because it
will be a sparse file. As data is written to the disk, it will occupy more and
more space but the upper limit is the size to which disk has been expanded.

Downloading images: Images are downloaded from FreedomBox download server using
fixed URLs for each distribution. Signature is verified for the download images.
The fingerprint of the allowed signing key is hard-coded in this script.
Downloaded images are kept even after destroying the extracted raw image along
with container. This allows for quickly resetting the container without
downloading again.

Booting: systemd-nspawn is run in 'boot' mode. This means that init process
(happens to be systemd) is started inside the container. It then spawns all the
other necessary daemons including openssh-server, firewalld and network-manager.
A login terminal can be opened using 'machinectl login' because container is
running systemd. SSH into the container is possible because network is up,
configured by network-manager, and openssh server is running.

Shared folder: Using systemd-nspawn, the project directory is mounted as
/freedombox inside the container. The project directory is determined as
directory in which this script resides. The project folder from the container
point of view will be read-only. Container should be able to write various files
such as build files, FreedomBox sqlite3 database and session files into the
/freedombox folder. To enable writing, an additional read-write folder is
overlayed onto /freedombox folder in the container. This directory can't be
created under the project folder and is created instead in
$XDG_DATA_HOME/freedombox-container/overlay/$DISTRIBUTION. If XDG_DATA_HOME is
not set, it is assumed to be $HOME/.local/shared/. Whenever data is written into
/freedombox directory inside the container, this directory on the host receives
the changes. See documentation for Overlay filesystem for further details. When
container is destroyed, this overlay folder is destroyed to ensure clean state
after bringing up the container again.

Users: PrivateUsers configuration flag for systemd-nspawn is currently off. This
means that each user's UID on the host is also the same UID in the container as
along as there is an entry in the container's password database. In future, we
may explore using private users inside the container.

'fbx' is the development user and its UID is changed during setup phase to 10000
hoping it would not match anything on the host system. 'fbx' user has full sudo
access inside the container without needing a password. Password for this user
is not set by default, but can be set if needed. If there is no access to the
container in any way, one can run 'sudo machinectl shell' and then run 'passwd
fbx' to set the password for the 'fbx' user.

'plinth' user's UID in the container is also changed and set to the UID of
whichever user owns the project directory. This allows the files to written by
'plinth' container user in the project directory because UID of the owner of the
directory is same as the 'plinth' user's UID in container.

Network: A private network is created inside the container using systemd-nspawn
feature. Network interfaces from the host are not available inside the
container. A new network interface called 'host0' is configured inside the
container which is automatically configured by network-manager. On the host a
new network interface is created. This script creates configuration for a
'shared' network using network-manager. When bringing up the container, this
network connection is also brought up. A DHCP server and a DNS server are
started network-manager on the host side so that DHCP and DNS client functions
work inside the container. Traffic from the container is also masqueraded so
that Internet connectivity inside the container works if the host has one.

If necessary, the network interface on host side can be differently configured.
For example, it can be bridged with another interface to expose the container on
a network that the host machine participates in.

The network IP address inside the container can be queried using machinectl.
This script queries that IP address and presents the address in its console
messages. All ports in the container can be reached from the host using this IP
address as long as the firewall inside the container allows it. There is no need
to perform port forwarding or mapping.

SSH: It is assumed that openssh-server is installed inside the container. SSH
server keys in the container are created if missing. Client side keys are
created in .container/ssh directory and the public key is installed in the
authorized keys file of the 'fbx' user. The 'ssh' sub-command to this script is
simply a convenience mechanism for quick launch of ssh with the right IP
address, user name and identity file.

Role of machinectl: Most of the work is done by systemd-nspawn. machinectl is
useful for running systemd-nspawn in the background and querying its current
state. It also helps with providing the IP address of the container. machinectl
is made to recognize the container by creating a link in /var/lib/machines/ to
the image file. systemd-nspawn options are added by creating a temporary file in
/run/systemd/nspawn. All machinectl commands should work.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-06-04 18:20:03 +03:00