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

[Bug] Public key authentication not working in version 3 #22

Closed
josefschabasser opened this issue Jun 19, 2020 · 13 comments · Fixed by #25
Closed

[Bug] Public key authentication not working in version 3 #22

josefschabasser opened this issue Jun 19, 2020 · 13 comments · Fixed by #25
Assignees
Labels
bug Something isn't working

Comments

@josefschabasser
Copy link

josefschabasser commented Jun 19, 2020

Hi!

I set up emberstack/sftp as an Azure container Instance. I tried to configure public key authentication, but as soon as I set the password to "" or null I can't login anymore.
Here is my configuration:

{
  "Global": {
    "Chroot": {
      "Directory": "%h",
      "StartPath": "sftp"
    },
    "Directories": [
      "sftp"
    ],
    "HostKeys": {
      "Ed25519": "[MY HOST ED25519 PRIVATE KEY]",
      "Rsa": "[MY HOST RSA PRIVATE KEY]"
    }
  },
  "Users": [
    {
      "Username": "myuser",
      "Password": "",
      "PublicKeys": [
        "[MY USER PUBLIC KEY]"
      ]
    }
  ]
}

Log output when using sshfs:

2020-06-19 14:41:05.388 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - PAM: Authentication failure for myuser from 10.240.255.56
2020-06-19 14:41:05.455 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - Connection closed by authenticating user myuser 10.240.255.56 port 46479 [preauth]
2020-06-19 14:41:18.675 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - PAM: Authentication failure for myuser from 10.240.255.56
2020-06-19 14:41:20.855 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - PAM: Authentication failure for myuser from 10.240.255.56
2020-06-19 14:41:20.895 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - Postponed keyboard-interactive for myuser from 10.240.255.56 port 59492 ssh2 [preauth]
2020-06-19 14:41:23.242 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - PAM: Authentication failure for myuser from 10.240.255.56
2020-06-19 14:41:23.589 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - Failed none for myuser from 10.240.255.56 port 59492 ssh2
2020-06-19 14:41:24.117 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - Failed password for myuser from 10.240.255.56 port 59492 ssh2
2020-06-19 14:41:24.126 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - maximum authentication attempts exceeded for myuser from 10.240.255.56 port 59492 ssh2 [preauth]
2020-06-19 14:41:24.126 [VRB] (ES.SFTP.Host.SSH.SSHService) sshd - Disconnecting authenticating user myuser 10.240.255.56 port 59492: Too many authentication failures [preauth]

When I use Filezilla, more or less the same thing happens.

EDIT: shortened log

@antoinedeschenes
Copy link
Collaborator

antoinedeschenes commented Jun 23, 2020

v2.1.14 will work, permissions of users' home folder on v3 prevent sshd from reading the authorized_keys file using a custom AuthorizedKeysFile instruction should fix those problems

@antoinedeschenes
Copy link
Collaborator

@winromulus two possible solutions here, either move authorized_keys out of users' home, or create the home directory with 755 permissions.

@josefschabasser
Copy link
Author

josefschabasser commented Jun 24, 2020

me not understanding SFTP chroot permissions

Why is the users home directory owned by root:root?
Simplest fix: chown -R $USER:$GROUP $HOME during creation of folder structure.
chown $USER $HOME (without -R and $GROUP) already solves this issue.

In fact, nearly everything is owned by root:root!

$ kubectl exec sftp-pod -- bash
  # ls -lisah /home
  total 12K
  823876 4.0K drwxr-xr-x 1 root root 4.0K Jun 24 08:12 .
  920766 4.0K drwxr-xr-x 1 root root 4.0K Jun 24 08:12 ..
  920983 4.0K drwx------ 3 root root 4.0K Jun 24 08:12 myuser

  # ls -lisah /home/myuser
  total 12K
  920983 4.0K drwx------ 3 root root 4.0K Jun 24 08:12 .
  823876 4.0K drwxr-xr-x 1 root root 4.0K Jun 24 08:12 ..
  920984 4.0K drwxr-xr-x 3 root root 4.0K Jun 24 08:12 .ssh

  # ls -lisah /home/myuser/.ssh
  total 16K
  920984 4.0K drwxr-xr-x 3 root    root 4.0K Jun 24 08:12 .
  920983 4.0K drwx------ 3 root    root 4.0K Jun 24 08:12 ..
  910298 4.0K -r-------- 1 myuser  root  584 Jun 24 08:12 authorized_keys
  920985 4.0K drwxr-xr-x 2 root    root 4.0K Jun 24 08:12 keys

@winromulus
Copy link
Contributor

@antoinedeschenes @josefschabasser I'm currently investigating this

@antoinedeschenes - Not sure if creating the home directory with 755 will work because of chroot.
I need to have a look over the changes in v3 again to see if any of the user permissions changed

@winromulus winromulus added the bug Something isn't working label Jun 24, 2020
@winromulus winromulus self-assigned this Jun 24, 2020
@winromulus winromulus changed the title public key authentication not working [Bug] Public key authentication not working in version 3 Jun 24, 2020
@josefschabasser
Copy link
Author

josefschabasser commented Jun 24, 2020

Okay, root:root owning the users home is not the problem.
The problem are the permissions on the users home folder: 0700.
According to the ArchWiki it should be 0755.

Or maybe move the authorized_keys file to /etc/sshd like suggested here.

@antoinedeschenes
Copy link
Collaborator

Yes, the sshd auth process runs unprivileged and can't reach the authorized_keys file
It used to be a config option but it's been removed in the OpenSSH version used
https://manpages.debian.org/stretch/openssh-server/sshd_config.5.en.html#UsePrivilegeSeparation

@winromulus
Copy link
Contributor

@antoinedeschenes - I think this is a breaking change after setting the container to run as a non-root user.

@winromulus
Copy link
Contributor

After doing a lot of research I've concluded that the current version of sshd cannot run unprivileged without affecting multiple capabilities, authorized keys being one of them. I'm putting in a new PR to run the container as root again.

@tibarix
Copy link

tibarix commented Jun 25, 2020

Hello everyone, I am getting the same error even with version 2.1.10

docker-compose.yaml:

version: '2'
services:
  sftp:
    image: "emberstack/sftp:2.1.10"
    ports:
      - "22:22"
    volumes:
      - ./config.json:/app/config/sftp.json:ro

config.json:

{
    "Global": {
        "Chroot": {
            "Directory": "%h",
            "StartPath": "sftp"
        },
        "Directories": ["sftp"],
        "HostKeys": {
            "Ed25519": "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW\nQyNTUx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ITEjSDhnWP1\n9G7d/zw0vv7MIvENp9FFcy87FSIiwuCOM/2Mw52mDYZ+W8e2/aEmKGSOGqvsORdbebtZEr\nT0/By9jUhmMdMPAAABAQDUW+tX++FKQjuQhaCB5HoNFG/w0ZhS8cARIiCKAKlnJwpk7Gxw\n9yjJycw3C5XlfM3Q+VwWzY7VJnLVWjLRXxDbT4wpaOfODAsu4d50jyjgvSboEJ7/xS8C6f\nugAlhTxMDIo46Ul6a2MXHxyKoNZ1uF6koxsOzIuCD3UfZWNqyzUyQ26omVcQxyY19adJMD\nKsmpOljA3NwgX+/yi7fm1yhOCnNRJ08UuQ0cA9ZJjGG2WSHq1YtL7HNUKhKg+44sVCOlBO\nr8VG8APpzxDklqXv3PsHQYkVMSbzEAgVeYTsf+Hob0zI/ia0GGr2s3FNnUV3I73dwE0Riv\n2BuMjpGpmikhAAAAK21vaGFtbWVkLmFheWFjaGlATGVuZGljby1NQUMtTW9oYW1tZWQubG\n9jYWwBAgMEBQYH\n-----END OPENSSH PRIVATE KEY-----\n"

        }
    },
    "Users": [
        {
            "Username": "demo",
            "PublicKeys": [
                "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAEUDeHc2qpNEqy64RoJzDezbt6oEnPUOpCVjCpW9jxd test@test",
                "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDTlfo+CCBMJru9cqeq9GDUIwAr8wOkY6qcTElNR9bsBjFQRbUI0hGcntox3/va5DPhF641QB+f9btRCBBGSF6cfKDUd2EipUu1jxvP0+BB5zlBJ2EkN5dmPSy7zmSsdGU5PJ51xoUUB9KQOHDtYnS+IJTZRVbXLO5ArEeBtuKWLUmrt0knl3Z9Exu6TUz8JWWV8J6/4sDgVaBlsPPprxlNXseedsSnJUx7w5ZHUVzrF105qWgufHQr7k9z3LJE9T2F59aOcRH7Wn+3m+dvsGIZ6L6EO7hSXaElww2HIPtteVqN5zNMNIMUa2DtxNjfszh4SF15CK14ZJsRfHp4ihLPOs7dHaPPw91eTjorG/qnYwrIhfE03whWsTdA3Cq2/8ntr/ikiYMP590Bb8NS9n/vejZoFZak8LqJxXfiBhgKV1k+OzbpsUTw5nLy+yMlwj1AL24O6UdklMB4GNeKeHL4d6GZI/HEUBW+2Q/FXDhleXSwXWt1Lo7rSbSjvokcTpEKtXl9hyD7DRs4SzQj0MbUSlsJiJo+i4xG4ycJaISTfEu28GXph4vMhtyd/+IQADQJ6yg2y69iYaRQI5RN8pHaeUz/r0tXqDqpmSSKz+ZISs/nUhvZyvpqbYnd/YixUrUrH+ugUCUbc1GxpSAomwn3lMKWhtcGCkFfkwqABT+b7w== test@test"
            ]
        }
    ]
}

Am I missing anything here?

@antoinedeschenes
Copy link
Collaborator

@tibarix feature was added in 2.0.12

@antoinedeschenes
Copy link
Collaborator

antoinedeschenes commented Jun 26, 2020

@winromulus aren't we already running as root?

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         129  0.1  0.0   3992  3280 pts/0    Ss   11:14   0:00 bash
root         225  0.0  0.0   7644  2740 pts/0    R+   11:16   0:00  \_ ps auxwfw
root           1  0.1  0.0   2288   692 ?        Ss   11:14   0:00 tini -- dotnet ES.SFTP.Host.dll
root           6  0.8  0.3 22904220 97444 ?      SLl  11:14   0:01 dotnet ES.SFTP.Host.dll
root         127  0.0  0.0  15856  6552 ?        S    11:14   0:00  \_ /usr/sbin/sshd -D -e
root         220  0.3  0.0  17104  8048 ?        Ss   11:16   0:00      \_ sshd: demo [priv]
sshd         221  0.0  0.0  15856  4768 ?        S    11:16   0:00          \_ sshd: demo [net]
root         222  0.0  0.0  17104  3216 ?        S    11:16   0:00          \_ sshd: demo [pam]

The problem seems to be the auth process (PID 221 in this example) not having access to the users' home folder

@winromulus
Copy link
Contributor

@antoinedeschenes I apologise. I did a lot of work that weekend and was under the impression that I modified this project to run as non-root (was thinking of the Reflector project).
I'm currently doing some tests on the permissions.

@winromulus
Copy link
Contributor

@antoinedeschenes @josefschabasser - Fixed the issue by setting home directory permissions to 711.
I do not want to set them to 755 unless there's very good reasons to.
I've tested this and it works with public keys now.
Give it a spin if you can and if the problem persists, reopen the issue please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

4 participants