Skip to content

fix: reject symlinks in ConfigMap file entries - #7966

Open
GrosQuildu wants to merge 2 commits into
fabric8io:mainfrom
GrosQuildu:ptp-41-configmap-symlink
Open

fix: reject symlinks in ConfigMap file entries#7966
GrosQuildu wants to merge 2 commits into
fabric8io:mainfrom
GrosQuildu:ptp-41-configmap-symlink

Conversation

@GrosQuildu

@GrosQuildu GrosQuildu commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Description

The createConfigMapFromDirOrFiles uses NOFOLLOW_LINKS only to decide whether a path is a directory, then reads non-directory entries with Files.readAllBytes(file). A symlink to a regular file is accepted and the target bytes are embedded into the returned ConfigMap.

The kubernetes-client does follow symlinks in general. The explicit use of NOFOLLOW_LINKS in this single case raises a question of the expected kubernetes-client behavior in regards to symbolic links.

Exploit Scenario

A low privileged user creates a symlink staging/app.properties -> /etc/shadow.

Path staging = new File("./staging").toPath();
ConfigMap configMap =
        KubernetesResourceUtil.createConfigMapFromDirOrFiles("poc-config", staging);
String leaked = configMap.getData().get("app.properties");

The symlink is resolved by kubernetes-client. Unexpected file is leaked.

Threat Model

Should kubernetes-client not follow symlinks? Or should this behavior be configurable?

Note that the scope of the question is huge:

  • PodUpload.upload and PodOperationsImpl.copy may resolve symlinks on remote pods
  • Java generator follows input CRD symlink dirs and writes symlinked .java files with explicit FOLLOW_LINKS
  • CRD generator output may resolve project-controlled symlinks in CI
  • cert/key/truststore, OpenShift fromFile, and many other functionalities

Fix

If the client is supposed to follow symbolic links, then removing NOFOLLOW_LINKS from createConfigMapFromDirOrFiles is recommended for consistency, and an entry to threat model is recommended.

If client should not follow symlinks, then harden createConfigMapFromDirOrFiles and plan to harden other functionalities around symbolic links handling.

Note that the proposed fix still have race condition (time-of-check-time-of-use) issues.


Paweł Płatek from Trail of Bits in collaboration with OpenAI.

@GrosQuildu

Copy link
Copy Markdown
Contributor Author

Note that the proposed patch may be wrong, and correct idea is to just remove NOFOLLOW_LINKS. If so then please just close this PR and followup with a new one.

@GrosQuildu
GrosQuildu marked this pull request as ready for review June 26, 2026 15:42
GrosQuildu added a commit to GrosQuildu/kubernetes-client that referenced this pull request Jun 26, 2026
@GrosQuildu
GrosQuildu force-pushed the ptp-41-configmap-symlink branch from eaf70a8 to d45fc7b Compare June 26, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant