Skip to content

Commit

Permalink
Add DisableIncludeRequestableRequests to UIConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
avatus committed May 2, 2024
1 parent d0e5a78 commit 25f45af
Show file tree
Hide file tree
Showing 11 changed files with 1,711 additions and 1,605 deletions.
6 changes: 5 additions & 1 deletion api/client/webclient/webconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ type FeatureLimits struct {
// UIConfig provides config options for the web UI served by the proxy service.
type UIConfig struct {
// ScrollbackLines is the max number of lines the UI terminal can display in its history
ScrollbackLines int `json:"scrollbackLines,omitempty"` //nolint:unused // marshaled in config/configuration.go for WebConfig
ScrollbackLines int `json:"scrollbackLines,omitempty"`
// ShowResources determines which resources are shown in the web UI. Default if unset is "requestable"
// which means resources the user has access to and resources they can request will be shown in the
// resources UI. If set to `accessible_only`, only resources the user already has access to will be shown.
ShowResources constants.ShowResources `json:"showResources,omitempty"`
}

// WebConfigAuthProvider describes auth. provider
Expand Down
13 changes: 13 additions & 0 deletions api/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@ const (
SessionRecordingModeBestEffort = SessionRecordingMode("best_effort")
)

// ShowResources determines which resources are shown in the web UI. Default if unset is "requestable"
// which means resources the user has access to and resources they can request will be shown in the
// resources UI. If set to `accessible_only`, only resources the user already has access to will be shown.
type ShowResources string

const (
// ShowResourcesaccessibleOnly will only show resources the user currently has access to.
ShowResourcesaccessibleOnly = ShowResources("accessible_only")

// ShowResourcesRequestable will allow resources that the user can request into resources page.
ShowResourcesRequestable = ShowResources("requestable")
)

// Constants for Traits
const (
// TraitLogins is the name of the role variable used to store
Expand Down
8 changes: 8 additions & 0 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5425,7 +5425,15 @@ message UIConfigV1 {

// UIConfigSpecV1 is the specification for a UIConfig
message UIConfigSpecV1 {
// ScrollbackLines is the max number of lines the UI terminal can display in its history.
int32 ScrollbackLines = 1 [(gogoproto.jsontag) = "scrollback_lines"];
// ShowResources determines which resources are shown in the web UI. Default if unset is "requestable"
// which means resources the user has access to and resources they can request will be shown in the
// resources UI. If set to `accessible_only`, only resources the user already has access to will be shown.
string ShowResources = 2 [
(gogoproto.jsontag) = "show_resources,omitempty",
(gogoproto.casttype) = "github.com/gravitational/teleport/api/constants.ShowResources"
];
}

// InstallerV1 represents an installer script resource. Used to
Expand Down
3,249 changes: 1,650 additions & 1,599 deletions api/types/types.pb.go

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions api/types/ui_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ import (
"time"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/constants"
)

// UIConfig defines configuration for the web UI served
// by the proxy service. This is a configuration resource,
// never create more than one instance of it.
type UIConfig interface {
Resource

// GetScript returns the contents of the installer script
// GetShowResources will returns which resources should be shown in the unified resources UI
GetShowResources() constants.ShowResources
// GetScrollbackLines returns the amount of scrollback lines the terminal remembers
GetScrollbackLines() int32
// SetScript sets the installer script
// SetScrollbackLines sets the amount of scrollback lines the terminal remembers
SetScrollbackLines(int32)

String() string
Expand All @@ -55,6 +58,15 @@ func (c *UIConfigV1) CheckAndSetDefaults() error {
if c.Spec.ScrollbackLines < 0 {
return trace.BadParameter("invalid scrollback lines value. Must be greater than or equal to 0.")
}
if c.Spec.ShowResources == "" {
c.Spec.ShowResources = constants.ShowResourcesRequestable
}
switch c.Spec.ShowResources {
case constants.ShowResourcesaccessibleOnly,
constants.ShowResourcesRequestable:
default:
return trace.BadParameter("show resources %q not supported", c.Spec.ShowResources)
}
return nil
}

Expand Down Expand Up @@ -113,6 +125,11 @@ func (c *UIConfigV1) SetSubKind(sk string) {
c.SubKind = sk
}

// GetShowResources will returns which resources should be shown in the unified resources UI
func (c *UIConfigV1) GetShowResources() constants.ShowResources {
return c.Spec.ShowResources
}

func (c *UIConfigV1) GetScrollbackLines() int32 {
return c.Spec.ScrollbackLines
}
Expand Down
6 changes: 6 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,12 @@ func applyProxyConfig(fc *FileConfig, cfg *servicecfg.Config) error {

if fc.Proxy.UI != nil {
cfg.Proxy.UI = webclient.UIConfig(*fc.Proxy.UI)
switch cfg.Proxy.UI.ShowResources {
case constants.ShowResourcesaccessibleOnly,
constants.ShowResourcesRequestable:
default:
return trace.BadParameter("show resources %q not supported", cfg.Proxy.UI.ShowResources)
}
}

if fc.Proxy.Assist != nil && fc.Proxy.Assist.OpenAI != nil {
Expand Down
4 changes: 4 additions & 0 deletions lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,10 @@ type Proxy struct {
type UIConfig struct {
// ScrollbackLines is the max number of lines the UI terminal can display in its history
ScrollbackLines int `yaml:"scrollback_lines,omitempty"`
// ShowResources determines which resources are shown in the web UI. Default if unset is "requestable"
// which means resources the user has access to and resources they can request will be shown in the
// resources UI. If set to `accessible_only`, only resources the user already has access to will be shown.
ShowResources constants.ShowResources `yaml:"show_resources,omitempty"`
}

// ACME configures ACME protocol - automatic X.509 certificates
Expand Down
1 change: 1 addition & 0 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,7 @@ func (h *Handler) getUIConfig(ctx context.Context) webclient.UIConfig {
if uiConfig, err := h.cfg.AccessPoint.GetUIConfig(ctx); err == nil && uiConfig != nil {
return webclient.UIConfig{
ScrollbackLines: int(uiConfig.GetScrollbackLines()),
ShowResources: uiConfig.GetShowResources(),
}
}
return h.cfg.UI
Expand Down
1 change: 1 addition & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,7 @@ func TestNewTerminalHandler(t *testing.T) {
func TestUIConfig(t *testing.T) {
uiConfig := webclient.UIConfig{
ScrollbackLines: 555,
ShowResources: constants.ShowResourcesaccessibleOnly,
}
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions tool/tctl/common/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ func (c *uiConfigCollection) resources() (r []types.Resource) {
}

func (c *uiConfigCollection) writeText(w io.Writer, verbose bool) error {
t := asciitable.MakeTable([]string{"Scrollback Lines"})
t.AddRow([]string{string(c.uiconfig.GetScrollbackLines())})
t := asciitable.MakeTable([]string{"Scrollback Lines", "Show Resources"})
t.AddRow([]string{strconv.FormatInt(int64(c.uiconfig.GetScrollbackLines()), 10), string(c.uiconfig.GetShowResources())})
_, err := t.AsBuffer().WriteTo(w)
return trace.Wrap(err)
}
Expand Down
1 change: 1 addition & 0 deletions web/packages/teleport/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const cfg = {

ui: {
scrollbackLines: 1000,
showResources: 'requestable',
},

auth: {
Expand Down

0 comments on commit 25f45af

Please sign in to comment.