Classic confinement request for "cloud-validation"

  • name: cloud-validation
  • description: A suite of tools to be run on a deployed cloud to collect evidences for support handover.
  • snapcraft: https://github.com/canonical/Cloud-Validation-Automation/blob/main/cloud-validation/snap/snapcraft.yaml (private to developers, may not be accessible).
  • upstream: PRIVATE (same repo as above)
  • upstream-relation: the tool is developed by the same team publishing it
  • supported-category: debug tools (although some of the unsupported categories also apply, like running other snaps directly without connections, accessing arbitraty files, etc.)
  • reasoning: This is an internal Canonical tool, to be used by field-engineering to collect support handover evidences in an openstack deployment at a customer site. The tool is public and may be executed by the customer himself eventually, hence the need to be easily distributable/installable. Unfortunately the tool runs a lot of external commands (juju, snap cli, openstack cli, apt, etc.) making it impossible to strictly confine it.

YES - I understand that strict confinement is generally preferred over classic.

YES - I’ve tried the existing interfaces to make the snap to work under strict confinement but there are too much exceptions.

This request has been added to the queue for review by the @reviewers team.

Hello @token47 :slight_smile:

While I understand the difficulties you are describing, it isn’t clear that the requirements for classic confinement are met here. Some of the external commands could still be used under strict confinement, for example, by bundling the clients (shipping python-openstackclient and the other CLIs inside the snap via stage-packages or Python parts, rather than relying on host binaries).

Could you be a bit more specific about the denials you encountered?

Hi Chrisa

Sure, those are valid points. I’m helping the team to package this application so I don’t know every detail about it yet, so I asked for help to my friendly AI which did a better job than me. I understand some of these items are indeed fixable but some are not. Please let me know what you think.


Here is a breakdown of everything in the project (cloud-validation) that conflicts with strict snap confinement, organized by severity from fundamental architectural blockers to solvable interface/bundling issues.


1. Hard Architectural Blockers (Impossible in Strict Confinement)

Under strict confinement, the snap runs inside a mount namespace rooted at the core24 base snap with strict AppArmor and Seccomp profiles. It cannot execute arbitrary host binaries or mutate the host OS.

A. Execution of Host CLIs (juju, openstack, sunbeam, snap)

The tool’s core architecture (and openspec/specs/cloud-validation/snap-packaging/spec.md) explicitly relies on invoking pre-installed, authenticated CLIs on the host:

  • juju (integrations/juju.py, checks/collectors/juju.py, ceph.py, network.py, system.py, openstack.py, handover/policy.py, checks/tests/openstack_*.py): Invokes juju status, juju exec/run, juju ssh, juju scp, juju export-bundle, juju config, juju show-controller, juju list-models, juju machines, juju show-model.
  • openstack (integrations/openstack.py, checks/collectors/openstack.py, checks/tests/openstack_*.py, handover/policy.py): Invokes the openstack CLI.
  • sunbeam (checks/collectors/sunbeam.py:69): Invokes sunbeam deployment export.
  • snap (checks/collectors/packages.py:68,125, snap.py:39, system_hotsos.py:91): Invokes snap list and snap info to inspect installed snaps and refresh holds on the host.

Why it fails in strict mode: /usr/bin and /snap/bin from the host are not accessible or executable inside the strict sandbox. Even if openstack or juju were bundled into the snap, sunbeam cannot be easily bundled, and snap CLI calls require talking to /run/snapd.socket (snapd-control interface, which is restricted/brand-store only).

B. Host Package & Repository Mutation via sudo (system.hotsos)

  • checks/collectors/system_hotsos.py (lines 68, 116, 215–263, 319–366):
    • Runs sudo -n true, sudo -n add-apt-repository, sudo -n apt-get update, sudo -n apt-get install -y hotsos, sudo -n apt-get purge -y hotsos, and sudo -n /usr/bin/hotsos --save.
    • Runs dpkg-query and grep against /etc/apt/sources.list and /etc/apt/sources.list.d to check host package state.
  • checks/collectors/packages.py (lines 78, 130):
    • When target="localhost" (used by juju.version-info), runs dpkg-query -W and dpkg -l to inspect the host’s dpkg database.

Why it fails in strict mode: A strictly confined snap cannot escalate privileges via sudo to modify the host’s apt repositories or install .deb packages on the host, and /var/lib/dpkg / /etc/apt inside the sandbox belong to the core24 base snap, not the host (unless accessed via system-files at /var/lib/snapd/hostfs/...).

C. Downloading .deb Packages via apt-cache / apt-get (openstack.ceph-fio)

  • checks/tests/openstack_ceph_fio.py (lines 285–325):
    • Runs apt-cache depends ... fio gawk rbd-nbd, apt-get download ..., and dpkg-deb -x on the local runner to build an offline runtime tarball for the test VM.

Why it fails in strict mode: Inside core24, /etc/apt/sources.list and /var/lib/apt/lists are empty/unpopulated, and apt is not configured or permitted to use the host’s apt cache.


2. Host Filesystem & Dotfile Access Issues

Strict snaps rewrite $HOME to ~/snap/cloud-validation/<revision> and block access to hidden directories (~/.local, ~/.ssh, ~/.config) in the real home directory, even with the home plug connected.

  1. Juju Credentials & State (~/.local/share/juju):
    • checks/collectors/sunbeam.py:63,131 and profiles/openstack-sunbeam.yaml:44: Reads ~/.local/share/juju directly to archive Juju credentials.
    • Any juju invocation also needs read/write access to ~/.local/share/juju.
  2. SSH Client Configuration & Keys (~/.ssh):
    • integrations/ssh.py:15 (maas.version-info) and handover/policy.py:227: Runs ssh <target> relying on the user’s default ~/.ssh/config, ~/.ssh/id_*, ~/.ssh/known_hosts, and $SSH_AUTH_SOCK.
    • checks/tests/openstack_vm_network.py:311,571 and profiles/*.yaml: Default profile uses private_key: ~/.ssh/id_ed25519.
  3. OpenStack Client Configs & OpenRC Files:
    • integrations/openstack.py:45: Sources an openrc file via bash (which itself might source other files or reference paths outside the sandbox) or uses --os-cloud, which looks for ~/.config/openstack/clouds.yaml or /etc/openstack/clouds.yaml.
  4. Arbitrary Input/Output Paths (/tmp, /var, etc.):
    • Users passing --profile, --output-dir, --kit, or --file located in /tmp (a private mount namespace inside strict snaps!), /opt, /srv, or hidden folders will get FileNotFoundError or PermissionError.

(Note: Accessing ~/.local/share/juju, ~/.ssh, and ~/.config/openstack in a strict snap requires the personal-files interface and ssh-keys interface, which still require a manual store review/exception from Canonical!)


3. Missing Bundled Binaries & Runtime Dependencies in snapcraft.yaml

Currently, snap/snapcraft.yaml only stages python3.12-minimal. Under classic confinement, it falls back to the host’s /usr/bin for everything else. In strict confinement, the following invoked tools are either missing from core24 or not staged in the snap:

  • git: Used in checks/analyzers/ua_reviewkit.py:118, checks/tests/openstack_extra_checks.py:205, and checks/tests/openstack_ceph_fio.py:251 to clone https://github.com/canonical/ua-reviewkit.
  • jq, nc (netcat), uuidgen: Required by checks/tests/openstack_extra_checks.py:160 (and the ua-reviewkit Octavia script it runs).
  • ssh: Used by maas.version-info, openstack.vm-network, and customer preflight.
  • ping, ip: Used by checks/tests/openstack_vm_network.py:309,509,598 (ip -4 route get, ping -c 1). Also requires the network-observe plug for ip route and raw socket permissions (or network plug with unprivileged ping) for ping.
  • External Python Script Dependencies (ua-reviewkit):
    • checks/analyzers/ua_reviewkit.py:181 runs sys.executable ua-bundle-check.py. That upstream script imports third-party Python packages (such as PyYAML, packaging, or others depending on revision); if it imports anything beyond PyYAML and jsonschema, the snap’s isolated Python environment won’t have it.

4. Hardcoded Classic Assumptions in Code & Tests

  • cloud-validation/snap/snapcraft.yaml:14: confinement: classic (and no plugs defined for network, home, ssh-keys, network-observe, etc.).
  • cloud-validation/src/cloud_validation/handover/kit.py:59,63,170: Customer runbook and delivery README hardcode sudo snap install --classic --dangerous ....
  • cloud-validation/tests/test_snap_packaging.py:23: Explicitly asserts assert config["confinement"] == "classic".

Summary: Can this be strictly confined without losing Canonical store auto-approval?

Not in its current form. Even if you bundled juju, openstack, git, jq, nc, openssh-client, iproute2, and iputils-ping inside the snap:

  1. Store Exception Catch-22: For bundled juju, openstack, and ssh to read the operator’s existing credentials (~/.local/share/juju, ~/.config/openstack, ~/.ssh), the snap would need personal-files and ssh-keys interfaces—which also trigger a manual Canonical Store review/exception, defeating goal #1.
  2. Feature Loss: system.hotsos (local apt/dpkg manipulation via sudo), sunbeam.access-backup (sunbeam CLI), system.snap-refresh-hold / packages.py (snap and dpkg host queries), and openstack.ceph-fio (apt-get download on host) cannot work inside strict confinement unless redesigned (e.g., executing them over SSH to localhost or via Juju on remote units instead of direct local subprocesses).

(Note: Regarding goal #2*—avoiding conflicts with system libraries—even a classic snap runs its own isolated Python interpreter and site-packages from $SNAP as long as python3 is staged and invoked via command-chain without PYTHONPATH leaking from the host.)*