Skip to content

Commit

Permalink
Refactor plugin.proto and pluginbase.go to add support for metadata i…
Browse files Browse the repository at this point in the history
…n connection context
  • Loading branch information
tg123 committed Oct 27, 2024
1 parent c8ca0c4 commit 9b24dfd
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 371 deletions.
10 changes: 10 additions & 0 deletions cmd/sshpiperd/internal/plugin/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func (cp *ChainPlugins) Append(p *GrpcPlugin) error {
func (cp *ChainPlugins) onNextPlugin(challengeCtx ssh.ChallengeContext, upstream *libplugin.UpstreamNextPluginAuth) error {
chain := challengeCtx.(*chainConnMeta)

if upstream.Meta != nil {
if chain.Metadata == nil {
chain.Metadata = make(map[string]string)
}

for k, v := range upstream.Meta {
chain.Metadata[k] = v
}
}

if chain.current+1 >= len(cp.pluginsCallback) {
return fmt.Errorf("no more plugins")
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/sshpiperd/internal/plugin/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (g *GrpcPlugin) CreateChallengeContext(conn ssh.ConnMetadata) (ssh.Challeng
UserName: conn.User(),
FromAddr: conn.RemoteAddr().String(),
UniqId: uiq.String(),
Metadata: make(map[string]string),
}

return &meta, g.NewConnection(&meta)
Expand All @@ -180,6 +181,7 @@ func (g *GrpcPlugin) NewConnection(meta *connMeta) error {
UserName: meta.UserName,
FromAddr: meta.FromAddr,
UniqId: meta.UniqId,
Metadata: meta.Metadata,
},
})

Expand Down
Loading

0 comments on commit 9b24dfd

Please sign in to comment.