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

Fix debug service not being disabled by configuration #46032

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
11 changes: 9 additions & 2 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ type CommandLineFlags struct {

// ProfileSeconds defines the time the pprof will be collected.
ProfileSeconds int

// DisableDebugService disables the debug service.
DisableDebugService bool
}

// IntegrationConfAccessGraphAWSSync contains the arguments of
Expand Down Expand Up @@ -462,8 +465,8 @@ func ApplyFileConfig(fc *FileConfig, cfg *servicecfg.Config) error {
if fc.WindowsDesktop.Disabled() {
cfg.WindowsDesktop.Enabled = false
}
if fc.Debug.Enabled() {
cfg.DebugService.Enabled = true
if fc.Debug.Disabled() {
cfg.DebugService.Enabled = false
}

if fc.AccessGraph.Enabled {
Expand Down Expand Up @@ -2647,6 +2650,10 @@ func Configure(clf *CommandLineFlags, cfg *servicecfg.Config, legacyAppFlags boo
}
}

if clf.DisableDebugService {
cfg.DebugService.Enabled = false
}

return nil
}

Expand Down
44 changes: 44 additions & 0 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5003,3 +5003,47 @@ func TestProxyUntrustedCert(t *testing.T) {
// - the system root certs are loaded exactly once and cached
// - it only works on linux
}

func TestDebugServiceConfig(t *testing.T) {
for name, tc := range map[string]struct {
configFile string
commandLineFlags *CommandLineFlags
expectDebugServiceEnabled bool
}{
"enabled by default": {configFile: "", expectDebugServiceEnabled: true},
"disabled by commandline": {
configFile: "",
commandLineFlags: &CommandLineFlags{DisableDebugService: true},
expectDebugServiceEnabled: false,
},
"disabled by configuration": {
configFile: `
debug_service:
enabled: "no"
`,
expectDebugServiceEnabled: false,
},
"commandline flag has priority over config file": {
configFile: `
debug_service:
enabled: "yes"
`,
commandLineFlags: &CommandLineFlags{DisableDebugService: true},
expectDebugServiceEnabled: false,
},
} {
gabrielcorado marked this conversation as resolved.
Show resolved Hide resolved
t.Run(name, func(t *testing.T) {
filePath := filepath.Join(t.TempDir(), "config.yaml")
require.NoError(t, os.WriteFile(filePath, []byte(tc.configFile), 0o777))

if tc.commandLineFlags == nil {
tc.commandLineFlags = &CommandLineFlags{}
}
tc.commandLineFlags.ConfigFile = filePath

conf := servicecfg.MakeDefaultConfig()
require.NoError(t, Configure(tc.commandLineFlags, conf, false))
require.Equal(t, tc.expectDebugServiceEnabled, conf.DebugService.Enabled)
})
}
}
3 changes: 3 additions & 0 deletions tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
start.Flag("db-aws-region",
"AWS region AWS hosted database instance is running in.").Hidden().
StringVar(&ccf.DatabaseAWSRegion)
start.Flag("no-debug-service", "Disables debug service.").BoolVar(&ccf.DisableDebugService)

// define start's usage info (we use kingpin's "alias" field for this)
start.Alias(usageNotes + usageExamples)
Expand All @@ -218,6 +219,7 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
appStartCmd.Flag("diag-addr", "Start diagnostic prometheus and healthz endpoint.").StringVar(&ccf.DiagnosticAddr)
appStartCmd.Flag("insecure", "Insecure mode disables certificate validation").BoolVar(&ccf.InsecureMode)
appStartCmd.Flag("skip-version-check", "Skip version checking between server and client.").Default("false").BoolVar(&ccf.SkipVersionCheck)
appStartCmd.Flag("no-debug-service", "Disables debug service.").BoolVar(&ccf.DisableDebugService)
appStartCmd.Alias(appUsageExamples) // We're using "alias" section to display usage examples.

// "teleport db" command and its subcommands
Expand Down Expand Up @@ -254,6 +256,7 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
dbStartCmd.Flag("diag-addr", "Start diagnostic prometheus and healthz endpoint.").StringVar(&ccf.DiagnosticAddr)
dbStartCmd.Flag("insecure", "Insecure mode disables certificate validation").BoolVar(&ccf.InsecureMode)
dbStartCmd.Flag("skip-version-check", "Skip version checking between server and client.").Default("false").BoolVar(&ccf.SkipVersionCheck)
dbStartCmd.Flag("no-debug-service", "Disables debug service.").BoolVar(&ccf.DisableDebugService)
dbStartCmd.Alias(dbUsageExamples) // We're using "alias" section to display usage examples.

dbConfigure := dbCmd.Command("configure", "Bootstraps database service configuration and cloud permissions.")
Expand Down
Loading