1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 03:19:47 +03:00
Commit graph

39 commits

Author SHA1 Message Date
Casey Connolly
4210e98c02 pmbootstrap: fix running ssh in a user namespace
Since we are root in the namespace, ssh will attempt to use the root
users config, additionally the ssh_config.d directory will have invalid
permissions (since it's owned by root on the host which is not mapped
into the userns).

Hack around all of these with some fancy mounts in the sandbox.

The "proper" way to do this would be to stop using the host rootfs
alltogether and unshare ourselves into an Alpine chroot, with the
users .ssh directory mounted in. But that will require refactoring
pmbootstrap's init code to be able to parse args and do actions before
entering the namespace.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:23 +02:00
Casey Connolly
9e2bba8d7a add a tmpfs for scratch data
Some data like kernel mount overlays and the apk progress fifo don't
need to stick around, let's put them in a special new tmpfs which is
destroyed when pmbootstrap exits.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:23 +02:00
Casey Connolly
6e39b495ea HACK: support install --disk by chowning the target block device prior to unshare()
By making the block device writable by our user, we solve the problem of
needing sudo which isn't available in the user namespace.

Solve this by doing some hacky early argument parsing and prompting the
user to chown the block device.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:23 +02:00
Casey Connolly
5ddb7d66f7 remove --as-root
Running pmbootstrap as root doesn't work anymore, and there should never
be a need for this. Let's just stop supporting this usecase.

Error:

Traceback (most recent call last):
  File "/home/cas/bin/pmbootstrap", line 61, in <module>
    sandbox.setup_mounts(fsops)
  File "/home/cas/pmos/pmbootstrap/pmb/init/sandbox.py", line 975, in setup_mounts
    mount(".", "/", "", MS_MOVE, "")
  File "/home/cas/pmos/pmbootstrap/pmb/init/sandbox.py", line 170, in mount
    oserror("mount", dst)
  File "/home/cas/pmos/pmbootstrap/pmb/init/sandbox.py", line 145, in oserror
    raise OSError(ctypes.get_errno(), os.strerror(ctypes.get_errno()), filename or None)
OSError: [Errno 22] Invalid argument: '/'

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:23 +02:00
Casey Connolly
cb1bdcb6d0 pmbootstrap: fix CWD after mount setup
After we pivot into the new mount namespace we need to reset our CWD for
some commands to work.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:22 +02:00
Casey Connolly
20807bce86 pmbootstrap: unshare PID namespaec
Put ourselves in a new PID namespace so that daemons we might start in
the chroot like adbd will be killed on exit.

This simplifies "shutdown" since we no longer need to kill these
processes.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:35:06 +02:00
Casey Connolly
c500d95875 pmbootstrap: sanitize the environment a little
Clean up the environment a little, set shell to something known

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:35:06 +02:00
Casey Connolly
4030cd4d61 unshare binfmt
Rework how we handle binfmt_misc so it will work inside a user
namespace.

* Use a custom mountpoint (only accessible inside the mount namespace),
  this is the crux of the change, allowing us to mount it as non-root
  and avoid messing with any host configs too!
* No longer explicitly modprobe binfmt_misc, any modern system should
  probe it automatically when we try to mount it... I think so anyways
  heh

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:30:04 +02:00
Casey Connolly
a29076572b unshare pmbootstrap!
Use sandbox functions to unshare the entire pmbootstrap process with
user namespaces.

This lets us do whatever we want without polluting the global mount
namepsace, and eliminates the need for "pmbootstrap shutdown".

Currently install is broken since it uses loop devices, this should be
addressed by using something like systemd.repartd (or doing all the
offset calculation and gpt stuff ourselves).

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:30:04 +02:00
Casey Connolly
a3de41ff59 pass in original UID
detect running as root before entering the user namespace.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:30:04 +02:00
Oliver Smith
5d28c5ccf3
pmbootstrap.py: move all features to pmb:main()
Prepare to modernize the python packaging. pmbootstrap.py will not be
part of the packaging, so add a note there and move both features
(python version check, ^C check) to pmb/__init__.py:main().

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230407233026.1712-3-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:37 +02:00
Oliver Smith
49cd288078
pmbootstrap.py: require at least python 3.7
The minimum python version was already increased to 3.7, but it wasn't
adjusted here yet.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230407233026.1712-2-ollieparanoid@postmarketos.org%3E
2023-04-15 01:44:36 +02:00
Oliver Smith
9975d373b0
Bump copyright to 2023 2023-01-22 19:18:06 +01:00
Oliver Smith
6f6a3b0408
Happy new year 2022! 2022-01-02 22:39:14 +01:00
Newbyte
446a8fc430
pmbootstrap.py: Check which version of Python pmbootstrap is run with (MR 2118)
This prevents people from getting strange syntax errors if they
accidentally run pmbootstrap with e.g. Python 2.
2021-10-01 22:46:23 -07:00
Newbyte
73d242485a
pmbootstrap.py: Don't print stacktrace when KeyboardInterrupt is caught (MR 2078)
This looks obnoxious and I cannot think of a single time I found it
useful, so let's make it prettier.
2021-07-05 12:19:35 +02:00
Oliver Smith
1c791da482
treewide: bump copyright to 2021 2021-01-07 23:30:47 +01:00
Oliver Smith
f21c216a26
Cosmetic: use SPDX license header (!1877)
While at it, also remove unnecessary "#!/usr/bin/env python3" in files
that only get imported, and adjust other empty/comment lines in the
beginnings of the files for consistency.

This makes files easier to read, and makes the pmbootstrap codebase more
consistent with the build.postmarketos.org codebase.
2020-02-24 03:11:10 +03:00
Oliver Smith
948e3f931f
Change copyright to 2020 2020-01-06 02:43:00 +01:00
Oliver Smith
f16bdaf0ca
Update copyright to 2019
Happy new year \o/
2019-01-02 09:31:20 +01:00
Grant Miller
7eaf9de000 Implement bash tab completion 2018-08-27 21:35:05 +00:00
Oliver Smith
7750c1dd40
Happy new year! (update copyright to 2018) 2018-01-04 04:53:35 +01:00
Yuval Adam
b6003a2815 Close #327: Add initial setup.py (#443) 2017-09-02 19:30:40 +00:00
Oliver Smith
1aae094b50 Close #174: Put frontend functions in extra file (#185) 2017-07-18 19:01:11 +00:00
clayton craft
fc3e4bfe4a Fix PR #160, Fix #172 (#173)
Thanks craftyguy!
Probably meant to call 'globals()' and not 'locals()'. As @MartijnBraam
pointed out in IRC, probably best to have these functions in a separate
module so they can be parsed with getattr
2017-07-17 18:41:39 +00:00
cclauss
a502b50475 Reduce complexity in pmbootstrap.py (#160)
Thanks, @cclauss!

* Dictionary lookup of event loop actions

This was kind of an experiment that adds lots of blank lines to this script -- feel free to reject it.

The observation that triggered this was that in main() all actions can execute using just one parameter, args.  This means that it is possible to use args.action to do a dict lookup to get the corresponding function.  This approach adds tons of blank lines to the script in exchange for a rapid seek to the action implementation and a substantial reduction of the McCabe complexity of main().

$ __flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics__
```
./pmbootstrap.py:43:1: C901 'main' is too complex (23)
./pmb/aportgen/core.py:38:1: C901 'rewrite' is too complex (17)
[ ... ]
```

* Remove action_dict and use locals() instead
2017-07-17 15:38:45 +00:00
Oliver Smith
34622368d9
Fix #107: Grsec check: read file in /proc as root 2017-07-11 18:50:40 +02:00
Oliver Smith
51bdc24315 Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.

I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.

To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.

In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.

In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".

This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.

Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).

The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
Oliver Smith
05e79c1d5c
Fix #107: Meaningful error for grsecurity/chroot_deny_chmod 2017-07-06 21:16:00 +02:00
Oliver Smith
10fd0f312d
Display short troubleshooting URL on exception 2017-07-06 19:09:45 +02:00
Oliver Smith
fcc5501a44
Slightly improve error handling
* Fix: Do not swallow traces when crashing before log init (e.g.
  during argument parsing)
* Show a link to the troubleshooting page, when an error happens
* (Formatting done by autopep8 in pmb/config/init.py)
2017-06-27 00:23:21 +02:00
Oliver Smith
fb1e8ec73b
Update min apk version/add more apk version checks
* Minimum version: 2.7.2 (which fixes two CVEs)
* Check the minimum apk version before doing something with apk and
  before entering the chroot manually (previously, it has just checked
  the apk-tools-static version, which gets used to set up the chroot)
* Reword the message for an outdated APK version. Most likely it is
  just the outdated http cache, instead of a man-in-the-middle attack.

See also:
b849b481a0
2017-06-23 17:04:49 +02:00
Oliver Smith
112dc5e70c
Move challenge code to own folder (#64)
...and add a stub for 'pmbootstrap challenge APKINDEX.tar.gz'.
2017-06-17 17:42:28 +02:00
Oliver Smith
3a3dd8063f
Merge branch 'lazy-reproducible-builds'
We have "lazy reproducible builds" now. What I mean by that is, that
the resulting "apk" archive is not fully reproducible, but all binaries
inside it are. This is necessary to kick-off the binary repo, which is
in turn required to get the testsuite going on Travis. Read #64 for more
information.

Usage:
```
pmbootstrap build hello-world --buildinfo
pmbootstrap challenge /tmp/path/to/hello-world-1-r2.apk
```

The "--buildinfo" parameter generates a "buildinfo.json", which contains
the versions of all dependencies. It is not very optimizied, so this
is a performance bottleneck and takes 10 seconds (which is quite much
considering that the hello-world package builds in less than a second).
This can be improved in the future, and then the buildinfo parameter
may become the default.
2017-06-11 14:19:57 +02:00
Oliver Smith
18339d0a14
Close #69: add 'pmbootstrap initfs' and improve initfs workflow
* allows to build/extract/list initramfs, add/del hook
* rebuild the initfs whenever running install or trying to flash/boot it
* flasher flash/boot: automatically set up a minimal rootfs with kernel and initfs,
  if it does not exist yet
2017-06-09 19:22:25 +02:00
Oliver Smith
32ad868cdc
apk.installed(): Retuns all packages and versions now
pmb.chroot.apk.installed() used to return only the explicitly installed
packages. This is not good enough for the initfs check functions (and
especially for the "lazy reproducible builds", from which branch this
commit was cherry picked).

This commit introduces more noise for the logfile - if this becomes
a problem, raise your voice in the issues tracker and we'll do something
about it.

(This commit also changes minor code styling in other files, I did
not run autopep8 last time, because flake8 didn't complain...)
2017-06-09 18:01:39 +02:00
Oliver Smith
50195a6af2
pmbootstrap log: Add a -n/--lines parameter (like tail has)
...also increase the default line count to 30, so it's easier to
spot an error if you didn't have the log open when it happened.

This parameter also works for 'pmbootstrap log_distccd', for consistency.
2017-06-08 18:15:38 +02:00
Oliver Smith
63ac1f5f6c
WIP #64: "lazy reproducible builds" 2017-06-05 03:58:45 +02:00
Oliver Smith
ae950fb9f7
Hello, there! 2017-05-26 22:08:45 +02:00