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

perf: 重置用户 ssh 认证客户端请求 #1296

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions pkg/auth/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type SSHAuthFunc func(ctx ssh.Context, password, publicKey string) (res ssh.Auth

func SSHPasswordAndPublicKeyAuth(jmsService *service.JMService) SSHAuthFunc {
return func(ctx ssh.Context, password, publicKey string) (res ssh.AuthResult) {
if password == "" && publicKey == "" {
logger.Errorf("SSH conn[%s] no password and publickey", ctx.SessionID())
return ssh.AuthFailed
}
remoteAddr, _, _ := net.SplitHostPort(ctx.RemoteAddr().String())
username := ctx.User()
if req, ok := parseDirectLoginReq(jmsService, ctx); ok {
Expand All @@ -35,25 +39,22 @@ func SSHPasswordAndPublicKeyAuth(jmsService *service.JMService) SSHAuthFunc {
if password != "" {
authMethod = "password"
}
userAuthClient, ok := ctx.Value(ContextKeyClient).(*UserAuthClient)
if !ok {
newClient := jmsService.CloneClient()
var accessKey model.AccessKey
conf := config.GetConf()
_ = accessKey.LoadFromFile(conf.AccessKeyFilePath)
userClient := service.NewUserClient(
service.UserClientUsername(username),
service.UserClientRemoteAddr(remoteAddr),
service.UserClientLoginType("T"),
service.UserClientHttpClient(&newClient),
service.UserClientSvcSignKey(accessKey),
)
userAuthClient = &UserAuthClient{
UserClient: userClient,
authOptions: make(map[string]authOptions),
}
ctx.SetValue(ContextKeyClient, userAuthClient)
newClient := jmsService.CloneClient()
var accessKey model.AccessKey
conf := config.GetConf()
_ = accessKey.LoadFromFile(conf.AccessKeyFilePath)
userClient := service.NewUserClient(
service.UserClientUsername(username),
service.UserClientRemoteAddr(remoteAddr),
service.UserClientLoginType("T"),
service.UserClientHttpClient(&newClient),
service.UserClientSvcSignKey(accessKey),
)
userAuthClient := &UserAuthClient{
UserClient: userClient,
authOptions: make(map[string]authOptions),
}
ctx.SetValue(ContextKeyClient, userAuthClient)
userAuthClient.SetOption(service.UserClientPassword(password),
service.UserClientPublicKey(publicKey))
logger.Infof("SSH conn[%s] authenticating user %s %s", ctx.SessionID(), username, authMethod)
Expand Down
Loading