-
Couldn't load subscription status.
- Fork 57
Add a ChannelOption for a server to query the authenticated username. #58
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
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
ChannelOptionnamedSSHChildChannelOptions.Types. UsernameOptionwhich is aString?of the username if authenticated, otherwise nil.The new code passes the
usernamealong with the chain of possible completions from an authentication request until it reaches the creation of the.userAuthSuccessmessage. This message is augmented with an associatedString?to hold the username. Eventually, this message will arrive at theSSHConnectionStateMachine, where it will be recorded.The
NIOSSHHandlercontains theSSHConnectionStateMachine, and there is a parent path reaching up from theSSHChildHandlerto theNIOSSHHandler. This path is festooned withvar username:String?properties to allowthe
SSHChildHandlerto reach up and back down to get the username when theUsernameOptionis requested.I wonder a bit about adding the associated type to the
.userAuthSuccessSSHMessage, but most of them have associateddata already. I had to add explicit
nilvalues 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
ChannelOptions are also untested and suspect that has something to do with it. My knowledge of NIO stops a littleshort of understanding the
BackToBackEmbeddedChanneltest harness. I've been testing the PR from my SSHConsoleproject's
echoserver and it appears to work fine.