sftp icon indicating copy to clipboard operation
sftp copied to clipboard

Fails to start if public key directory is empty

Open anomiex opened this issue 2 years ago • 1 comments

Following the instructions at https://github.com/atmoz/sftp#logging-in-with-ssh-keys, if the specified keys don't exist then you get #350, plus your docker-compose configuration needs to list every key the user might want to specify.

If we instead use -v <host-dir>/ssh.keys:/home/foo/.ssh/keys:ro, a whole host directory is mounted where users can add whichever keys they want. But if the user doesn't add any keys, image startup still fails.

Since it's hard to have a docker-compose file that adds a volume conditionally on the host dir being non-empty, it'd be nice if the image could gracefully handle the situation, e.g. by setting shopt -s nullglob or by testing the result of the attempted glob before trying to cat it. Testing the potential filename with -f before catting it would probably also help with #350.

Reproduction steps

  1. mkdir -p /tmp/test/ssh.keys
  2. (optional) touch /tmp/test/ssh.keys/.gitkeep
  3. docker run --rm -it --env SFTP_USERS=foo:foo:1001 -v /tmp/test/ssh.keys:/home/foo/.ssh/keys:ro atmoz/sftp:latest

Expected results

Container runs. No keys are configured.

Actual results

[/usr/local/bin/create-sftp-user] Parsing user data: "foo:foo:1001"
cat: '/home/foo/.ssh/keys/*': No such file or directory
/usr/local/bin/create-sftp-user: Error on line 90: cat "$publickey" >> "$userKeysAllowedFileTmp"
/entrypoint: Error on line 60: create-sftp-user "$user"

anomiex avatar Jun 22 '23 12:06 anomiex

For others who may run into this, we added a simple README file that describes the folder's purpose, which worked to prevent the error. https://github.com/Automattic/jetpack/pull/32588

kraftbj avatar Aug 18 '23 19:08 kraftbj