Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to start if public key directory is empty #377

Open
anomiex opened this issue Jun 22, 2023 · 1 comment
Open

Fails to start if public key directory is empty #377

anomiex opened this issue Jun 22, 2023 · 1 comment

Comments

@anomiex
Copy link

anomiex commented Jun 22, 2023

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"
@kraftbj
Copy link

kraftbj commented Aug 18, 2023

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. Automattic/jetpack#32588

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

No branches or pull requests

2 participants