Compare commits

..

No commits in common. "792dfdba78125b85ac2b6f9e5189315581209f79" and "6d6ed302276071cb2bd398e88020b8131c3a5c3e" have entirely different histories.

3 changed files with 19 additions and 13 deletions

View File

@ -22,6 +22,8 @@
package backends package backends
import ( import (
"strings"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
"go.elara.ws/seashell/internal/config" "go.elara.ws/seashell/internal/config"
"go.elara.ws/seashell/internal/router" "go.elara.ws/seashell/internal/router"
@ -82,6 +84,17 @@ func ctyObjToStringMap(o *cty.Value) map[string]string {
return out return out
} }
// sshGetenv gets an environment variable from the SSH session
func sshGetenv(env []string, key string) string {
for _, kv := range env {
before, after, ok := strings.Cut(kv, "=")
if ok && before == key {
return after
}
}
return ""
}
// valueOr returns the value that v points to // valueOr returns the value that v points to
// or a default value if v is nil. // or a default value if v is nil.
func valueOr[T any](v *T, or T) T { func valueOr[T any](v *T, or T) T {

View File

@ -41,7 +41,6 @@ type dockerSettings struct {
Command *cty.Value `cty:"command"` Command *cty.Value `cty:"command"`
Privileged *bool `cty:"privileged"` Privileged *bool `cty:"privileged"`
User *string `cty:"user"` User *string `cty:"user"`
UserMap *cty.Value `cty:"user_map"`
} }
// Docker is the docker backend. It returns a handler that connects // Docker is the docker backend. It returns a handler that connects
@ -64,17 +63,6 @@ func Docker(route config.Route) router.Handler {
return errors.New("this route only accepts pty sessions (try adding the -t flag)") return errors.New("this route only accepts pty sessions (try adding the -t flag)")
} }
if opts.User == nil {
userMap := ctyObjToStringMap(opts.UserMap)
user, _ := sshctx.GetUser(sess.Context())
if muser, ok := userMap[user.Name]; ok {
opts.User = &muser
} else {
opts.User = &user.Name
}
}
c, err := client.NewClientWithOpts( c, err := client.NewClientWithOpts(
client.WithHostFromEnv(), client.WithHostFromEnv(),
client.WithVersionFromEnv(), client.WithVersionFromEnv(),
@ -84,6 +72,11 @@ func Docker(route config.Route) router.Handler {
return err return err
} }
if opts.User == nil {
envUser := sshGetenv(sess.Environ(), "DOCKER_USER")
opts.User = &envUser
}
cmd := sess.Command() cmd := sess.Command()
if len(cmd) == 0 { if len(cmd) == 0 {
cmd = ctyTupleToStrings(opts.Command) cmd = ctyTupleToStrings(opts.Command)

View File

@ -44,7 +44,7 @@ type proxySettings struct {
Server string `cty:"server"` Server string `cty:"server"`
User *string `cty:"user"` User *string `cty:"user"`
PrivkeyPath *string `cty:"privkey"` PrivkeyPath *string `cty:"privkey"`
UserMap *cty.Value `cty:"user_map"` UserMap *cty.Value `cty:"userMap"`
} }
// Proxy is the proxy backend. It returns a handler that establishes a proxy // Proxy is the proxy backend. It returns a handler that establishes a proxy