Skip to content

Commit

Permalink
[v15] Fix debug service not being disabled by configuration (#46292)
Browse files Browse the repository at this point in the history
* fix(config): update conditional check to disabled debug service

* refactor(teleport): rename flag and make it public

* test(config): add a test case with config file and command line arg

* chore(config): fix command line flag name typo
  • Loading branch information
gabrielcorado authored Sep 5, 2024
1 parent 0fb193a commit 52bdeaa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,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 @@ -453,8 +456,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 @@ -2655,6 +2658,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 @@ -5050,3 +5050,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,
},
} {
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

0 comments on commit 52bdeaa

Please sign in to comment.