Public bug reported:

In Ubuntu 20.04, 24.04 and newer, containers started with affected lxc/lxc-utils
are not provided with a valid `container_ttys` environment variable, resulting
in non-functioning console when called via `lxc-console`. Upstream fixes are
available, and should be backported to stable Ubuntu releases.


## Steps to reproduce

Create and start an Ubuntu focal container:

        # apt update && apt install lxc-utils lxc-templates
        # lxc-create -n test-focal -t /usr/share/lxc/templates/lxc-ubuntu -- 
--release focal
        # lxc-start test-focal

View the environment variables of the init process inside the container:

        # lxc-attach test-focal -- bash -c "tr '\0' '\n' </proc/1/environ"
        ...

Try attaching to the default console of the container:

        # lxc-console test-focal
        ...

The issue is not specific to a particular distribution of version of the
container. What is important is that the container uses `container_ttys`
environment variable to spawn gettys on them. This is done by systemd, see [1].


## Expected results

1. `/proc/1/environ` within the container includes the `container_ttys`
environment variable with a list of virtual consoles:

        container=lxc
        container_ttys=pts/1 pts/2 pts/3 pts/4

2. `lxc-console test-focal` without any special arguments results in a working
console:

        # lxc-console test-focal
        
        Connected to tty 1
        Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a 
itself
        
        Ubuntu 20.04.6 LTS test-focal pts/1
        
        test-focal login:


## Actual results

1. `/proc/1/environ` either has an empty `container_ttys`, or it's not defined
at all:

On Ubuntu 20.04:

        container=lxc
        container_ttys=

On Ubuntu 24.04 and newer:

        container=lxc

2. `lxc-console test-focal` without any special arguments results in an empty,
non-functional console:

        # lxc-console test-focal

        Connected to tty 1
        Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a 
itself
        <nothing>


## Affected versions

Upstream:
* LXC 4.0.11 and 4.0.12
        Bug report: https://github.com/lxc/lxc/issues/4088
        Fixed in: https://github.com/lxc/lxc/pull/4089
* LXC 5.0.1 and newer
        Bug report: https://github.com/lxc/lxc/issues/4198
        Fixed in: https://github.com/lxc/lxc/pull/4544

Ubuntu:
* 20.04
        * `1:4.0.12-0ubuntu1~20.04.1` in `updates`
* 24.04
        * `1:5.0.3-2ubuntu7` in `release`
        * `1:5.0.3-2ubuntu7.1` in `updates`
* 24.10
        * `1:6.0.1-1ubuntu1` in `release`
        * `1:6.0.1-1ubuntu1.1` in `updates`
* 25.04
        * `1:6.0.3-1` in `release`
* 25.10
        * `1:6.0.3-1` in `release`
        * `1:6.0.4-2` in `proposed`

Packages in 20.04 `release`, 22.04 are unaffected.


## Patches

Attached patches are taken as-is from pull requests mentioned in the
"Affected versions" section.

* For Ubuntu 20.04: `3b9f84fd2397d06782bbf67dc8421463c43ab139.patch`
        This has been tested applied on top of `1:4.0.12-0ubuntu1~20.04.1` and 
is
        working.
* For Ubuntu 24.04 and newer: `0636ec66b950dd42342fc937cbba97365e92f01e.patch`
        This has been tested applied on top of `1:5.0.3-2ubuntu7.1` and is 
working.


## Workarounds
It is possible to define the `container_ttys` environment variable manually
in the container configuration file, or in host-wide LXC configuration,
for example:

        lxc.environment = container_ttys=/dev/pts/1 /dev/pts/2
/dev/pts/3 /dev/pts/4

This approach is fragile however, as the allocated device names can vary from
host to host, and also depend on the `lxc.tty.max` value (default is `4`).

Additionally it is possible to use `/dev/console` by specifying `-t 0`:

        lxc-console -t 0 <container_name>

which is available regardless of `container_ttys`.


## Motivation

We use LXC in an automated test environment, where `lxc-console` is used for
interacting with running containers. This functionality broke for us when we
upgraded our container host to Ubuntu 24.04.

Our original workaround was to use `/dev/console` by specifying `-t 0`. This
turned out to be problematic. We observed that, on large output, chunks of data
were missing, as the console couldn't keep up. This does not happen with
normally allocated virtual consoles.

We're currently manually specifying the `container_ttys` environment variable
host-wide, but this is a fragile workaround, we'd like to have a proper fix for
this.

I believe the scope of the attached patches is limited, and they restore
expected behaviour, thus they should be applied to packages in existing stable
Ubuntu releases.


[1]: 
https://github.com/systemd/systemd/blob/5e6dd20a6e217674f53f738f9fc84dbbf4506a63/docs/CONTAINER_INTERFACE.md#environment-variables

** Affects: lxc (Ubuntu)
     Importance: Undecided
         Status: New

** Patch added: "Patch for Ubuntu 24.04 and newer"
   
https://bugs.launchpad.net/bugs/2109890/+attachment/5875589/+files/0636ec66b950dd42342fc937cbba97365e92f01e.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2109890

Title:
  lxc: container_ttys env var not populated, leading to broken lxc-
  console

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/2109890/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to