Expose proxy host to permissions system
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Elara 2024-08-12 17:43:12 -07:00
parent e7994824a5
commit 70788ba261

View File

@ -55,9 +55,6 @@ type proxySettings struct {
func Proxy(route config.Route) router.Handler { func Proxy(route config.Route) router.Handler {
return func(sess ssh.Session, arg string) error { return func(sess ssh.Session, arg string) error {
user, _ := sshctx.GetUser(sess.Context()) user, _ := sshctx.GetUser(sess.Context())
if !route.Permissions.IsAllowed(user, "*") {
return router.ErrUnauthorized
}
var opts proxySettings var opts proxySettings
err := gocty.FromCtyValue(route.Settings, &opts) err := gocty.FromCtyValue(route.Settings, &opts)
@ -81,22 +78,23 @@ func Proxy(route config.Route) router.Handler {
} }
} }
var matched bool matched := false
var addr, portstr string addr := arg
var portstr, pattern string
if opts.Host == nil { if opts.Host == nil {
hosts := ctyTupleToStrings(opts.Hosts) hosts := ctyTupleToStrings(opts.Hosts)
if len(hosts) == 0 { if len(hosts) == 0 {
return errors.New("no host configuration provided") return errors.New("no host configuration provided")
} }
for _, hostPattern := range hosts { for _, hostPattern := range hosts {
addr, portstr, ok = strings.Cut(hostPattern, ":") pattern, portstr, ok = strings.Cut(hostPattern, ":")
if !ok { if !ok {
// addr is already set by the above statement, so just set the default port // addr is already set by the above statement, so just set the default port
portstr = "22" portstr = "22"
} }
matched, err = path.Match(addr, arg) matched, err = path.Match(pattern, arg)
if err != nil { if err != nil {
return err return err
} }
@ -114,6 +112,10 @@ func Proxy(route config.Route) router.Handler {
} }
} }
if !route.Permissions.IsAllowed(user, addr) {
return router.ErrUnauthorized
}
if !matched { if !matched {
return errors.New("provided argument doesn't match any host patterns in configuration") return errors.New("provided argument doesn't match any host patterns in configuration")
} }