Skip to content

fix(k8s): fix SSH host key permissions for non-root user#2

Merged
irony merged 3 commits into
mainfrom
fix/ssh-permissions
May 18, 2026
Merged

fix(k8s): fix SSH host key permissions for non-root user#2
irony merged 3 commits into
mainfrom
fix/ssh-permissions

Conversation

@irony

@irony irony commented May 17, 2026

Copy link
Copy Markdown
Contributor

Problem

SSH-servern kraschade med permission denied när den försökte läsa mountad SSH host key som non-root user.

Ändringar

  • Add fsGroup: 1001 to pod security context
  • Change defaultMode from 0600 to 0640
  • Create /app/data/ssh-keys as writable directory

Test

  • Pod startar utan CrashLoopBackOff
  • SSH-servern kan läsa host key

- Add fsGroup: 1001 to pod security context
- Change defaultMode from 0600 to 0640 for ssh-host-key secret
- Create /app/data/ssh-keys as writable directory in Dockerfile
- Allow nodejs user (UID 1001) to read mounted SSH host key
Copilot AI review requested due to automatic review settings May 17, 2026 23:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes an SSH server crash on Kubernetes caused by the non-root nodejs (uid/gid 1001) user being unable to read the SSH host key mounted from a Secret with defaultMode: 0600. With a Secret volume, files are owned by root:fsGroup, so the fix sets fsGroup: 1001 on the pod and relaxes the file mode to 0640 so the group-mounted user can read it. The Dockerfile is also updated to provision a writable fallback directory for a self-generated host key.

Changes:

  • Add fsGroup: 1001 to the pod's securityContext so Kubernetes chgrps the mounted secret volume to the nodejs group.
  • Change the ssh-host-key secret volume defaultMode from 0600 to 0640 so the group can read it.
  • Create /app/data/ssh-keys in the image (in addition to /app/ssh-keys) and chown both to nodejs:nodejs for the generated-key fallback path used in src/ssh-server.ts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
k8s/app/base/deployment.yaml Adds fsGroup: 1001 and changes secret volume defaultMode to 0640 so the non-root container can read the mounted SSH host key.
Dockerfile Creates an additional writable /app/data/ssh-keys directory and recursively chowns it (and /app/ssh-keys) to the nodejs user for the generated-key fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Dockerfile Outdated
Comment on lines +28 to +30
# Create writable directories
RUN mkdir -p /app/ssh-keys /app/data/ssh-keys && \
chown -R nodejs:nodejs /app/ssh-keys /app/data
irony added 2 commits May 18, 2026 12:22
- Remove fallback key generation logic
- Fail fast with clear error if memory-ssh-host-key secret is missing
- Mount point: /app/ssh-keys/ssh_host_ed25519_key
- Remove unused data directory creation in Dockerfile
@irony irony merged commit 561dddc into main May 18, 2026
1 check passed
@irony irony deleted the fix/ssh-permissions branch May 18, 2026 10:35
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