diff --git a/pkg/ccl/oidcccl/authentication_oidc.go b/pkg/ccl/oidcccl/authentication_oidc.go index 276f83f3f0b2..b4e00e161508 100644 --- a/pkg/ccl/oidcccl/authentication_oidc.go +++ b/pkg/ccl/oidcccl/authentication_oidc.go @@ -137,10 +137,9 @@ type oidcAuthenticationConf struct { autoLogin bool } -// GetUIConf is used to extract certain parts of the OIDC -// configuration at run-time for embedding into the -// Admin UI HTML in order to manage the login experience -// the UI provides. +// GetOIDCConf is used to extract certain parts of the OIDC +// configuration at run-time for embedding into the DB Console in order +// to manage the login experience the UI provides. func (s *oidcAuthenticationServer) GetOIDCConf() ui.OIDCUIConf { return ui.OIDCUIConf{ ButtonText: s.conf.buttonText, diff --git a/pkg/cmd/dev/build.go b/pkg/cmd/dev/build.go index be2fa7d6382e..490905f61e79 100644 --- a/pkg/cmd/dev/build.go +++ b/pkg/cmd/dev/build.go @@ -89,6 +89,7 @@ var buildTargetMapping = map[string]string{ "label-merged-pr": "//pkg/cmd/label-merged-pr:label-merged-pr", "geos": geosTarget, "libgeos": geosTarget, + "obsservice": "//pkg/obsservice/cmd/obsservice", "optgen": "//pkg/sql/opt/optgen/cmd/optgen:optgen", "optfmt": "//pkg/sql/opt/optgen/cmd/optfmt:optfmt", "oss": "//pkg/cmd/cockroach-oss:cockroach-oss", @@ -412,7 +413,9 @@ func (d *dev) getBasicBuildArgs( // Add --config=with_ui iff we're building a target that needs it. for _, target := range buildTargets { - if target.fullName == buildTargetMapping["cockroach"] || target.fullName == buildTargetMapping["cockroach-oss"] { + if target.fullName == buildTargetMapping["cockroach"] || + target.fullName == buildTargetMapping["cockroach-oss"] || + target.fullName == buildTargetMapping["obsservice"] { args = append(args, "--config=with_ui") break } diff --git a/pkg/obsservice/cmd/obsservice/BUILD.bazel b/pkg/obsservice/cmd/obsservice/BUILD.bazel index 568b9e733198..2a94e51aa5f7 100644 --- a/pkg/obsservice/cmd/obsservice/BUILD.bazel +++ b/pkg/obsservice/cmd/obsservice/BUILD.bazel @@ -9,6 +9,7 @@ go_library( "//pkg/cli/exit", "//pkg/obsservice/obslib/httpproxy", "//pkg/obsservice/obslib/migrations", + "//pkg/ui/distoss", "@com_github_spf13_cobra//:cobra", ], ) diff --git a/pkg/obsservice/cmd/obsservice/main.go b/pkg/obsservice/cmd/obsservice/main.go index eab93130f991..da598f4d5b66 100644 --- a/pkg/obsservice/cmd/obsservice/main.go +++ b/pkg/obsservice/cmd/obsservice/main.go @@ -16,6 +16,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/cli/exit" "github.com/cockroachdb/cockroach/pkg/obsservice/obslib/httpproxy" "github.com/cockroachdb/cockroach/pkg/obsservice/obslib/migrations" + _ "github.com/cockroachdb/cockroach/pkg/ui/distoss" // web UI init hooks "github.com/spf13/cobra" ) diff --git a/pkg/obsservice/obslib/BUILD.bazel b/pkg/obsservice/obslib/BUILD.bazel deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/pkg/obsservice/obslib/httpproxy/BUILD.bazel b/pkg/obsservice/obslib/httpproxy/BUILD.bazel index 897933ce8716..d27dc7f9346f 100644 --- a/pkg/obsservice/obslib/httpproxy/BUILD.bazel +++ b/pkg/obsservice/obslib/httpproxy/BUILD.bazel @@ -7,6 +7,7 @@ go_library( visibility = ["//visibility:public"], deps = [ "//pkg/cli/exit", + "//pkg/ui", "//pkg/util/log", "//pkg/util/syncutil", "@com_github_cockroachdb_cmux//:cmux", diff --git a/pkg/obsservice/obslib/httpproxy/reverseproxy.go b/pkg/obsservice/obslib/httpproxy/reverseproxy.go index d1de62367312..3c5a844421b8 100644 --- a/pkg/obsservice/obslib/httpproxy/reverseproxy.go +++ b/pkg/obsservice/obslib/httpproxy/reverseproxy.go @@ -25,6 +25,7 @@ import ( "github.com/cockroachdb/cmux" "github.com/cockroachdb/cockroach/pkg/cli/exit" + "github.com/cockroachdb/cockroach/pkg/ui" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/syncutil" "github.com/cockroachdb/errors" @@ -95,6 +96,27 @@ to trust the certificate presented by CockroachDB.`) } } +// We define our own copy of this struct that also exists in +// pkg/server/authentication.go because we don't want to import that +// package. This struct is used to define a null OIDC configuration for +// the UI Config. DB Console uses information present here to show +// different login UI when OIDC is present. +type noOIDCConfigured struct{} + +var _ ui.OIDCUI = &noOIDCConfigured{} + +// GetOIDCConf implements the `ui.OIDCUI` interface with a configuration +// that disables OIDC login options for the UI server. +func (c *noOIDCConfigured) GetOIDCConf() ui.OIDCUIConf { + return ui.OIDCUIConf{ + Enabled: false, + } +} + +// CRDBProxyPaths is the list of path prefixes that are proxied to the +// underlying CRDB cluster. +var CRDBProxyPaths = []string{"/_admin/", "/_status/", "/ts/", "/api/v2/"} + // RunAsync runs an HTTP proxy server in a goroutine. The returned channel is // closed when the server terminates. // @@ -122,7 +144,21 @@ func (p *ReverseHTTPProxy) RunAsync(ctx context.Context) <-chan struct{} { // Create the HTTP mux. Requests will generally be forwarded to p.proxy, // except the /debug/pprof ones which will be served locally. mux := http.NewServeMux() - mux.Handle("/", p.proxy) + // TODO(davidh): Ideally, the UI handler should probably be + // configured in `obsservice` and not hardcoded into `obslib`. This + // gives lib users a chance to do whatever they want with the UI. + mux.Handle("/", ui.Handler(ui.Config{ + ExperimentalUseLogin: false, + LoginEnabled: false, + GetUser: func(ctx context.Context) *string { + u := "Observability Service" + return &u + }, + OIDC: &noOIDCConfigured{}, + })) + for _, path := range CRDBProxyPaths { + mux.Handle(path, p.proxy) + } // This seems to be the minimal set of handlers that we need to register in // order to get all the pprof functionality. The pprof.Index handler handles // some types of profiles itself. diff --git a/pkg/server/authentication.go b/pkg/server/authentication.go index 250b518010fd..b4bc6914b5ad 100644 --- a/pkg/server/authentication.go +++ b/pkg/server/authentication.go @@ -62,6 +62,8 @@ const ( type noOIDCConfigured struct{} +var _ ui.OIDCUI = &noOIDCConfigured{} + func (c *noOIDCConfigured) GetOIDCConf() ui.OIDCUIConf { return ui.OIDCUIConf{ Enabled: false, diff --git a/pkg/ui/ui.go b/pkg/ui/ui.go index 4feaf3b8e572..1e567446597d 100644 --- a/pkg/ui/ui.go +++ b/pkg/ui/ui.go @@ -138,11 +138,13 @@ func Handler(cfg Config) http.Handler { LoggedInUser: cfg.GetUser(r.Context()), Tag: buildInfo.Tag, Version: build.BinaryVersionPrefix(), - NodeID: cfg.NodeID.String(), OIDCAutoLogin: oidcConf.AutoLogin, OIDCLoginEnabled: oidcConf.Enabled, OIDCButtonText: oidcConf.ButtonText, } + if cfg.NodeID != nil { + args.NodeID = cfg.NodeID.String() + } if uiConfigPath.MatchString(r.URL.Path) { argBytes, err := json.Marshal(args) if err != nil {