fix sub dir version
This commit is contained in:
parent
ee76ceab6c
commit
ac593cca3f
2 changed files with 12 additions and 3 deletions
|
|
@ -7,6 +7,6 @@ var (
|
|||
NoCheckPerm bool `long:"upstream-workingdir-nocheckperm" description:"Disable 0400 checking when using files in the working directory" env:"SSHPIPERD_UPSTREAM_WORKINGDIR_NOCHECKPERM" ini-name:"upstream-workingdir-nocheckperm"`
|
||||
FallbackUsername string `long:"upstream-workingdir-fallbackusername" description:"Fallback to a user when user does not exists in directory" env:"SSHPIPERD_UPSTREAM_WORKINGDIR_FALLBACKUSERNAME" ini-name:"upstream-workingdir-fallbackusername"`
|
||||
StrictHostKey bool `long:"upstream-workingdir-stricthostkey" description:"Upstream host public key must be in known_hosts file, otherwise drop the connection" env:"SSHPIPERD_UPSTREAM_WORKINGDIR_STRICTHOSTKEY" ini-name:"upstream-workingdir-stricthostkey"`
|
||||
MatchPublicKeyInSubDir bool `long:"upstream-workingdir-matchpublickeyinsubdir" description:"Remap user in user's sub dir with publickey" env:"SSHPIPERD_UPSTREAM_WORKINGDIR_MATCHPUBLICKeYINSUBDIR" ini-name:"upstream-workingdir-matchpublickeyinsubdir"`
|
||||
MatchPublicKeyInSubDir bool `long:"upstream-workingdir-matchpublickeyinsubdir" description:"Remap user in user's sub dir with publickey" env:"SSHPIPERD_UPSTREAM_WORKINGDIR_MATCHPUBLICKEYINSUBDIR" ini-name:"upstream-workingdir-matchpublickeyinsubdir"`
|
||||
}{}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,15 @@ func (p *plugin) InstallUpstream(piper *ssh.PiperConfig) error {
|
|||
|
||||
piper.PublicKeyCallback = p.matchPublicKeyInSubDir
|
||||
|
||||
if config.MatchPublicKeyInSubDir {
|
||||
old := piper.NextAuthMethods
|
||||
piper.NextAuthMethods = func(conn ssh.ConnMetadata, ctx ssh.ChallengeContext) ([]string, error) {
|
||||
methods, err := old(conn, ctx)
|
||||
methods = append(methods, "publickey")
|
||||
return methods, err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +111,7 @@ func (p *plugin) matchPublicKeyInSubDir(conn ssh.ConnMetadata, key ssh.PublicKey
|
|||
// search in working dir
|
||||
filepath.Walk(config.WorkingDir, func(path string, info os.FileInfo, err error) error {
|
||||
|
||||
logger.Debug("search public key in path: %v", path)
|
||||
logger.Debugf("search public key in path: %v", path)
|
||||
if err != nil {
|
||||
logger.Debug("error walking path: ", err)
|
||||
return nil
|
||||
|
|
@ -114,7 +123,7 @@ func (p *plugin) matchPublicKeyInSubDir(conn ssh.ConnMetadata, key ssh.PublicKey
|
|||
|
||||
u, err := p.matchPublicKeyDir(conn, key, conn.User(), path)
|
||||
if err != nil {
|
||||
logger.Info("cannot map private key in %v: %v, search next", path, err)
|
||||
logger.Infof("cannot map private key in %v: %v, search next", path, err)
|
||||
}
|
||||
|
||||
if u != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue