Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obsservice: ui handler serves db console assets #82741

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/ccl/oidcccl/authentication_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/obsservice/cmd/obsservice/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
1 change: 1 addition & 0 deletions pkg/obsservice/cmd/obsservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Empty file removed pkg/obsservice/obslib/BUILD.bazel
Empty file.
1 change: 1 addition & 0 deletions pkg/obsservice/obslib/httpproxy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
38 changes: 37 additions & 1 deletion pkg/obsservice/obslib/httpproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
//
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (

type noOIDCConfigured struct{}

var _ ui.OIDCUI = &noOIDCConfigured{}

func (c *noOIDCConfigured) GetOIDCConf() ui.OIDCUIConf {
return ui.OIDCUIConf{
Enabled: false,
Expand Down
4 changes: 3 additions & 1 deletion pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down