Giter VIP home page Giter VIP logo

cntr's Introduction

cntr

Say no to $ apt install vim in containers! cntr is a replacement for docker exec that brings all your developers tools with you. This is done by mounting the file system from one container or the host into the target container by creating a nested container with the help of a FUSE filesystem. This allows to ship minimal runtime image in production and limit the surface for exploits.

Cntr was also published in Usenix ATC 2018. See bibtex for citation.

Demo

In this two minute recording you learn all the basics of cntr:

asciicast

Features

  • For convenience cntr supports container names/identifier for the following container engines natively:
    • docker
    • podman
    • LXC
    • LXD
    • rkt
    • systemd-nspawn
    • containerd
  • For other container engines cntr also takes process ids (PIDs) instead of container names.

Installation

Cntr can be only supports linux.

Pre-build static-linked binary

For linux x86_64 we build static binaries for every release. More platforms can added on request. See the release tab for pre-build tarballs. At runtime only commandline utils of the container engine in questions are required.

Build from source

All you need for compilation is rust + cargo. Checkout rustup.rs on how to get a working rust toolchain. Then run:

Either:

$ cargo install cntr

Or the latest master:

$ cargo install --git https://github.com/Mic92/cntr

For offline builds we also provided a tarball with all dependencies bundled here for compilation with cargo-vendor.

Usage

At a high-level cntr provides two subcommands: attach and exec:

  • attach: Allows you to attach to a container with your own native shell/commands. Cntr will mount the container at /var/lib/cntr. The container itself will run unaffected as the mount changes are not visible to container processes.
    • Example: cntr attach <container_id> where container_id can be a container identifier or process id (see examples below).
  • exec: Once you are in the container, you can also run commands from the container filesystem itself. Since those might need their native mount layout at / instead of /var/lib/cntr, cntr provides exec subcommand to chroot to container again and also resets the environment variables that might have been changed by the shell.
    • Example: cntr exec <command> where command is an executable in the container

Note: Cntr needs to run on the same host as the container. It does not work if the container is running in a virtual machine while cntr is running on the hypervisor.

$ cntr --help
Cntr 1.5.1
Jörg Thalheim <[email protected]>
Enter or executed in container

USAGE:
    cntr <SUBCOMMAND>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    attach    Enter container
    exec      Execute command in container filesystem
    help      Prints this message or the help of the given subcommand(s)
$ cntr attach --help
cntr-attach 1.5.1
Jörg Thalheim <[email protected]>
Enter container

USAGE:
    cntr attach [OPTIONS] <id> [command]...

FLAGS:
    -h, --help    Prints help information

OPTIONS:
        --effective-user <EFFECTIVE_USER>    effective username that should be owner of new created files on the host
    -t, --type <TYPE>                        Container types to try (sperated by ','). [default: all but command]
                                             [possible values: process_id, rkt, podman, docker, nspawn, lxc, lxd,
                                             containerd, command]

ARGS:
    <id>            container id, container name or process id
    <command>...    Command and its arguments to execute after attach. Consider prepending it with '-- ' to prevent
                    parsing of '-x'-like flags. [default: $SHELL]
$ cntr exec --help
cntr-exec 1.5.1
Jörg Thalheim <[email protected]>
Execute command in container filesystem

USAGE:
    cntr exec [command]...

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <command>...    Command and its arguments to execute after attach. Consider prepending it with '-- ' to prevent
                    parsing of '-x'-like flags. [default: $SHELL]

Docker

1: Find out the container name/container id:

$ docker run --name boxbusy -ti busybox
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
55a93d71b53b        busybox             "sh"                22 seconds ago      Up 20 seconds                           boxbusy

Either provide a container id...

$ cntr attach 55a93d71b53b
[root@55a93d71b53b:/var/lib/cntr]# echo "I am in a container!"
[root@55a93d71b53b:/var/lib/cntr]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
40: eth0@if41: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
[root@55a93d71b53b:/var/lib/cntr]# vim etc/resolv.conf

...or the container name. Use cntr exec to execute container native commands (while running in the cntr shell).

$ cntr attach boxbusy
[root@55a93d71b53b:/var/lib/cntr]# cntr exec -- sh -c 'busybox | head -1'

You can also use Dockerfile from this repo to build a docker container with cntr:

$ docker build -f Dockerfile . -t cntr
# boxbusy here is the name of the target container to attach to
$ docker run --pid=host --privileged=true -v /var/run/docker.sock:/var/run/docker.sock -ti --rm cntr attach boxbusy /bin/sh

Podman

See docker usage, just replace docker with the podman command.

LXD

1: Create a container and start it

$ lxc image import images:/alpine/edge
$ lxc launch images:alpine/edge
$ lxc list
+-----------------+---------+------+------+------------+-----------+
|      NAME       |  STATE  | IPV4 | IPV6 |    TYPE    | SNAPSHOTS |
+-----------------+---------+------+------+------------+-----------+
| amazed-sailfish | RUNNING |      |      | PERSISTENT | 0         |
+-----------------+---------+------+------+------------+-----------+

2: Attach to the container with cntr

$ cntr attach amazed-sailfish
$ cat etc/hostname
amazed-sailfish

LXC

1: Create a container and start it

$ lxc-create --name ubuntu -t download -- -d ubuntu -r xenial -a amd64
$ lxc-start --name ubuntu -F
...
Ubuntu 16.04.4 LTS ubuntu console
ubuntu login:
$ lxc-ls
ubuntu

2: Attach to container with cntr:

$ cntr attach ubuntu
[root@ubuntu2:/var/lib/cntr]# cat etc/os-release
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

rkt

1: Find out the container uuid:

$ rkt run --interactive=true docker://busybox
$ rkt list
UUID            APP     IMAGE NAME                                      STATE   CREATED         STARTED         NETWORKS
c2d2e87e        busybox registry-1.docker.io/library/busybox:latest     running 6 minutes ago   6 minutes ago   default:ip4=172.16.28.3

2: Attach with cntr

# make sure your container is still running!
$ cntr attach c2d2e87e
# Finally not the old ugly top!
[gen0@rkt-c2d2e87e-e798-4341-ae93-26f6cbb7c017:/var/lib/cntr]# htop
...

With cntr you can also debug stage1 of rkt - even there is no support from rkt itself.

$ ps aux | grep stage1
joerg    13546  0.0  0.0 120808  1608 pts/12   S+   11:10   0:00 grep --binary-files=without-match --directories=skip --color=auto stage1
root     22232  0.0  0.0  54208  2656 pts/7    S+   10:54   0:00 stage1/rootfs/usr/lib/ld-linux-x86-64.so.2 stage1/rootfs/usr/bin/systemd-nspawn --boot --notify-ready=yes --register=true --link-journal=try-guest --quiet --uuid=c2d2e87e-e798-4341-ae93-26f6cbb7c017 --machine=rkt-c2d2e87e-e798-4341-ae93-26f6cbb7c017 --directory=stage1/rootfs --capability=CAP_AUDIT_WRITE,CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FSETID,CAP_FOWNER,CAP_KILL,CAP_MKNOD,CAP_NET_RAW,CAP_NET_BIND_SERVICE,CAP_SETUID,CAP_SETGID,CAP_SETPCAP,CAP_SETFCAP,CAP_SYS_CHROOT -- --default-standard-output=tty --log-target=null --show-status=0

Therefore we use the process id instead of the container uuid:

$ cntr attach 22232
# new and exiting territory!
[root@turingmachine:/var/lib/cntr]# mount | grep pods
sysfs on /var/lib/cntr/var/lib/rkt/pods/run/c2d2e87e-e798-4341-ae93-26f6cbb7c017/stage1/rootfs/sys type sysfs (ro,nosuid,nodev,noexec,relatime)
tmpfs on /var/lib/cntr/var/lib/rkt/pods/run/c2d2e87e-e798-4341-ae93-26f6cbb7c017/stage1/rootfs/sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /var/lib/cntr/var/lib/rkt/pods/run/c2d2e87e-e798-4341-ae93-26f6cbb7c017/stage1/rootfs/sys/fs/cgroup/memory type cgroup (ro,nosuid,nodev,noexec,relatime,memory)

systemd-nspawn

1: Start container

$ wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-root.tar.xz
$ mkdir /var/lib/machines/ubuntu
$ tar -xf ubuntu-16.04-server-cloudimg-amd64-root.tar.xz -C /var/lib/machines/ubuntu
$ systemd-nspawn -b -M ubuntu
$ machinectl list
MACHINE CLASS     SERVICE        OS     VERSION ADDRESSES
ubuntu  container systemd-nspawn ubuntu 16.04   -

2: Attach

$ cntr attach ubuntu

Generic process id

The minimal information needed by cntr is the process id of a container process you want to attach to.

# Did you now chromium uses namespaces too?
$ ps aux | grep 'chromium --type=renderer'
joerg    17498 11.7  1.0 1394504 174256 ?      Sl   15:16   0:08 /usr/bin/chromium

In this case 17498 is the pid we are looking for.

$ cntr attach 17498
# looks quite similar to our system, but with less users
[joerg@turingmachine cntr]$ ls -la /
total 240
drwxr-xr-x   23 nobody nogroup    23 Mar 13 15:05 .
drwxr-xr-x   23 nobody nogroup    23 Mar 13 15:05 ..
drwxr-xr-x    2 nobody nogroup     3 Mar 13 15:14 bin
drwxr-xr-x    4 nobody nogroup 16384 Jan  1  1970 boot
drwxr-xr-x   24 nobody nogroup  4120 Mar 13 14:56 dev
drwxr-xr-x   52 nobody nogroup   125 Mar 13 15:14 etc
drwxr-xr-x    3 nobody nogroup     3 Jan  8 16:17 home
drwxr-xr-x    8 nobody nogroup     8 Feb  9 22:10 mnt
dr-xr-xr-x  306 nobody nogroup     0 Mar 13 09:38 proc
drwx------   22 nobody nogroup    43 Mar 13 15:09 root
...

Containerd

For containerd integration the ctr binary is required. You can get a binary by running:

$ GOPATH=$(mktemp -d)
$ go get github.com/containerd/containerd/cmd/ctr
$ $GOPATH/bin/ctr --help

Put the resulting ctr binary in your $PATH

1: Start container

$ ctr images pull docker.io/library/busybox:latest
$ ctr run docker.io/library/busybox:latest boxbusy
$ ctr tasks lists
TASK        PID      STATUS
boxbusy    24310    RUNNING

2: Attach

$ cntr attach boxbusy

It's also possible to run cntr from a container itself. This repository contains a example Dockerfile for that:

$ docker build -f Dockerfile.example . -t cntr
$ docker save cntr > cntr.tar
$ ctr images import --base-name cntr ./cntr.tar

In this example we attach to containerd by process id. The process id of a task is given in ctr tasks list.

$ ctr run --privileged --with-ns pid:/proc/1/ns/pid --tty docker.io/library/cntr:latest cntr /usr/bin/cntr attach 31523 /bin/sh

To resolve containerd names one also would need to add the ctr binary (~12mb) to the Dockerfile.

Additional Config

ZFS

cntr requires POSIX ACLs be enabled under ZFS. By default, Linux ZFS doesn't have POSIX ACLs enabled. This results in the following error when trying to attach:

unable to move container mounts to new mountpoint: EOPNOTSUPP: Operation not supported on transport endpoint

To enable POSIX ACLs on the ZFS dataset:

$ zfs set acltype=posixacl zpool/media
$ zfs set xattr=sa zpool/media              #  optional, but encouraged for best performance

How it works

Cntr is container-agnostic: Instead of interfacing with container engines, it implements the underlying operating system API. It treats every container as a group of processes, that it can inherit properties from.

Cntr inherits the following container properties:

  • Namespaces (mount, uts, pid, net, cgroup, ipc)
  • Cgroups
  • Apparamor/selinux
  • Capabilities
  • User/group ids
  • Environment variables
  • The following files: /etc/passwd, /etc/hostname, /etc/hosts, /etc/resolv.conf

Under the hood it spawns a shell or user defined program that inherits the full context of the container and mount itself as a fuse filesystem.

We extensively evaluated the correctness and performance of cntr's filesystem using xfstests and a wide range of filesystem performance benchmarks (iozone, pgbench, dbench, fio, fs-mark, postmark, ...)

Related projects

  • nsenter
    • Only covers linux namespaces and the user is limited to tools installed in the containers
  • toolbox
    • Does attach from a container to the host, this is the opposite of what Cntr is doing

Bibtex

We published a paper with all technical details about Cntr in Usenix ATC 2018.

@inproceedings{cntr-atc18,
  author = {J{\"o}rg Thalheim and Pramod Bhatotia and Pedro Fonseca and Baris Kasikci},
  title = {Cntr: Lightweight {OS} Containers},
  booktitle = {2018 {USENIX} Annual Technical Conference ({USENIX} {ATC} 18)},
  year = {2018},
}

cntr's People

Contributors

a-kenji avatar dependabot[bot] avatar github-actions[bot] avatar lopsided98 avatar mergify[bot] avatar mic92 avatar mic92-renovate[bot] avatar pogobanane avatar sarcasticadmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cntr's Issues

/nix/store bind-mount to an NFS mount incompatible with cntr

Steps to reproduce

  1. Install Nix
  2. Mount an NFS to /media/nas: mount -t nfs nas.lan:/ /media/nas
  3. Bind mount /nix/store: mount -o bind /media/nas/nix-store /nix/store
  4. Follow instructions listed here to create a debug sandbox.
  5. Observe that executing /.cntr/cntr-exec gives the error "Operation not supported". And nothing in nix-store or my regular user is accessible(with the same error), even if I set --effective-user to root or my regular user.
  6. Unmount /nix/store, rm -rf /nix/store, and reinstall Nix
  7. Observe that the same nix-build stops during buildPhase with a container whose /.cntr/cntr-exec is executable, and that the expect /nix/store tools are available and execute fine.

I speculate that two issues are relevant:

  1. cntr sets CAP_SYS_CHROOT on a copy of itself, but this is likely not persisted across NFS.
  2. My NFSv4 is configured to squash all user ids to the same user, but in a multi-user Nix daemon installation there are 32 nixbld1 users. So it is possible that permissions given to those are being lost during the user id squash.

It seems reasonable to throw an explicit error if the permissions responsible cannot be set, rather than build an unusable container.

cntr exec fails with umask set to 077

To reproduce run umask 077 in your shell and then attach to any container running non-root user inside. After that try to run cntr exec. It fails, because /.cntr/pid file was created with permissions 600 and is not readable.

I've tested with zsh and bash.

Also with umask set to 000 the pid file is created with permissions 666 which means it's writable by anyone, which could potentially be a security issue?

To fix this the correct permissions should be set when this file is created:

cntr/src/dotcntr.rs

Lines 26 to 37 in 43f88bf

pub fn write_pid_file(&self, target_pid: Pid) -> Result<()> {
let path = self.dir.path().join("pid");
let mut file = try_with!(File::create(&path), "failed to create {}", path.display());
let raw_pid: pid_t = target_pid.into();
try_with!(
file.write_all(format!("{}", raw_pid).as_bytes()),
"failed to write {}",
path.display()
);
Ok(())
}

Error when trying to attach to breakpointHook: unable to move container mounts to new mountpoint: EOPNOTSUPP: Operation not supported on transport endpoint

Hi, I'm trying out cntr to debug a nix package, but I get the following error when trying to connect:

# cntr attach -t command cntr-/nix/store/cv9dl6yr37a3c0iqqjmz76ba5bsda01n-notmuch-0.35
unable to move container mounts to new mountpoint: EOPNOTSUPP: Operation not supported on transport endpoint

My system information:

I have tried the following things, without change of error message:

  • reboot
  • run cntr as root with sudo
  • run cntras root with su
  • run cntr as root with doas
  • run nix-build as root with sudo

It seems like some kernel options/capabilities/modules may be missing, but I don't know which one that would be.

How to get data out of a container?

I want to get a ZIP file of a directory found in a cntr container - a logs directory of a failing Nix Build. I tried:

sudo cntr attach -t command cntr-/nix/store/...-${name} -- zip -r - build/source/tests/_logs > tests_logs.zip

But it doesn't work - the ZIP file generated is a text file with the text:

zip error: Invalid command arguments (cannot write zip file to terminal)

why we need fuse?

  1. why we need fuse support? if I created a new mount namespace, add I mount the slim container filesystem in /var/lib/cntr and mount debugging tool (whatever located in host or container) in /usr/bin/, everything seems ok, why need fuse? why redirect request between them?
  2. furthermore, I did't know why UnionFS is not good? I think it can also expand the slim container at run-time, but the paper says "However, in practice, users still end up with multiple base images due to the use of different base image distributions across different containers", the question is that with using cntr, this question is solved? in production environment, different application (java php...) of course have different base images?
  3. int step#3, why at begins mount at TMP/ and chroot into /? Because it was in a new nested namespace, what happens if I mount at / at begins?
  4. How to with IPC namespace? in step#3, after you bind mount /proc, you set this process in application ipc namespace? in this paper, the term 'namespace' only refer to the mount namespace? This also confused me a lot.
  5. when I use cntr attach pid , I saw the cntr forks two child process, can you explain the purpose of them? I know one of them attach to application containers, create nested namespace, finally chroot /.

Thanks for your reply.

cntr hangs under NixOS test

Not familiar with cntr, so I don't have much to add other than what I said in the workaround Nixpkgs pr… the fix was to make output not be a tty, and when I straced the pre-fix cntr invocation in the NixOS test, it hung right after some tty-related ioctls and I believe it had just received SIGWINCH. Didn't catch the actual call it was stuck on unfortunately.

rkt: check if container was already terminated

$ ./target/debug/cntr attach 5e020cea
no suitable container found, got the following errors:
  - ProcessId: not a valid pid: `5e020cea`: invalid digit found in string
  - Rkt: could not find container process belonging to rkt container '5e020cea': no child process found for pid 20849
  - Docker: Failed to list containers. 'docker inspect --format '{.State.Running};{.State.Pid}' 5e020cea' exited with exit code: 1: Error: No such object: 5e020cea
  - Nspawn: Failed to list containers. 'machinectl show --property=Leader 5e020cea' exited with exit code: 1: Could not get path to machine: No machine '5e020cea' known
  - Lxc: Failed to list containers. 'lxc-info --no-humanize --pid --name 5e020cea' exited with exit code: 1: 5e020cea doesn't exist

currently the error message is not too helpful.

Failing to attach to nix build

I'm using cntr from nixpkgs 19.09 (on NixOS), doesn't matter of which package build I'm trying to debug, it just fails ans locks completely the terminal

sudo RUST_BACKTRACE=full cntr attach -t command cntr-/nix/store/ih6pz06jrn806lx1315gc1djklxh6zfc-terraform-provider-keycloak-1.13.2
[sudo] password for eon: 
WARNING: the per-user profile dir /nix/var/nix/profiles/per-user/root should belong to user id 1000
thread '<unnamed>' panicked at 'BUG! got unknown d_entry type received from d_type', src/fs.rs:602:14
stack backtrace:
0:     0x55c51067844c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd5cf01a6458823ce
1:     0x55c51065f72d - core::fmt::write::h239984b34be80164
2:     0x55c510677151 - std::io::Write::write_fmt::h71b3597bde52e201
3:     0x55c51067a490 - std::panicking::default_hook::{{closure}}::h22b55119be64c15e
4:     0x55c510679f65 - std::panicking::rust_panic_with_hook::hc671c362d83d7750
5:     0x55c510658684 - std::panicking::begin_panic::hbfd0096d822b4d01
6:     0x55c51060d92a - cntr::fs::CntrFs::generic_readdir::h62575c5ba9c58ab2
7:     0x55c51061733f - fuse::request::Request::dispatch::h596ab4aba69542f6
8:     0x55c510651452 - std::sys_common::backtrace::__rust_begin_short_backtrace::h800c518d8b197517
9:     0x55c51063e146 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2f3283e15ccecb31
10:     0x55c510676c5f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h36570ddedd92a948
11:     0x55c510677dac - std::sys::unix::thread::Thread::new::thread_start::hac7b969fab3af94c
12:     0x7f46fce81ef7 - start_thread
13:     0x7f46fcba122f - __GI___clone
14:                0x0 - <unknown>

Attach and Exec don't support the Posix -- command line argument convention

The -- convention cannot be used to differentiate arguments for cntr vs arguments for the command
For example,
cntr attach -t command cntr-/nix/store/xyzzy bash --rcfile foo.sh
fails. The issue is that cntr considers --rcfile to be a unknown option rather than an argument for bash.
If the -- convention were supported, then this probably would have worked:
cntr attach -t command cntr-/nix/store/xyzzy -- bash --rcfile foo.sh

See a description of -- here: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

Docker image fails to build - clap version can't be found

Step 8/14 : RUN cargo build --release --target=x86_64-unknown-linux-musl
 ---> Running in c3fa8844dd31
    Updating crates.io index
error: failed to select a version for the requirement `clap = "=4.0.15"`
candidate versions found which didn't match: 3.2.23, 3.2.22, 3.2.21, ...
location searched: crates.io index
required by package `cntr v1.5.1 (/)`
The command '/bin/sh -c cargo build --release --target=x86_64-unknown-linux-musl' returned a non-zero code: 101


Tried with Cargo.lock from the pending PR as well and still the same issue.

Step 8/14 : RUN cargo build --release --target=x86_64-unknown-linux-musl
 ---> Running in fe6714ef2e60
    Updating crates.io index
error: failed to select a version for the requirement `clap = "=4.0.18"`
candidate versions found which didn't match: 3.2.23, 3.2.22, 3.2.21, ...
location searched: crates.io index
required by package `cntr v1.5.1 (/)`
The command '/bin/sh -c cargo build --release --target=x86_64-unknown-linux-musl' returned a non-zero code: 101

Permissions error on socket-proxy

When I try to use the socket-proxy branch of cntr I get the following error most of the time that I try to attach with any command:

sudo cntr attach -t command cntr-/nix/store/5shlk963b0ca6s7pd27rb7gpxp577c8v-java-debugme -- somecommand
failed to setup socket proxy: failed to bind socket '/tmp/cntrfs-sockets.wAcUADoChfPH/0': EACCES: Permission denied

Sometimes it works.

cntr only runnable as root?

If I have user namespaces enabled on a Linux box, the nix daemon can run as a "nobody" user with sandboxing enabled and this "just works" without issue.

However, if I then try to use cntr with an interactive breakpoint, I see this:

To attach install cntr and run the following command as root:

   cntr attach -t command cntr-/nix/store/q1l80p0z1v7gc2q7zri8xlkx5s2ap86k-debug

and indeed, it fails if not run as root, as advertised.

$ cntr attach -t command cntr-/nix/store/q1l80p0z1v7gc2q7zri8xlkx5s2ap86k-debug
    failed to get status of target process: Could not find namespace pid in /proc/221016/status

Is this a fundamental limitation or is there a way that I can find the nobody daemon's namespace pid (either as another user, or as the nobody daemon itself)?

Document Nix usage

I know that there is a version that works with Nix. If it merged into master yet?

Help for making cntr work in nixos

I added cntr and I'm trying to run use it with a breakpointHook in nixos, but I get

sudo cntr attach -t command cntr-/nix/store/02p9zkkq9mvxvdrnmviwdl0ifiq0ms7h-sudachi-vedd7896                      !
cannot create container mountpoint /var/lib/cntr: No such file or directory (os error 2) 

no idea why because the /var/lib/cntr directory exists.

cntr hangs when attaching

I tried out this tool coming from the nixpkgs documentation, I installed to my system configurations however it seems that when I try to attatch, via eg:
sudo cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0, the command just hangs and nothing happens. Doing a Ctrl+C takes me back to the prompt, however cntr keeps running in the background:

$ ps -aux | grep "cntr"
root       12215  0.0  0.0   3472  1536 ?        D    16:19   0:00 cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0
root       13466  0.0  0.0   3472  1408 ?        D    16:22   0:00 cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0
root       13530  0.0  0.0   3472  1536 ?        D    16:22   0:00 cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0 bash
root       13749  0.0  0.0   3472  1664 ?        D    16:22   0:00 cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0 bash
root       13929  0.0  0.0   3492  1408 pts/1    D    16:23   0:00 cntr attach -t command cntr-/nix/store/hsi0wjy93c1cv98kr7qgpyaaw3fa2fd3-asm-lsp-0.5.0
root       14519  0.0  0.0 222736  2688 pts/1    S+   16:27   0:00 grep cntr

(I might have tried a few times to attach).

I am also unable to sudo kill -9 13466, as in it doesn't get killed...

I am not sure if the root of the problem is some misconfiguration on my system, nixos, or cntr.

Problems installing cntr on ark linux (manjaro KDE Plasma 18.1.5)

  • I use an ark linux manjaro kde plasma 18.1.5
  • I installed cargo 1.41.0
  • i tried to install cntr but got rust specific error messages
  • anyone knows what goes wrong ?

[rene@thinky api-platform]$ cargo install cntr
Updating crates.io index
Installing cntr v1.1.2
Compiling libc v0.2.66
Compiling maybe-uninit v2.0.0
Compiling cfg-if v0.1.10
Compiling log v0.4.8
Compiling bitflags v1.2.1
Compiling pkg-config v0.3.17
Compiling stable_deref_trait v1.1.1
Compiling spin v0.4.10
Compiling void v1.0.2
Compiling thread-scoped v1.0.2
Compiling remove_dir_all v0.5.2
Compiling argparse v0.2.2
Compiling owning_ref v0.3.3
Compiling concurrent-hashmap v0.2.2
Compiling log v0.3.9
Compiling smallvec v0.6.13
Compiling cntr-fuse v0.3.6
Compiling rand v0.4.6
Compiling time v0.1.42
Compiling num_cpus v1.12.0
Compiling cntr-nix v0.10.0-pre1
Compiling parking_lot_core v0.2.14
Compiling tempdir v0.3.7
error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/macros.rs:197:26
|
197 | $entry = libc::$entry,
| ^^^^ expected i32, found u32
|
::: /home/rene/.cargo/registry/src/github.com-1ecc6299db9ec823/cntr-nix-0.10.0-pre1/src/sys/resource.rs:6:1
|
6 | / libc_enum!{
7 | | #[repr(i32)]
8 | | pub enum Resource {
9 | | RLIMIT_AS,
... |
35 | | }
36 | | }
| |_- in this macro invocation
|
help: you can convert an u32 to i32 and panic if the converted value wouldn't fit
|
197 | $entry = libc.try_into().unwrap()::$entry,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 7 previous errors

For more information about this error, try rustc --explain E0308.
Compiling parking_lot v0.5.5
error: could not compile cntr-nix.
warning: build failed, waiting for other jobs to finish...
error: failed to compile cntr v1.1.2, intermediate artifacts can be found at /tmp/cargo-install5r9ZE3

Caused by:
build failed

Attach fails: failed to setup /.cntr

I tested cntr the other day and it failed to attach to a container. I tried running the command as a non-root user in the docker group. It was installed via cargo install cntr.

Do you have any idea what is wrong here and how to fix it?

$ cntr attach 0531f16fe281
failed to setup /.cntr, failed to create setcap executable, Failed set file capability CAP_SYS_CHROOT on /tmp/cntr.p60d0d/cntr-exec, setxattr failed, EPERM: Operation not permitted

$ TMPDIR=/home/[redacted]/.cache cntr attach 0531f16fe281
failed to setup /.cntr, failed to create setcap executable, Failed set file capability CAP_SYS_CHROOT on /home/[redacted]/.cache/cntr.pw6ZLa/cntr-exec, setxattr failed, EPERM: Operation not permitted

some questions about cntr paper

hi~
After reading your paper, I have some questions, can you explain it ? thanks a lot, sorry for my poor english.

  1. the paper said there's a way to configure where the CntrFS Server stay in host or fat container? but I didn't find the server in host and didn't see a new fat container? but I guess the default is that it run in the host. can you explain it? and how to configure it ?
  2. the cntr needs fuse support, but I did't install the fuse kernel driver before, is the cntr dose the job?
  3. the binary command such as vim/htop/top after attached the application container, where those located? in CntrFS Server or download from network when launch the CntrFS server?

thanks for your reply.

How to attach to unprivileged podman containers?

Suppose you start an unprivileged podman container like this:

podman run -it debian /bin/sh

Now, running sudo cntr attach $(podman ps | tail -n1 | awk '{ print $1 }') fails with the following error:

no suitable container found, got the following errors:
  - ProcessId: not a valid pid: `eb77cae38179`: invalid digit found in string
  - Podman: Failed to list containers. 'podman inspect --format {{.State.Running}};{{.State.Pid}} eb77cae38179' exited with exit status: 125: Error: inspecting object: no such object: "eb77cae38179"
  - Docker: Failed to list containers. 'docker inspect --format {{.State.Running}};{{.State.Pid}} eb77cae38179' exited with exit status: 125: Error: inspecting object: no such object: "eb77cae38179"
  - Nspawn: Failed to list containers. 'machinectl show --property=Leader eb77cae38179' exited with exit status: 1: Could not get path to machine: No machine 'eb77cae38179' known

This is because running podman inspect as root doesn't give you information about a container started as another user. Obviously, running cntr without sudo won't work because the user has insufficient permissions.

Another thing I tried is to obtain the PID of the process in the container and run cntr attach against it:

$ sudo cntr attach 1396643
[sudo] password for ma27:
cannot create container mountpoint /var/lib/cntr: Permission denied (os error 13)

^C
$

Is it even possible nowadays to achieve that? If yes, how?

Currently using cntr 1.5.1 from NixOS 22.11.

cntr date is Incorrect.

The time zone for viewing date in cntr and docker exec is abnormal. How can I adjust it? Thanks!

Get a user specific shell from cntr?

As someone who manages their system using home-manager, there are no tools in the system wide config, the shell cntr gives me is barebones. Is it possible to get the shell with all the tools installed for my user when running cntr?

I suspect, I'd have to circumvent the sudo call somewhat? Maybe assign my user a certain group?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.