Skip to content

feat(kubectl): hardening Dockerfile#84

Open
mydoomfr wants to merge 1 commit intomainfrom
harden-kubectl-images
Open

feat(kubectl): hardening Dockerfile#84
mydoomfr wants to merge 1 commit intomainfrom
harden-kubectl-images

Conversation

@mydoomfr
Copy link
Owner

No description provided.

@mydoomfr mydoomfr requested a review from Copilot October 19, 2025 14:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Hardening kubectl image by minimizing installed packages, tightening file permissions, removing build-time tools, and enforcing non-root execution.

  • Removes git and later uninstalls curl to shrink and harden the runtime image.
  • Changes executable permissions for kubectl and yq from +x (default 0755) to numeric 0555 (read/execute only) and strips all setuid/setgid bits.
  • Adds cleanup steps, non-root user configuration, tmp permissions, and environment/history hardening.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
apps/kubectl-1.34/Dockerfile Applies hardening: permission changes, removal of curl, SUID stripping, user and WORKDIR adjustments.
apps/kubectl-1.33/Dockerfile Mirrors hardening changes for previous kubectl version image to keep versions aligned.
Comments suppressed due to low confidence (4)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

curl -fsSL "https://dl.k8s.io/release/v${KUBECTL_VERSION}/bin/linux/${ARCH}/kubectl.sha256" -o /tmp/kubectl.sha256 && \
echo "$(cat /tmp/kubectl.sha256) /usr/local/bin/kubectl" | sha256sum -c - && \
chmod +x /usr/local/bin/kubectl && \
chmod 0555 /usr/local/bin/kubectl && \
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using mode 0555 removes write permission for root (image owner), which can hinder debugging or layering (e.g., replacing/updating the binaries in derived images). Consider reverting to 0755 or explicitly documenting this breaking change in image release notes.

Copilot uses AI. Check for mistakes.
curl -fsSL "https://github.com/mikefarah/yq/releases/latest/download/checksums" -o /tmp/yq.checksums && \
grep "^yq_linux_${ARCH} " /tmp/yq.checksums | awk '{print $19 " /usr/local/bin/yq"}' | sha256sum -c - && \
chmod +x /usr/local/bin/yq && \
chmod 0555 /usr/local/bin/yq && \
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using mode 0555 removes write permission for root (image owner), which can hinder debugging or layering (e.g., replacing/updating the binaries in derived images). Consider reverting to 0755 or explicitly documenting this breaking change in image release notes.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +34
RUN apt-get remove -y curl && \
apt-get autoremove -y && \
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Removing curl from the final image is a functional change; consumers may rely on curl to fetch manifests or auxiliary resources. If retaining minimal footprint is the goal, note this as a breaking change or consider keeping curl (small footprint) and documenting rationale.

Suggested change
RUN apt-get remove -y curl && \
apt-get autoremove -y && \
RUN apt-get autoremove -y && \

Copilot uses AI. Check for mistakes.
apt-get clean && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/* /var/log/* /tmp/* /var/tmp/*

RUN find / -xdev -perm /6000 -type f -exec chmod a-s {} \; 2>/dev/null || true
Copy link

Copilot AI Oct 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Blanket stripping all setuid/setgid bits may unintentionally break legitimate utilities (e.g., ping) and makes future troubleshooting harder. Recommend targeting a known list of binaries or starting from a base image that already minimizes privileged binaries instead of a broad filesystem sweep.

Suggested change
RUN find / -xdev -perm /6000 -type f -exec chmod a-s {} \; 2>/dev/null || true
RUN chmod a-s /usr/local/bin/kubectl /usr/local/bin/yq

Copilot uses AI. Check for mistakes.
@mydoomfr mydoomfr force-pushed the main branch 5 times, most recently from e5306af to 696069c Compare October 19, 2025 18:04
Signed-off-by: Benjamin Pinchon <dev@mdfr.me>
@mydoomfr mydoomfr force-pushed the harden-kubectl-images branch from 598e8e7 to add7298 Compare October 19, 2025 18:16
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.

2 participants