diff options
Diffstat (limited to 'app/controllers/proxy.go')
-rw-r--r-- | app/controllers/proxy.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/controllers/proxy.go b/app/controllers/proxy.go index c8345e8..9e3ec13 100644 --- a/app/controllers/proxy.go +++ b/app/controllers/proxy.go | |||
@@ -12,6 +12,21 @@ import ( | |||
12 | 12 | ||
13 | "github.com/gorilla/websocket" | 13 | "github.com/gorilla/websocket" |
14 | "github.com/labstack/echo/v4" | 14 | "github.com/labstack/echo/v4" |
15 | "github.com/prometheus/client_golang/prometheus" | ||
16 | "github.com/prometheus/client_golang/prometheus/promauto" | ||
17 | ) | ||
18 | |||
19 | var ( | ||
20 | proxyError = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
21 | Namespace: "ssh_proxy", | ||
22 | Name: "proxy_error", | ||
23 | Help: "Total number of errors during proxy setup operation", | ||
24 | }, []string{"type"}) | ||
25 | proxySuccess = promauto.NewCounter(prometheus.CounterOpts{ | ||
26 | Namespace: "ssh_proxy", | ||
27 | Name: "proxy_success", | ||
28 | Help: "Total number of successful proxy sessions", | ||
29 | }) | ||
15 | ) | 30 | ) |
16 | 31 | ||
17 | type ProxyHandler struct { | 32 | type ProxyHandler struct { |
@@ -37,6 +52,7 @@ func (h *ProxyHandler) authorizeRequest(c echo.Context) error { | |||
37 | } | 52 | } |
38 | 53 | ||
39 | if !session.HasScope("ssh:proxy") { | 54 | if !session.HasScope("ssh:proxy") { |
55 | proxyError.With(prometheus.Labels{"type": "token_missing_scope"}).Inc() | ||
40 | return fmt.Errorf("Authorized session does not have scope ssh:proxy") | 56 | return fmt.Errorf("Authorized session does not have scope ssh:proxy") |
41 | } | 57 | } |
42 | 58 | ||
@@ -46,6 +62,7 @@ func (h *ProxyHandler) authorizeRequest(c echo.Context) error { | |||
46 | return nil | 62 | return nil |
47 | } | 63 | } |
48 | 64 | ||
65 | proxyError.With(prometheus.Labels{"type": "not_authorized"}).Inc() | ||
49 | return fmt.Errorf("User %s not authorized for host %s", session.UserId, host) | 66 | return fmt.Errorf("User %s not authorized for host %s", session.UserId, host) |
50 | } | 67 | } |
51 | 68 | ||
@@ -70,6 +87,8 @@ func (h *ProxyHandler) Handle(c echo.Context) error { | |||
70 | errc := make(chan error) | 87 | errc := make(chan error) |
71 | ws := &proxy.WebsocketReadWriter{W: wsconn} | 88 | ws := &proxy.WebsocketReadWriter{W: wsconn} |
72 | 89 | ||
90 | proxySuccess.Inc() | ||
91 | |||
73 | go proxy.CopyWithErrors(proxyconn, ws, errc) | 92 | go proxy.CopyWithErrors(proxyconn, ws, errc) |
74 | go proxy.CopyWithErrors(ws, proxyconn, errc) | 93 | go proxy.CopyWithErrors(ws, proxyconn, errc) |
75 | 94 | ||