Skip to content

Commit

Permalink
Fix: Check for missing client config in secure socks proxy check (#1179)
Browse files Browse the repository at this point in the history
* Fix: Check for missing client config in secure socks proxy check

* add clarifying comment

* Update backend/proxy/secure_socks_proxy.go

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>

* fixup suggestion comment

* pr comments

---------

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
  • Loading branch information
kevinwcyu and wbrowne authored Jan 8, 2025
1 parent 75f67e7 commit 5364a9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 4 additions & 5 deletions backend/proxy/secure_socks_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,14 @@ type cfgProxyWrapper struct {
}

// SecureSocksProxyEnabled checks if the Grafana instance allows the secure socks proxy to be used
// and the datasource options specify to use the proxy
// and the datasource options specify to use the proxy.
// The secure proxy can only be used if it's enabled on both the datasource connection and the client (Grafana server)
func (p *cfgProxyWrapper) SecureSocksProxyEnabled() bool {
// it cannot be enabled if it's not enabled on Grafana
if p.opts == nil {
if p.opts == nil || !p.opts.Enabled || p.opts.ClientCfg == nil {
return false
}

// if it's enabled on Grafana, check if the datasource is using it
return (p.opts != nil) && p.opts.Enabled
return true
}

// ConfigureSecureSocksHTTPProxy takes a http.DefaultTransport and wraps it in a socks5 proxy with TLS
Expand Down
6 changes: 5 additions & 1 deletion backend/proxy/secure_socks_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ func TestSecureSocksProxyEnabled(t *testing.T) {
cli := New(nil)
assert.Equal(t, false, cli.SecureSocksProxyEnabled())
})
t.Run("enabled, if Enabled field is true", func(t *testing.T) {
t.Run("not enabled if opts.ClientCfg is nil", func(t *testing.T) {
cli := New(&Options{Enabled: true})
assert.Equal(t, false, cli.SecureSocksProxyEnabled())
})
t.Run("enabled, if Enabled field is true", func(t *testing.T) {
cli := New(&Options{Enabled: true, ClientCfg: &ClientCfg{}})
assert.Equal(t, true, cli.SecureSocksProxyEnabled())
})
}
Expand Down

0 comments on commit 5364a9d

Please sign in to comment.