Skip to content

receiver, compactor, sidecar: use os.Root API#8797

Open
guidonguido wants to merge 3 commits intothanos-io:mainfrom
guidonguido:fix/os-root-api
Open

receiver, compactor, sidecar: use os.Root API#8797
guidonguido wants to merge 3 commits intothanos-io:mainfrom
guidonguido:fix/os-root-api

Conversation

@guidonguido
Copy link
Copy Markdown

@guidonguido guidonguido commented Apr 30, 2026

Fixes #8103

Issue
Current os filesystem access methods do not prevent accidental path traversal access, so directory operations based on user input may access unintended paths.

Changes
Force the use of os.Root to confine access to subdirectories only to the root working folder of the specific service.

Approach
Receiver, Sidecar: long-lived os.Root. The data directory persists for the entire service lifetime, so the Root is stored in the owning struct.
Compactor: transient os.Root. The compaction dir is fully removed after each compaction iteration, so the Root dir is opened on-demand.

Analysis
Receiver: real protection from user input, since the tenants directory paths are retrieved from the tenant IDs, derived either from HTTP Header, TLS cert or metric label.

Compactor: no path is composed from user input. The change only prevents accidental use on the codebase side.

Sidecar: as compactor.

Signed-off-by: Guido Ricioppo <griciopp@redhat.com>
Signed-off-by: Guido Ricioppo <griciopp@redhat.com>

Defer compactDir close to goroutine end

Signed-off-by: Guido Ricioppo <griciopp@redhat.com>
Signed-off-by: Guido Ricioppo <griciopp@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the new os.Root type

1 participant