-
Notifications
You must be signed in to change notification settings - Fork 162
add max-auth-attempts #621
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
Open
vxpyy9
wants to merge
1
commit into
CESNET:devel
Choose a base branch
from
vxpyy9:devel
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1727,7 +1727,13 @@ nc_server_ssh_auth(struct nc_session *session, struct nc_server_ssh_opts *opts, | |
| ++session->opts.server.ssh_auth_attempts; | ||
| VRB(session, "Failed user \"%s\" authentication attempt (#%d).", session->username, | ||
| session->opts.server.ssh_auth_attempts); | ||
| 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 */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ssh_disconnect(session->ti.libssh.session); | ||
| } else { | ||
| ssh_message_reply_default(msg); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
|
|
@@ -2013,6 +2019,9 @@ nc_accept_ssh_session_auth(struct nc_session *session, struct nc_server_ssh_opts | |
|
|
||
| DBG(session, "SSH authentication..."); | ||
|
|
||
| /* copy so the value stays fixed even if endpoint-reference delegation later uses different opts */ | ||
| session->opts.server.ssh_max_auth_attempts = opts->max_auth_attempts; | ||
|
|
||
| /* authenticate */ | ||
| if (opts->auth_timeout) { | ||
| nc_timeouttime_get(&ts_timeout, opts->auth_timeout * 1000); | ||
|
|
@@ -2040,14 +2049,31 @@ nc_accept_ssh_session_auth(struct nc_session *session, struct nc_server_ssh_opts | |
| /* timeout */ | ||
| break; | ||
| } | ||
| if (session->opts.server.ssh_max_auth_attempts && | ||
| (session->opts.server.ssh_auth_attempts >= session->opts.server.ssh_max_auth_attempts)) { | ||
| /* max auth attempts reached */ | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!(session->flags & NC_SESSION_SSH_AUTHENTICATED)) { | ||
| /* timeout */ | ||
| if (session->username) { | ||
| ERR(session, "User \"%s\" failed to authenticate for too long, disconnecting.", session->username); | ||
| if (session->opts.server.ssh_max_auth_attempts && | ||
| (session->opts.server.ssh_auth_attempts >= session->opts.server.ssh_max_auth_attempts)) { | ||
| /* max auth attempts reached */ | ||
| if (session->username) { | ||
| ERR(session, "User \"%s\" reached the maximum number of failed SSH authentication attempts (%d), disconnecting.", | ||
| session->username, session->opts.server.ssh_max_auth_attempts); | ||
| } else { | ||
| ERR(session, "Reached the maximum number of failed SSH authentication attempts (%d), disconnecting.", | ||
| session->opts.server.ssh_max_auth_attempts); | ||
| } | ||
| } else { | ||
| ERR(session, "User failed to authenticate for too long, disconnecting."); | ||
| /* timeout */ | ||
| if (session->username) { | ||
| ERR(session, "User \"%s\" failed to authenticate for too long, disconnecting.", session->username); | ||
| } else { | ||
| ERR(session, "User failed to authenticate for too long, disconnecting."); | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.