Skip to content

bug(allowedpaths): cannot read /var/log/containers logs in Kubernetes/container environments due to symlinks #166

@AlexandreYang

Description

@AlexandreYang

Summary

In containerized Kubernetes deployments, reading log files from /var/log/containers/ fails with a path escapes from parent error, even when the directory is included in AllowedPaths.

Root Cause

On Kubernetes nodes, /var/log/containers/*.log files are symlinks pointing into /var/log/pods/...:

/var/log/containers/some-pod_namespace_container-<hash>.log -> /var/log/pods/.../0.log

rshell's AllowedPaths sandbox is backed by Go's os.Root / openat syscall, which rejects symlinks whose targets escape the configured root. Since the symlink target (/var/log/pods/...) escapes the root set to e.g. /host/var/log, the read fails.

Error

cat: /host/var/log/containers/<pod-name>.log: openat <pod-name>.log: path escapes from parent

Observed Behavior

  • Reading files from /var/log/pods/ works fine (no symlinks involved).
  • Reading files from /var/log/containers/ fails — these are symlinks into /var/log/pods/.
  • Adding a second allowed root (e.g. /var/log) does not resolve the issue: os.Root cannot follow a symlink from one root into another.

Expected Behavior

Log files in /var/log/containers/ should be readable when the directory is within AllowedPaths, since the symlink targets ultimately resolve to files on the same node filesystem.

Additional Notes

  • ls does not display symlink targets (-> destination), making this hard to diagnose from inside the shell. Improving ls -l to show symlink info would help operators debug this class of issue.
  • The underlying general problem of symlinks crossing allowed-path roots is tracked separately.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions