gravitational / teleport

The easiest, and most secure way to access and protect all of your infrastructure.
https://goteleport.com
GNU Affero General Public License v3.0
17.28k stars 1.73k forks source link

config file log level affects `teleport` command verbosity #44483

Open GavinFrazar opened 1 month ago

GavinFrazar commented 1 month ago

We should add a --debug flag to teleport, and for commands that don't start a daemon it should ignore the log level in config file.

Expected behavior:

If I run a command like teleport discovery bootstrap -c /etc/teleport.yaml and I get an error message, I expect to see a normal error message format instead of debug level format.

Example expected output:

$ teleport discovery bootstrap -c ~/code/dev/clusters/alpha/agent.yaml --manual
Reading configuration at "/Users/gavin/code/dev/clusters/alpha/agent.yaml"...
ERROR: discovery service type does not support "ec2x", supported resource types are: [ec2 eks rds rdsproxy redshift redshift-serverless elasticache memorydb opensearch docdb]

Current behavior:

If a teleport yaml config file has log level set to DEBUG, then the command that acts on the config file will also use DEBUG level, and error messages are formatted for debug mode:

---
version: v3
teleport:
  nodename: "mbp"
  log:
    severity: "DEBUG"

Example unexpected output:

$ teleport discovery bootstrap -c ~/code/dev/clusters/alpha/agent.yaml --manual
Reading configuration at "/Users/gavin/code/dev/clusters/alpha/agent.yaml"...

ERROR REPORT:
Original Error: *trace.BadParameterError discovery service type does not support "ec2x", supported resource types are: [ec2 eks rds rdsproxy redshift redshift-serverless elasticache memorydb opensearch docdb]
Stack Trace:
    github.com/gravitational/teleport/api/types/matchers_aws.go:116 github.com/gravitational/teleport/api/types.(*AWSMatcher).CheckAndSetDefaults
    github.com/gravitational/teleport/lib/config/configuration.go:1597 github.com/gravitational/teleport/lib/config.applyDiscoveryConfig
    github.com/gravitational/teleport/lib/config/configuration.go:664 github.com/gravitational/teleport/lib/config.ApplyFileConfig
    github.com/gravitational/teleport/lib/configurators/configuratorbuilder/builder.go:38 github.com/gravitational/teleport/lib/configurators/configuratorbuilder.BuildConfigurators
    github.com/gravitational/teleport/tool/teleport/common/configurator.go:144 github.com/gravitational/teleport/tool/teleport/common.onConfigureDiscoveryBootstrap
    github.com/gravitational/teleport/tool/teleport/common/teleport.go:685 github.com/gravitational/teleport/tool/teleport/common.Run
    github.com/gravitational/teleport/e/tool/teleport/main.go:19 main.main
    runtime/proc.go:271 runtime.main
    runtime/asm_arm64.s:1222 runtime.goexit
User Message: discovery service type does not support "ec2x", supported resource types are: [ec2 eks rds rdsproxy redshift redshift-serverless elasticache memorydb opensearch docdb]

Bug details:

webvictim commented 1 month ago

tctl does the same thing, which results in a few lines of surplus output with every command.