bottlerocket-os / bottlerocket-os/bottlerocket-core-kit
`apiclient exec` ignores `TERM` environment variable
- Dominant language
- Rust
- Stars
- 34
- Forks
- 77
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 23
Description
**Package I'm using:**
`apiclient`
**What I expected to happen:**
I expect that `apiclient` uses the `TERM` configured here:
https://github.com/bottlerocket-os/bottlerocket-core-kit/blob/cf79a2b9c4c57665d2078019e367cbe3239a62ac/sources/api/apiserver/src/server/exec/child.rs#L125
**What actually happened:**
The `TERM` environment variable is set for the process calling `ctr` but not for the actual process `exec`'d in the container:
```
# Process running ctr, forked by apiserver
[root@admin]# ps aux | grep "task exec"
root 85291 0.1 0.0 1846756 25168 ? Ssl+ 19:07 0:00 /usr/bin/ctr -a /run/host-containerd/containerd.sock task exec --exec-id apiexec-PwuupPC70QMeV8xD --tty admin bash
[root@admin]# cat /proc/85291/environ
TERM=screen
# The actual process that exec'ed
[root@admin]# cat /proc/self/environ
NO_PROXY=localhost,127.0.0.1,032e431c8c6db4d7c0b634561b5195bd.gr7.us-west-2.eks.amazonaws.com,.cluster.localPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/SHLVL=1HOME=/rootno_proxy=localhost,127.0.0.1,032e431c8c6db4d7c0b634561b5195bd.gr7.us-west-2.eks.amazonaws.com,.cluster.local_
```
**How to reproduce the problem:**
From the `control` container, just `apiclient exec admin bash` and check `TERM`;
```bash
[ssm-user@control]$ apiclient exec admin sh -c 'echo $TERM'
dumb
```
I haven't nail down where is this `dumb` coming from. Is not set by `ctr` and it isn't in the environment variables list as shown above. My guess is that it is an automatic value set by the terminal emulator.
I tried to force `ctr` to override this env variable, but `ctr` doesn't allow overrides in `exec`. One thing to try is to force the container image to have `ENV TERM=screen`, so that the main container process always has `TERM` set and theoretically, `ctr` will respect that when forking the `exec`'d process.
Contributor guide
Research direction
Start with the `apiclient exec` entry point and compare its environment handling with `sources/api/apiserver/src/server/exec/child.rs` around line 125. Reproduce the issue with `apiclient exec admin sh -c 'echo $TERM'`; done means the configured `TERM` value reaches the exec'd process instead of unexpectedly becoming `dumb`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100