Repository navigation
Description
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I have read the troubleshooting guide and I think this is a new bug.
Contact Details
Version
trunk (main)
What version of Kubernetes are you using?
1.36
What is your Kubernetes environment?
Self-managed: kind (evaluation)
How did you install the operator?
YAML manifest
What happened?
Summary
The webhook validation for per-extension paths (extension_control_path, dynamic_library_path, ld_library_path, bin_path) rejects relative traversal (..) but not absolute paths. A crafted absolute path with embedded .. bypasses the check and, at runtime, resolves to a location outside the extension image volume, contradicting the check's stated intent ("path must not escape the extension directory").
Found by source-code inspection on main; environment-independent.
Root cause
internal/webhook/v1/cluster_webhook.go:2976
if strings.HasPrefix(filepath.Clean(path), "..") {
result = append(result, field.Invalid(
fieldPath.Index(j),
path,
"path must not escape the extension directory",
))
continue
}This only catches relative traversal. filepath.Clean on an absolute path stays absolute (starts with /), so it never starts with ... At runtime, absolutizePaths (pkg/postgres/configuration.go:915) joins each path with the extension mount:
for _, path := range paths {
if !yield(filepath.Join(ext.MountPath, path)) {filepath.Join strips the leading slash of an absolute path but still resolves embedded .., so a path like /a/../../../../etc joined with /extensions/myext resolves to /etc.
What you expected to happen
The check should reject any path that escapes the extension directory, including absolute paths, matching its stated intent.
How to reproduce
Running the exact webhook check and the exact runtime join:
path = "/a/../../../../etc"
webhook rejects? -> false (Clean is "/etc", not prefixed with "..")
filepath.Join("/extensions/myext", path) -> "/etc" (escapes the mount)
So a Cluster like the following is accepted by the webhook even though the resulting GUC points outside the extension image volume:
spec:
postgresql:
extensions:
- name: myext
dynamic_library_path:
- "/a/../../../../lib"Impact
extension_control_path / dynamic_library_path control where PostgreSQL loads extension control files and shared libraries. Bypassing this check lets a crafted spec point them outside the read-only extension image volume the feature is meant to confine them to, defeating the isolation the check promises.
This is admin-scoped (whoever sets the Cluster spec is normally trusted), so it is validation hardening / defense-in-depth rather than a critical vulnerability. It still silently breaks a deliberate safety boundary that policy-restricted or GitOps setups may rely on, and the image-volume extensions feature is recent, so this path is lightly audited.
Suggested fix
Reject absolute paths in addition to .. traversal, since paths here are always relative to the extension mount (they are joined with MountPath):
if filepath.IsAbs(path) || strings.HasPrefix(filepath.Clean(path), "..") {A relative non-.. path cannot climb out of filepath.Join, so rejecting both absolute and .. fully prevents the escape. Add a test with /a/../../../../etc alongside the existing ../../etc case.
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: extension-path-repro
spec:
instances: 1
storage:
size: 1Gi
postgresql:
extensions:
- name: myext
image:
reference: example/myext:1.0
dynamic_library_path:
- "/a/../../../../lib"Relevant log output
N/A — found by source-code inspection. Webhook accepts the spec; at runtime the GUC resolves outside the extension mount via filepath.Join.Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Anand-240 commentedon Jul 15, 2026
Can I take this one? I traced the check in cluster_webhook.go and confirmed it only catches relative traversal, not absolute paths with embedded ".." — verified with filepath.Clean and the actual runtime Join in configuration.go, an absolute path like /a/../../../../etc slips past the webhook and still escapes the mount. I'd add the missing filepath.IsAbs check alongside the existing one, plus a test case for this alongside the existing "../../etc" test.
Anand-240 commentedon Jul 15, 2026
Opened a PR for this: #11210
fix(webhook): reject extension paths that escape via absolute travers…
fix(webhook): reject extension paths that escape via absolute travers…
fix(webhook): reject extension paths that escape via absolute travers…
fix(webhook): reject extension paths that escape via absolute travers…