Commit graph

685 commits

Author SHA1 Message Date
Alex Crawford
c3264abc96 docs: fix reference to Fedora CoreOS
CoreOS hasn't existed since late 2016 and refers to the now-defunct
Container Linux. Fedora CoreOS is an entirely separate project.
2020-10-15 17:17:30 +02:00
Ondřej Míchal
bbc23f3fb0 test/system: Test that toolboxes start alright 2020-10-09 18:40:09 +02:00
Ondřej Míchal
ecc796246b playbooks: Bump fedora-toolbox image to f34 for Rawhide 2020-10-08 15:07:42 +02:00
Debarshi Ray
03c69894df Prepare 0.0.96 2020-10-01 20:02:57 +02:00
Debarshi Ray
f72aa7bd86 cmd/initContainer: Give access to /tmp from the host operating system
Some users tend to put random throwaway files in /tmp, so having that
location shared across the host operating system and toolbox containers
makes it a more pleasant user experience.

One nice side-effect of this is that it also makes the local file
system socket in /tmp/.X11-unix used by X11 clients available to
toolbox containers. So far, X11 clients inside toolbox containers used
the local abstract socket. However, since GNOME 3.38, Mutter no longer
listens on the abstract socket and only uses the file system socket to
start the Xwayland server [1]. Therefore, this makes it possible to
run X11 clients inside toolbox containers running on a GNOME 3.38 host.

[1] Mutter commit e2123768f635ee89
    https://gitlab.gnome.org/GNOME/mutter/-/issues/1289

https://github.com/containers/toolbox/issues/562
2020-10-01 18:21:42 +02:00
Ondřej Míchal
be9b7dd07f cmd/initContainer: Give access to the udev database
This prevents devices from losing properties that would otherwise be
set on the host operating system. It's useful when developing software
like PipeWire that uses libudev to enumerate devices.

https://github.com/containers/toolbox/issues/468
2020-10-01 16:19:51 +02:00
Ondřej Míchal
c795af57a8 cmd/initContainer: Do create a symlink if the containerPath was absent
The redirectPath function used to error out when handling directories,
if the path inside the container was initially absent. There's no real
reason for this, and some containers failed to start because the
/media directory was absent from them. This can happen as a
consequence of Fedora's filesystem RPM failing 'dnf update'
transactions inside containers:
  $ toolbox enter f33-to-upgrade
  $ dnf --assumeyes --enablerepo=fedora --disablerepo=rawhide update
  <...>
  Failed:
    filesystem-3.14-2.fc32.x86_64
    filesystem-3.14-3.fc33.x86_64

  Error: Transaction failed

Therefore, it's better to not worry about the path being initially
absent, and be more forgiving and robust.

https://github.com/containers/toolbox/issues/539
2020-10-01 15:51:25 +02:00
Ondřej Míchal
40e7e6081e zuul: Really enable system tests on Fedora 33
The tests were defined but not actually enabled in any pipeline.

Fallout from https://github.com/containers/toolbox/pull/550
2020-09-23 22:49:47 +02:00
Ondřej Míchal
ff4e4905da zuul, playbooks: Enable system tests on Fedora 33
https://github.com/containers/toolbox/pull/550
2020-09-08 14:54:07 -04:00
Ryan McGuire
0c08a42ac8 cmd/run: Don't break GNU Readline's ctrl-p shortcut
Podman sets 'ctrl-p ctrl-q' as the default key sequence for detaching
a container. This breaks the ctrl-p shortcut that's equivalent to the
up arrow key in GNU Readline environments like Bash and Emacs.
Moreoever, toolbox containers aren't meant to be detached in the first
place.

Since Podman 1.8.1, it is now possible to unset the key sequence for
detaching [2, 3].

[0] https://tiswww.cwru.edu/php/chet/readline/readline.html#SEC15

[1] https://www.gnu.org/software/emacs/tour/

[2] Podman commit 7c623bd41ff3d534
    https://github.com/containers/podman/issues/4208

[3] Podman commit ebfd253fc658ffc9
    https://github.com/containers/podman/issues/5166

https://github.com/containers/toolbox/issues/394
2020-09-02 18:42:59 +02:00
Leonard König
9840ca55a1 pkg/utils: Update default release to 31 for non-fedora hosts
Fedora 30 reached End of Life on 26th May:
https://fedoraproject.org/wiki/End_of_life

https://github.com/containers/toolbox/pull/546
2020-08-30 23:30:41 +02:00
Debarshi Ray
b3f0a50652 Prepare 0.0.95 2020-08-30 22:40:16 +02:00
Debarshi Ray
9ea6fe5852 Unbreak 'sudo' inside toolbox containers with Podman 2.0.5
Since Podman 2.0.5, containers that were created with
'podman create --userns=keep-id ...' automatically get the user added
to /etc/passwd [1]. However, this user isn't as fully configured as it
needs to be. The home directory is specified as '/' and the shell is
/bin/sh.

Note that Podman doesn't add the user's login group to /etc/group [2].
This leads to the following error message when entering the container:
  /usr/bin/id: cannot find name for group ID 1000

It's expected that this will be fixed in Podman itself.

Therefore, the entry point needs to call usermod(8) to update the user,
instead of using useradd(8) to create it.

[1] Podman commit 6c6670f12a3e6b91
    https://github.com/containers/podman/pull/6829

[2] https://github.com/containers/podman/issues/7389

https://github.com/containers/toolbox/issues/523
2020-08-30 22:31:10 +02:00
Debarshi Ray
59f4a79251 cmd/initContainer: Split out the code to configure the user
This will make the subsequent commit easier to read.

https://github.com/containers/toolbox/issues/523
2020-08-30 20:27:29 +02:00
Martin Pitt
15173f8c25 Unbreak 'enter' on Fedora CoreOS
... and other hybrid set-ups where the host and container OSes aren't
the same.

The entry point of a toolbox container already runs as root:root.
Therefore, there's no need to run it with an additional group.
Interactive shells spawned by 'sudo su -' both inside the container
and on the host don't run with such an additional group either. They
run just as root:root.

This prevented toolbox containers from starting up on Fedora CoreOS
hosts, because CoreOS has both the 'sudo' and 'wheel' groups but the
fedora-toolbox images only have the 'wheel' group. Therefore, it
ended up calling 'podman create --group-add sudo ...', and since the
'sudo' group was missing from the image, the container failed to start.

The --group-add flag was added in commit 4bda42d414 when the
entry point ran as $USER as specified in the user-specific customized
image. The additional group was specified to retain consistency with
interactive shells run as $USER.

Since then, things have changed. There's no longer any user-specific
customized image and commit f74400f450 made the entry point run
as root:root. The --group-add flag should have been removed as part of
those changes.

https://github.com/containers/toolbox/issues/423
2020-08-28 23:38:49 +02:00
Martin Pitt
3b6b9e9396 cmd/initContainer: Fix typo
Fallout from 772b66bf3e

https://github.com/containers/toolbox/pull/545
2020-08-28 19:15:29 +02:00
Debarshi Ray
166b09b822 profile.d: Warn if $TERM has no terminfo entry in the container
It tries to loosely mimic ncurses to look up a terminfo entry for the
current terminal, as mentioned in the terminfo(5) manual. Unlike
ncurses, it doesn't handle TERMINFO_DIRS, though, to avoid parsing an
array of directories for the sake of simplicity.

Every line of code in this file is part of the interactive shell's
start-up sequence, which makes it a trade-off between correctness and
speed. Therefore, the purpose of this warning is not to exhaustively
catch all possible corner cases, but to serve as a convenience in the
majority of cases. Ultimately, if someone is using an exotic terminal
set-up, then a missing warning is a minor price to pay in order to not
slow things down for the vast majority of users who don't.

Based on code written by Mert Alp Taytak:
https://github.com/containers/toolbox/pull/515

https://github.com/containers/toolbox/issues/505
2020-08-28 17:27:49 +02:00
Ondřej Míchal
88a95b07af cmd/initContainer: Try to handle config files that're absolute symlinks
Currently toolbox containers can get misconfigured if some
configuration files on the host are absolute symbolic links to some
other location.

For example, when systemd-resolved is used to manage /etc/resolv.conf
on the host, and if the file is an absolute link to
/run/systemd/resolve/stub-resolv.conf, then /etc/resolv.conf ends up
being invalid inside the container. This happens because the
container's /etc/resolv.conf points to /run/host/etc/resolv.conf, which
in turn points to /run/systemd/resolve/stub-resolv.conf, but that's
absent from the container.

This is, of course, not a problem with relative symbolic links. If the
host had a relative link to ../run/systemd/resolve/stub-resolv.conf,
then it would continue to work inside the container.

One solution would have been to use flatpak-session-helper to maintain
a copy of the host's /etc/resolv.conf in
$XDG_RUNTIME_DIR/.flatpak-helper/monitor. However, that doesn't work
when toolbox(1) is run as root.

The other option is to prepend the destination of the absolute symbolic
link with /run/host to make it resolve inside the container. It might
not work with funky links, but it's enough for the common case where a
an administrator changed the host's /etc/resolv.conf into a sane, but
absolute, symbolic link.

Properly configured hosts should anyway use relative symbolic links,
because they don't need to be adjusted in such scenarios. That's also
what Fedora and Ubuntu do, by default.

Thanks to Tudor Roman for raising a concern about relative symbolic
links.

Based on Martin Pitt's work on the POSIX shell implementation:
https://github.com/containers/toolbox/pull/380

https://github.com/containers/toolbox/issues/187
2020-08-28 13:55:01 +02:00
Debarshi Ray
10b7de5e6c cmd/root: Limit the scope of the error
https://github.com/containers/toolbox/pull/542
2020-08-26 23:40:24 +02:00
Debarshi Ray
354a69bede cmd/root: Simplify code by using os.Create instead of syscall.Open
https://github.com/containers/toolbox/pull/542
2020-08-26 23:40:21 +02:00
Debarshi Ray
fac565bc33 cmd/root: Rename a variable
https://github.com/containers/toolbox/pull/542
2020-08-26 23:40:15 +02:00
Debarshi Ray
69cec92abb Prepare 0.0.94 2020-08-24 19:31:28 +02:00
Debarshi Ray
80c02344df Silence SC2086
Otherwise https://www.shellcheck.net/ would complain:
  Line 729:
  if $podman_command image exists localhost/$base_toolbox_image
    >/dev/null 2>&3; then
                                            ^-----------------^
    SC2086: Double quote to prevent globbing and word splitting.

See: https://github.com/koalaman/shellcheck/wiki/SC2086

https://github.com/containers/toolbox/pull/537
2020-08-24 19:30:12 +02:00
Debarshi Ray
1dce87c5f1 libc-wrappers: Tighten the definition of the ppc64le definition
This is based on the output of 'gcc -dM -E - </dev/null' on a ppc64le
system. For what it's worth, the _CALL_ELF macro is defined as 1 on
the big endian variants of the architecture.

The original intention in commit 6ad9c63180 was to support the
architectures that Fedora builds for, and it doesn't care about PowerPC
variants that aren't ppc64le [1].

[1] https://fedoraproject.org/wiki/Architectures/PowerPC

https://github.com/containers/toolbox/pull/536
2020-08-24 19:03:24 +02:00
Debarshi Ray
aa1235f4fb README.md: Mention that sudo(8) should work without a password
It turns out that this doesn't work out-of-the-box on openSUSE and
needs to be explicitly configured.

https://github.com/containers/toolbox/issues/452
2020-08-21 17:41:59 +02:00
Debarshi Ray
6ad9c63180 build: Ensure binaries built on Fedora 33 run on Fedoras 32 & 31
The /usr/bin/toolbox binary is not only used to interact with toolbox
containers and images from the host. It's also used as the entry point
of the containers by bind mounting the binary from the host into the
container. This means that the /usr/bin/toolbox binary on the host must
also work inside the container, even if they have different operating
systems.

In the past, this worked perfectly well with the POSIX shell
implementation because it got intepreted by whichever /bin/sh was
available.

The Go implementation also mostly worked so far because it's largely
statically linked, with the notable exception of the standard C
library. However, recently glibc-2.32, which is used by Fedora 33
onwards, added a new version of the pthread_sigmask symbol [1] as part
of the libpthread removal project:
  $ objdump -T /usr/bin/toolbox | grep GLIBC_2.32
  0000000000000000      DO *UND*	0000000000000000  GLIBC_2.32
    pthread_sigmask

This means that /usr/bin/toolbox binaries built against glibc-2.32 on
newer Fedoras pick up the latest version of the symbol and fail to run
against older glibcs in older Fedoras.

One way to fix this is to disable the use of any C code from Go by
using the CGO_ENABLED environment variable [2]. However, this can
negatively impact packages like "os/user" [3] and "net" [4], where the
more featureful glibc APIs will be replaced by more limited
equivalents written only in Go.

Instead, since glibc uses symbol versioning, it's better to tell the
Go toolchain to avoid linking against any symbols from glibc-2.32.

This was accomplished by a few linker tricks:

  * The GNU ld linker's --wrap flag was used when building the Go code
    to divert pthread_sigmask invocations from Go to another function
    called __wrap_pthread_sigmask.

  * A static library was added to provide this __wrap_pthread_sigmask
    function, which forwards calls to the actual pthread_sigmask API in
    glibc. This library itself was not linked with --wrap, and
    specifies the latest permissible version of the pthread_sigmask
    symbol from glibc for each architecture. Currently, the list of
    architectures covers the ones that Fedora builds for.

  * The Go cmd/link linker was switched to external mode [5]. This
    ensures that the final object file containing all the Go code gets
    linked to the standard C library and the wrapper static library by
    the GNU ld linker for the --wrap flag to kick in.

Based on ideas from Ondřej Míchal.

[1] glibc commit c6663fee4340291c
    https://sourceware.org/git/?p=glibc.git;a=commit;h=c6663fee4340291c

[2] https://golang.org/cmd/cgo/

[3] https://golang.org/pkg/os/user/

[4] https://golang.org/pkg/net/

[5] https://golang.org/src/cmd/cgo/doc.go

https://github.com/containers/toolbox/issues/529
2020-08-21 16:29:37 +02:00
Ondřej Míchal
3fee36c885 images: Add fedora-toolbox image definition for Fedora 34
https://github.com/containers/toolbox/pull/532
2020-08-21 16:13:28 +02:00
Juanje Ojeda
464ea7cb28 README: Add missing parameter at the installation instructions
https://github.com/containers/toolbox/pull/516
2020-08-20 04:22:24 -04:00
Ondřej Míchal
ff1fab0f52 cmd/rmi, pkg/podman: Move 'removeImage' func to podman pkg
The 'removeImage' function should go into 'pkg/podman' because it wraps
around Podman's command. Because it no longer has access to the commands
- toolbox rmi - parameters it has a new forceDelete parameter.

https://github.com/containers/toolbox/pull/519
2020-08-14 11:00:06 +02:00
Ondřej Míchal
2ecaaf8ba3 cmd/rm, pkg/podman: Move 'removeContainer' func to podman pkg
The 'removeContainer' function should go into 'pkg/podman' because it
wraps around Podman's command. Because it no longer has access to the
commands - 'toolbox rm' - parameters it has a new forceDelete parameter.

https://github.com/containers/toolbox/pull/519
2020-08-14 11:00:06 +02:00
Harry Míchal
6741ff3a26 cmd/initContainer: Add more information to errors from redirectPath
https://github.com/containers/toolbox/pull/527
2020-08-13 18:36:36 +02:00
Ondřej Míchal
f246d20fa6 build: Install the tests
Installing the tests will let downstream distributors like Fedora run
them as part of their build and CI systems.

https://github.com/containers/toolbox/pull/511
2020-08-13 11:34:37 +02:00
Ondřej Míchal
6eba08ff9e Add CONTRIBUTING.md
Having some contributing guidelines is good!

I wrote of this mostly from top of my head (but I took inspiration from
projects like Podman or Atom). Maybe some parts are not very clear.
2020-08-12 11:57:41 +02:00
Harry Míchal
09896ebfcd Update issue templates
Bug reporters most of the time don't know what and how much info they
should share with us.

I heavily based the bug report template on Podman's[0].

[0] https://github.com/containers/podman/blob/master/.github/ISSUE_TEMPLATE.md

https://github.com/containers/toolbox/pull/459
2020-08-12 11:51:39 +02:00
Debarshi Ray
2befde83d1 cmd/initContainer: Mount a tmpfs at /tmp to match the host
Podman doesn't mount a tmpfs at /tmp by default - it needs to be
separately requested. However, doing it as part of 'podman create ...'
won't add a tmpfs at /tmp for existing toolbox containers. Therefore,
it's best done as part of the entry point.

The mount options are the same as used by systemd (see tmp.mount) to
provide a tmpfs at the host's /tmp.

For what it's worth, the mount flags do differ slightly from the host.

The host has:
$ findmnt --output OPTIONS,PROPAGATION /tmp
OPTIONS                  PROPAGATION
rw,nosuid,nodev,seclabel shared

The container has:
$ findmnt --output OPTIONS,PROPAGATION /tmp
OPTIONS                                        PROPAGATION
rw,nosuid,nodev,seclabel,uid=100000,gid=100000 private

The uid and gid options don't show up on the host because both are 0,
and hence skipped by the tools.

https://github.com/containers/toolbox/issues/513
2020-08-05 16:29:30 +02:00
Debarshi Ray
679680df59 cmd/run: Make it more obvious when falling back to /bin/bash
Users, who prefer shells other than Bash, tend to get confused when
Toolbox presents a Bash prompt to them. It would be better to be more
upfront about what the problem is, so that users can self-support
themselves.

https://github.com/containers/toolbox/issues/18
2020-08-04 14:11:51 +02:00
Debarshi Ray
238a678264 Prepare 0.0.93 2020-07-24 17:44:51 +02:00
Ondřej Míchal
8168e0f58c cmd/list: Handle API change of Podman 2.1 in podman images
Since Podman 2.1 the field 'Created' of `podman images --format json`
no longer holds a string with human-readable string but holds a Unix
time integer[0].

[0] https://github.com/containers/podman/pull/6815

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:59 +02:00
Ondřej Míchal
e772207831 cmd/list, cmd/run: Decode image/container JSONs to typed structs
Every time Podman changes their JSON API Toolbox breaks horribly. That
is caused by the combination of decoding the JSON purely by hand and by
the complete lack of type assertions to make the process stable.

I previously didn't know that unmarshalling with Go works on the 'do
the best job it can' logic (thank you Owen!). This makes the need to
check for subtle changes in the names of fields go away and type
checking a bit more bearable (marking the questioned field as
interface{} and then immediatelly type switch).

If even now an existing field does not hold an expected value the field
will remain blank.

To take this a bit further, I created two types (toolboxImage and
toolboxContainer) that are used by both functions for returning the
list of images and containers. Instead of using getters for properties
that need some checks or adjustments this uses a custom unmarshaling
function (Owen's idea; thanks!).

The work around populating the two new types is a bit hacky
(marshalling and already unmarshalled JSON - that was unmarshalled to
[]map[string]interface{} - that is then unmarshalled to either
toolboxImage or toolboxContainer. This is done to prevent a major
refactoring before the 0.1.0 release. This should be changed for the
0.2.0 release.

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:59 +02:00
Ondřej Míchal
4028c3ae3f pkg/utils: Add function creating human-readable duration strings
https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:57 +02:00
Ondřej Míchal
0e5c30d971 build: Add github.com/docker/go-units
This package will be used for generating a human-readable
representation of elapsed time (e.g., "5 minutes").

https://github.com/containers/toolbox/pull/503
2020-07-24 17:31:51 +02:00
Debarshi Ray
06ef424c71 cmd/run: Adjust for changes in 'podman ps' in Podman 2.0
The key containing the container's name (ie., "Names") is no longer a
string, but a slice of strings.

https://github.com/containers/toolbox/pull/509
2020-07-23 15:28:02 +02:00
Ondřej Míchal
2aad8385e1 cmd/create: Update hint after creating a container
Rewritten version of Toolbox supports newer syntax for entering a
container: `toolbox enter <name-of-container>`. This new workflow should
be shown in the hint after creating a container with `toolbox create`.

https://github.com/containers/toolbox/issues/489
2020-07-22 23:56:26 +02:00
Harry Míchal
61a5f5158c cmd/list: Re-enable highlighting of running containers
The Go implementation did not highlight running containers because it
uses a special table writer from 'text/tabwriter' that does not
support colored output [0].

The trick used here is to use ANSI SGR terminal escape sequences [1]
on every line output by the table writer, including headers, and make
the escape sequences use the same number of characters. eg., even
though it's idiomatic to use "\033[0m" to reset the SGR attributes,
such as color; each non-colored line is prefixed with "\033[0;00m" to
ensure that it has the same number of characters as "\033[1;32m", which
is used for bold green output.

Therefore, not only are the non-colored lines wrapped in a redundant
pair of ANSI SGR terminal escape sequences, they are carefully crafted
to match the escape sequences for colored output.

Tested on VTE and xterm.

[0] https://github.com/golang/go/pull/35017
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters

https://github.com/containers/toolbox/pull/494
2020-07-22 23:29:44 +02:00
Ondřej Míchal
68c585f8b3 test/system: Don't check the output of 'toolbox run'
For some reason running 'toolbox run echo Hello World' in the tests in
the environment of Zuul is causing problems. Bats saves the output of
ran command to $output that can be then checked if it contains the right
output. This variable sometimes holds in this case the right output
("Hello World") but more often it is blank, causing the tests to fail.

I don't know the culprit, so for now I'm commenting out the checks to
make the CI pass again.

https://github.com/containers/toolbox/issues/410
2020-07-22 14:47:42 +02:00
Ondřej Míchal
8c971b381a playbooks, .zuul: Clarify naming and descriptions
Not all tests are the same and the ones we're currently running are
system tests. Also the mention of 'podman-stable' is not that important
because we're using the version in the 'stable' stream of Fedora
releases.

https://github.com/containers/toolbox/pull/508
2020-07-21 17:09:17 +02:00
Harry Míchal
cf1b74e1db .zuul, playbooks/fedora-32: Enable testing for Fedora 32
New release out, we need to run the tests there.

https://github.com/containers/toolbox/pull/507
2020-07-21 16:31:56 +02:00
Harry Míchal
5a651eae2f playbooks, test/system: Test the Go implementation and update tests
In the Go implementation, when the 'rm' and 'rmi' commands fail to
remove a container or image, they don't use a non-zero exit code.
There's currently no nice fix for this. So, the tests have been
adjusted as a temporary measure.

https://github.com/containers/toolbox/pull/507
2020-07-21 16:31:50 +02:00
Harry Míchal
9c5bc56bbd playbooks: Add Go to the list of build dependencies
Otherwise, the tests on Fedora 31 and Rawhide fail with:
  meson.build:8:0: ERROR: Program(s) ['go'] not found or not executable

https://github.com/containers/toolbox/pull/506
2020-07-21 16:04:40 +02:00
Debarshi Ray
bf815d3d73 cmd/create: Restore the spinner, when pulling an image, to stdout
This doesn't seem to have any user-visible effect. However, since the
line was inadvertently removed, it's good to put it back.

Fallout from 950f510872

https://github.com/containers/toolbox/pull/498
2020-07-10 12:36:03 +02:00