Expose proxy host to permissions system
This commit is contained in:
		| @@ -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,8 +78,9 @@ 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 { | ||||||
| @@ -90,13 +88,13 @@ func Proxy(route config.Route) router.Handler { | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			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") | ||||||
| 		} | 		} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user