Skip to content

add max-auth-attempts - #621

Open
vxpyy9 wants to merge 1 commit into
CESNET:develfrom
vxpyy9:devel
Open

add max-auth-attempts#621
vxpyy9 wants to merge 1 commit into
CESNET:develfrom
vxpyy9:devel

Conversation

@vxpyy9

@vxpyy9 vxpyy9 commented Jul 16, 2026

Copy link
Copy Markdown

Limit the number of failed SSH authentication attempts before the server disconnects the client, default 3.

Limit the number of failed SSH authentication attempts before
the server disconnects the client, default 3.

@Roytak Roytak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, thank you for the contribution. This feature was part of the code a couple years ago, but we decided to remove it. Is there any specific reason why you find it useful to have? I found a couple things that will need to be adjusted and also you should add a new test e.g. to test_ssh.c that tests this.

Comment on lines +167 to +174
leaf max-auth-attempts {
type uint16 {
range "1..max";
}
default 3;
description
"Maximum number of failed SSH authentication attempts before disconnecting the client.";
}

@Roytak Roytak Jul 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mention in the description that it is per connection. I think that the RFC4252 should be referenced here.

Furthermore, this description should probably mention something along the lines "each failed authentication request, including rejected public keys, counts as one attempt", because some SSH clients try all their configured public keys and hence hitting the 3 might be easy, so just so the users are aware.

Comment thread src/session_server_ssh.c
Comment on lines 1638 to 1645
/* user not known, set his authentication methods to public key only so that
* there is no interaction and it will simply be denied */
ERR(NULL, "User \"%s\" not known by the server.", username);
ssh_set_auth_methods(session->ti.libssh.session, SSH_AUTH_METHOD_PUBLICKEY);
ssh_message_reply_default(msg);
return 0;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ssh_auth_attempts need to be increased here, otherwise it would always remain 0 and that would lead to unlimited authenticaiton attempts (e.g. 3 would never be reached by the calling function) + we need to either reach the code checking if we hit max attempts from here or copy it here.

Comment thread src/session_server_ssh.c
ssh_message_reply_default(msg);
if (session->opts.server.ssh_max_auth_attempts &&
(session->opts.server.ssh_auth_attempts >= session->opts.server.ssh_max_auth_attempts)) {
/* disconnect immediately so client does not prompt again */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that both ssh_message_reply_default and ssh_disconnect should be called here, the abrupt disconnect is unnecessary.

Comment thread src/session_server_ssh.c
Comment on lines 1704 to 1707
++session->opts.server.ssh_auth_attempts;
VRB(session, "Authentication method \"%s\" not supported.", str_method);
ssh_message_reply_default(msg);
return 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could make this more consistent, by just setting ret = 1 and then down below the max attempts check would happen + the possible disconnect. Mention this in a comment above the VRB.

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