-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add a ChannelOption for a server to query the authenticated username. #58
base: main
Are you sure you want to change the base?
Conversation
A server may wish to know which user authenticated to decide what they are authorized to do. Modifications: - On an authentication request, keep the username until it can be associated with a userAuthSuccess message. - Once that userAuthSuccess message reaches the SSHConnectionStateMachine, record the successful username. - Carve an access path from a SSHChildChannel up through its multiplexor, to the NIOSSHHandler, and back down to the SSHConnectionStateMachine to get the username. - Implement a ChannelOption in SSHChildChannel for ChannelHandlers to query their username.
Can one of the admins verify this patch? |
3 similar comments
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
Can one of the admins verify this patch? |
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.
Thanks for this patch! This looks like a good start! I've left a few notes in the diff about how we might want to take this forward.
Sources/NIOSSH/Connection State Machine/SSHConnectionStateMachine.swift
Outdated
Show resolved
Hide resolved
Sources/NIOSSH/Connection State Machine/Operations/AcceptsUserAuthMessages.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Cory Benfield <[email protected]>
…hSuccess message.
…ection attributes. Use it to collect the authenticated username before that name is obliterated.
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.
This touches a lot of files, but mostly that's just adding it to each state.
I noticed a couple comments about TODO work needing to limit the number of attempts for various activities, this 'connectionAttributes' area would be an easy place to implement a counter for those in the future.
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.
Looks like a good set of changes to me!
@Lukasa can we merge this? |
Some servers will need to know which user authenticated. This PR exposes that information through a
ChannelOption
namedSSHChildChannelOptions.Types. UsernameOption
which is aString?
of the username if authenticated, otherwise nil.The new code passes the
username
along with the chain of possible completions from an authentication request until it reaches the creation of the.userAuthSuccess
message. This message is augmented with an associatedString?
to hold the username. Eventually, this message will arrive at theSSHConnectionStateMachine
, where it will be recorded.The
NIOSSHHandler
contains theSSHConnectionStateMachine
, and there is a parent path reaching up from theSSHChildHandler
to theNIOSSHHandler
. This path is festooned withvar username:String?
properties to allowthe
SSHChildHandler
to reach up and back down to get the username when theUsernameOption
is requested.I wonder a bit about adding the associated type to the
.userAuthSuccess
SSHMessage, but most of them have associateddata already. I had to add explicit
nil
values wherever they are created without a username.I could have stored the actual username directly in the
NIOSSHHandler
, but that would have required adding a per-message inspection inNIOSSHHandler
. It was already being done inSSHConnectionStateMachine
, but there isn't a parent link back up to set the value inNIOSSHHandler
.I didn't find a test which sets up a server and checks its behavior in order to write tests. I note that the other
ChannelOption
s are also untested and suspect that has something to do with it. My knowledge of NIO stops a littleshort of understanding the
BackToBackEmbeddedChannel
test harness. I've been testing the PR from my SSHConsoleproject's
echo
server and it appears to work fine.