Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(wrapper): detect rootless and SELinux under podman
Rodrigo Palharese56bdfae0a7e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 75fd2f49..69189362 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- The `bin/ai-memory` wrapper now detects rootless mode and SELinux under+ podman, so host-file commands stop failing with `Permission denied (os error+ 13)` on podman-based distros. Both the `-u 0:0` remap and `--security-opt+ label=disable` were decided from `docker info --format+ '{{.SecurityOptions}}'`, a Docker-only field that podman cannot evaluate;+ the swallowed error left both gates off exactly where they were needed.+ Podman's `.Host.Security.*` keys are consulted when that probe comes back+ empty. `bootstrap` is now covered as well: it only reads host files, but an+ unmapped UID blocks reads just as hard, and it degraded silently to "no+ `.git` found" before dying (#385).+## [1.25.0] - 2026-08-07### Addeddiff --git a/bin/ai-memory b/bin/ai-memoryindex dd36d621..8cb2d062 100755--- a/bin/ai-memory+++ b/bin/ai-memory@@ -440,6 +440,23 @@ case "${WRAPPER_SUBCOMMAND}" inWRITES_HOST_FILES=1;;esac+# bootstrap only *reads* host files — the repo bind-mounted at /work and the+# `.ai-memory.toml` markers under $HOME — but an unmapped UID and a confined+# SELinux label block reads exactly as hard as writes. The failure is+# two-stage and misleading: bootstrap first degrades silently to+# "no .git found at /work; bootstrapping from README/docs/rules only", then+# dies with "Permission denied (os error 13)" when it reaches a file it+# cannot skip. So readers need the same treatment as writers.+READS_HOST_FILES=0+case "${WRAPPER_SUBCOMMAND}" in+ bootstrap)+ READS_HOST_FILES=1+ ;;+esac+TOUCHES_HOST_FILES=0+if [ "${WRITES_HOST_FILES}" -eq 1 ] || [ "${READS_HOST_FILES}" -eq 1 ]; then+ TOUCHES_HOST_FILES=1+fi# Rootless Docker runs the whole daemon inside its own user namespace, where# container UID 0 maps back to the invoking host user, but any *non-zero*@@ -451,15 +468,35 @@ esac# staging dir, $PWD/CLAUDE.md, skill directories, …) fails with# EACCES/ENOENT. Running as UID 0 instead hits rootlesskit's primary# mapping and lands as the real host user. Only do this for commands that-# write to a host bind mount: other commands only touch the /data named+# touch a host bind mount: other commands only touch the /data named# volume, which isn't host-visible and doesn't have this problem, so leave# their UID mapping alone.DOCKER_SECURITY_OPTIONS=$("${DOCKER}" info --format '{{.SecurityOptions}}' 2>/dev/null || true)ROOTLESS_DOCKER=0+CONTAINER_SELINUX=0if printf '%s\n' "${DOCKER_SECURITY_OPTIONS}" | grep -q 'name=rootless'; thenROOTLESS_DOCKER=1fi-if [ "${WRITES_HOST_FILES}" -eq 1 ] && [ "${ROOTLESS_DOCKER}" -eq 1 ]; then+if printf '%s\n' "${DOCKER_SECURITY_OPTIONS}" | grep -q 'name=selinux'; then+ CONTAINER_SELINUX=1+fi+# `.SecurityOptions` is a Docker-only field. Podman — including through the+# podman-docker `docker` shim — fails the template with "can't evaluate field+# SecurityOptions in type system.infoReport" and exits 125, which the `|| true`+# above swallows into an empty string. Both gates then read as "not rootless,+# no SELinux" and rootless podman runs the helper as an unmapped subordinate+# UID under a confined label, so every host-file access dies with+# "Permission denied (os error 13)". Podman exposes the same two facts under+# different keys, so ask it directly when the Docker probe came back empty.+if [ -z "${DOCKER_SECURITY_OPTIONS}" ]; then+ if [ "$("${DOCKER}" info --format '{{.Host.Security.Rootless}}' 2>/dev/null || true)" = "true" ]; then+ ROOTLESS_DOCKER=1+ fi+ if [ "$("${DOCKER}" info --format '{{.Host.Security.SELinuxEnabled}}' 2>/dev/null || true)" = "true" ]; then+ CONTAINER_SELINUX=1+ fi+fi+if [ "${TOUCHES_HOST_FILES}" -eq 1 ] && [ "${ROOTLESS_DOCKER}" -eq 1 ]; thenUSER_ARGS=(-u 0:0)fi@@ -472,14 +509,14 @@ case "$(uname -s 2>/dev/null || true)" in# SELinux blocks the helper's container label from writing normal home# labels even when its uid/gid match the host user. Relabeling the entire# $HOME bind with :z/:Z is unsafe, so relax label confinement only for the- # short-lived, trusted helper commands that actually write host files.+ # short-lived, trusted helper commands that actually touch host files.SELINUX_MODE=$(getenforce 2>/dev/null || true)if [ -z "${SELINUX_MODE}" ] && [ -r /sys/fs/selinux/enforce ]; thenSELINUX_MODE=$(cat /sys/fs/selinux/enforce 2>/dev/null || true)fi- if [ "${WRITES_HOST_FILES}" -eq 1 ] \+ if [ "${TOUCHES_HOST_FILES}" -eq 1 ] \&& { [ "${SELINUX_MODE}" = "Enforcing" ] || [ "${SELINUX_MODE}" = "enforcing" ] || [ "${SELINUX_MODE}" = "1" ]; } \- && printf '%s\n' "${DOCKER_SECURITY_OPTIONS}" | grep -q 'name=selinux'; then+ && [ "${CONTAINER_SELINUX}" -eq 1 ]; thenSELINUX_ARGS=(--security-opt label=disable)fi;;