Commit Graph
113 Commits
Author SHA1 Message Date
rosstimothy 88d82cf476 Configure kingpin to allow DCE (#65897)
* Update kingpin

* Convert CLI formatting to use kingpin UsageRenderers

Avoiding the legacy kingpin text/templates allows for DCE to be used
by the linker. The existing formatting has been matched with a
pure Go UsageRenderer.
2026-04-22 14:57:55 +00:00
Adam Pickering 0ea6a8f6a8 Improve --help output for tsh, tctl, tbot, teleport-update and teleport (#64122)
* Write CLI --help text to stdout instead of stderr

* Display only one level of subcommands in help text

* Prevent a hidden command from increasing indentation level

* Add entry to changelog explaining updates to --help output
2026-04-14 19:39:34 +00:00
Brian Joerger 74ca5bbfdd Remove extra new line in client error messages (#65206)
* Fix formatErrorWriter adding duplicate new lines.

* Address comments.

* Address claude comment.
2026-04-07 19:50:30 +00:00
STeve (Xin) Huang dee809f091 Fix an issue tbot start/configure command usage not aligned (#65161) 2026-04-01 13:28:22 +00:00
Andrew LeFevreandjoerger 6fb284b786 expose logs of Teleport child processes (#61297)
* expose logs of Teleport child processes

Configures Teleport child proceses to log with the exact same
configuration as the parent process. Logs from child processes
previously were essentially discarded.

* Fix issues around os_log; Fix log spam from child process.

* Address comments; Fix lint.

* * Only write remote command failure errors to client tty

* Don't try to write errors to unserviced os.Stderr/Stdout of child process

* Don't connect networking stderr to parent process, just use logger

* Don't log client-responsible shell errors, e.g. shell interrupt

* Mention running teleport as root for common subprocess permission errors.

* Pass io.Discard pipe to child process if a log writer is not available.

* Fix tests with nil log writer.

* Add default child logger for tests.

* Fix lint.

* default to discard writer for tests.

* Write reexec errors to os.Stdout for parent process to digest.

* Address comments.

* Clean up child pipe copy logic.

* Cleanup log config inheritance.

* Address comments.

* Revert whitespace change.

* Fix typo.

* Fix merge conflict.

---------

Co-authored-by: joerger <bjoerger@goteleport.com>
2025-12-09 20:27:31 +00:00
Brian Joerger 9ab4a82b91 Use FlagsToTwoColumns format option in order to get env var help automatically. (#61344) 2025-11-13 20:28:16 +00:00
Chris ThachandZac Bergquist e16a7ad8ef Add debug logging to tsh when there is a SAN mismatch connecting to Auth via Proxy (#61059)
* Add debug logging to `tsh login` when there is a DNS SAN mismatch

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Fix formatting so it is consistent

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Filter for only proxy env vars. Improve message.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Add unit tests for formatCertError.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Revert copyright update

* Pretty print proxy env and certificate

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Print NotBefore

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Add case where there is a network intermediary

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Revert general HostnameError case. Add message for just the case of connecting to Auth.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Apply suggestions from code review

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Fix missing deref. Only build in the special case.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Remove internal cluster domain and move hostname to debug info.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

* Add vertical space.

Signed-off-by: Chris Thach <chris.thach@goteleport.com>

---------

Signed-off-by: Chris Thach <chris.thach@goteleport.com>
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2025-11-10 18:36:40 +00:00
Vadym Popov 71e84c6106 Fix printing empty usage and terminate CLI for parsing global flags (#57401)
* Fix printing empty usage and terminate CLI for parsing global flags

* Add test with check of both `--help` flag and `help` command that usage print is not empty and both identical.
Add godoc clarification

* Disable managed update check for version help command test
2025-08-01 16:34:12 +00:00
Vadym Popov 75b56b1c67 Client-tools managed updates version caching (#54563)
* Add profile integration to disable update and re-execution for specific cluster

* Complete integration for the tctl and tsh

* Add commands for tsh

* Fix linter warnings

* Add config file with version and disabling status

* Move check out from helper

* Fixed re-execution ignore if versions is identical

* Move logic out from client

* Remove helper package and profile integration

* Fix argument parsing by filtering

* Use same Darwin platform approach of package extraction for Linux
Add client tools cleanup for V1 directories

* Fix packaging unit test

* Add cleanup for last recently used tools

* Add migration from v1 for better support
Show error log message about failed update/re-execution instead of failing command execution in case if updated binary was broken, modified or not able to validate signature

* Add ignore the version check fail, add more debug information

* Check update for commands `tsh ssh`, `tsh proxy ssh`
Fixed creating `.tsh` subdirectory when TELEPORT_HOME is set
Fix `tsh --proxy` flag parsing

* Wraps client init function to check client tools managed update only when it requested for `tsh ssh` and `tsh proxy ssh`

* Move filesystem lock to configuration library
Configuration modification protected by lock, other process must wait until it is released

* Rename command to `tsh update`, `tsh update --clear`

* Add test for argument filtering

* Update RFD
Make max tools installed to be configurable and set to 3 by default

* Replace "automatic updates" to "managed updates"

* Updated comments to reflect the latest changes

* Fix migration for older versions with two packages

* CR changes

* Prevent failing tools execution if configuration file is corrupted

* Remove lock file as part of cleanup command

* Added context to arguments

* Use a separate Kingpin application for tctl, as is already done for tsh. Double parsing may cause issues since it is not stateless.
2025-07-18 04:31:35 +00:00
rosstimothy de734fb2b1 Complete logtest migration (#56864)
Updates e to include https://github.com/gravitational/teleport.e/pull/6906
so that utils.InitLoggerForTests and utils.NewSlogLoggerForTests
can be removed.

Updates https://github.com/gravitational/teleport/issues/51023.
2025-07-17 17:04:24 +00:00
rosstimothy 7541d6d7d0 Introduce logtest package (#56741)
Moves all test related logger initialization and creation to the
logtest package to reduce testing symbols in production code. The
existing helpers in lib/utils have been left in place until the
enterprise references can be converted.

Updates #51023.
2025-07-15 18:11:10 +00:00
Paul Gottschling f104ab66e4 Add a CLI reference generator (#54394)
* Add a CLI reference generator

See #3568

Add a function to update the kingpin usage template for a CLI
application and print a docs page. As a starting point, includes a
`docs` subcommand in `tsh` to call the function for that tool. By
generating CLI documentation, we can ensure that commmand, argument, and
flag usage information is consistent with the terminal help text for a
given CLI. We can also ensure that all changes to a CLI application are
reflected in the documentation.

As an alternative, we could edit `UpdateAppUsageTemplate` in `lib/utils`
to update the usage template to print an MDX page, e.g., using build
tags to print a docs template instead of the default usage template.
This approach would update all CLI tools at once and use a consistent
approach with minimal changes to each CLI tool. However, using a
separate function to take a `*kingpin.Application` and print a docs page
is more straightforward and explicit, even though it does require
editing each CLI tool to call the function.

One shortcoming of generating the CLI reference docs versus our current
manual approach is that it is non-trivial (and potentially impossible)
to use `kingpin`'s usage API to obtain the value types of the
subcommands, flags, and arguments registered against a
`*kingpin.Application`. We can use flag and argument descriptions and
default values to achieve the same purpose.

Another shortcoming is that `kingpin`'s usage API does not print usage
information for arguments, environment variable, etc. that a CLI looks
up directly from the OS, such as the `TELEPORT_CLUSTER` environment
variable for `tsh`.

* Respond to zmb3 and atburke feedback

**Separate docs generation code from production code.**

Add a separate implementation of `UpdateAppUsageTemplate` that requires
the `docs` build tag. Since all Go-based Teleport CLI tools call
`UpdateAppUsageTemplate`, the `docs` build of the function ensure that
the `help` command for Teleport CLI tools prints a docs page.

This change also adds a `cli-docs-tsh` make target to generate a docs
page for `tsh`.

**Escape pipes in `formatHelp`** to avoid breaking table cells.

* Respond to atburke feedback

- Make the main help description more visible. Assume that the main help
  description is not necessarily a complete sentence, adding the text to
  the end of the introductory sentence using a colon.

- Add a make rule for running CLI docs generator tests. Use the `-run`
  flag since the tests are in a package we already run tests for in
  another make rule.

* Respond to zmb3 feedback

- Use Fprintf instead of Buffer.WriteString.
- Use the zero value of bytes.Buffer instead of NewBuffer.
- Rename `.*ToColumns` functions to `.*ToRows` for clarity.
- Use slices.ContainsFunc in anyVisibleFlags.
- Use slices.ContainsFunc in anyEnvVarsForCmd.
- Clean up argsToRows.
- Minor cleanup in TestUpdateAppUsageTemplate.
- Clean up sortCommandsByName (no need to implement sort.Interface).
- Read the docs usage template from disk in UpdateAppUsageTemplate. For
  this to work, add the function updateAppUsageTemplate, which takes an
  io.Reader, and use separate file paths to pass the io.Reader to the
  function in the tests and in UpdateAppUsageTemplate.
- Inline formatFlagForTable and remove unnecessary branching.
- Add an ADDTAGS environment variable to the `test-go-unit` make
  target so it's possible to pass arbitrary build tags, e.g., "docs".
2025-06-27 17:33:14 +00:00
Zac Bergquist ff374ff7fd Modernize lib/auth and lib/utils (#55976) 2025-06-22 10:53:52 +00:00
Gabriel Corado 639992c6c5 Initial PostgreSQL MCP support (#54431)
* feat(mcp): initial postgres mcp

* test(postgres): fix missing mock function

* fix(gomod): go mod tidy all

* refactor: code review suggestions

* fix(tsh): mcp init missing logger

* chore(tsh): missing other route to database field

* refactor: use in-memory net listener

* test(tsh): add mcp db command test

* chore: fix license

* refactor(tsh): move logger init

* test(mcp): sort slices to avoid flakiness

* chore: fix lint

* test(mcp): sort the resources before assertion

* fix(mcp): update error handler for better message

* refactor: code review suggestions

* feat: add external error retriever for more accurate error messages

* refactor: use the same logger init for mcp purposes

* refactor: code review suggestions

* refactor(tsh): rename command to `tsh mcp db start`

* refactor(mcp): protect database resources with rw mutex

* chore: update server godocs

* chore: go mod tidy

* refactor: update command to take list of databases

* chore(mcp): license

* chore(tsh): remove unused function

* refactor: code review suggestions

* refactor(tsh): validate duplicated databases in MCP configuration

* refactor(tsh): rename files to mcp_db

* feat(mcp): add cluster name to the database resource
2025-06-04 21:17:22 +00:00
rosstimothy 280e1f5f6f Remove code marked for deletion (#54957) 2025-05-20 16:07:20 +00:00
Rafał Cieślak 5ebe5dd836 Make VNet daemon send logs to os_log (#54237)
* Support os_log in lib/utils.InitLogger

* Refactor code for getting bundle identifier

* Rename DaemonLabel to VNEDaemonLabel

Rename the Obj-C function so that we can add a C function called
DaemonLabel later. The C function will be called from Go code.

* Use os_log in VNet daemon

* Adjust logging preferences of VNet daemon

* Clean up logger components in lib/vnet
2025-05-06 11:22:12 +00:00
STeve (Xin) Huang 7b160600b8 Fix misaligned command usage for 'help' commands of Teleport binaries (#51660)
* Fix an issue command help is not aligned for help command

* align when unknown command/subcommand
2025-01-31 15:35:31 +00:00
rosstimothy 63537e3da5 Prevent race creating test logger (#51469)
Avoids parsing flags of the go test command more than
once to prevent the following race:

```
 ==================
WARNING: DATA RACE
Write at 0x00c0006c401f by goroutine 57:
  flag.(*boolValue).Set()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/flag/flag.go:138 +0x26b
  flag.(*FlagSet).parseOne()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/flag/flag.go:1124 +0x781
  flag.(*FlagSet).Parse()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/flag/flag.go:1157 +0xa4
  flag.Parse()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/flag/flag.go:1188 +0x8e
  github.com/gravitational/teleport/lib/utils.NewLoggerForTests.InitLoggerForTests.func1()
      /code/teleport/lib/utils/cli.go:164 +0x2b
  sync.(*Once).doSlow()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/sync/once.go:74 +0xf0
  sync.(*Once).Do()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/sync/once.go:65 +0x44
  github.com/gravitational/teleport/lib/utils.InitLoggerForTests()
      /code/teleport/lib/utils/cli.go:162 +0x2b
  github.com/gravitational/teleport/lib/utils.NewLoggerForTests()
      /code/teleport/lib/utils/cli.go:185 +0x18
  github.com/gravitational/teleport/lib/kube/proxy.TestGetKubeCreds()
      /code/teleport/lib/kube/proxy/auth_test.go:143 +0x497
  testing.tRunner()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1742 +0x44
Previous read at 0x00c0006c401f by goroutine 1156:
  testing.shouldFailFast()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2408 +0x12b
  testing.(*T).Run()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1710 +0xfd
  github.com/gravitational/teleport/lib/kube/proxy.Test_DynamicKubeCreds()
      /code/teleport/lib/kube/proxy/kube_creds_test.go:296 +0x26b4
  testing.tRunner()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1742 +0x44
Goroutine 57 (running) created at:
  testing.(*T).Run()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2161 +0x85
  testing.tRunner()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1689 +0x21e
  testing.runTests()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2027 +0xf17
  github.com/gravitational/teleport/lib/kube/proxy.TestMain()
      /code/teleport/lib/kube/proxy/forwarder_test.go:100 +0x30
  main.main()
      _testmain.go:129 +0x2d4
Goroutine 1156 (finished) created at:
  testing.(*T).Run()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2161 +0x85
  testing.tRunner()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:1689 +0x21e
  testing.runTests()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      /go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.11.linux-amd64/src/testing/testing.go:2027 +0xf17
  github.com/gravitational/teleport/lib/kube/proxy.TestMain()
      /code/teleport/lib/kube/proxy/forwarder_test.go:100 +0x30
  main.main()
      _testmain.go:129 +0x2d4
==================
```
2025-01-24 19:59:10 +00:00
Paul Gottschling 70d70a2d60 Fix outdated docs URLs (#50923)
- Web UI source
- README
- lib
- api

Do not touch docs URLs in test case names or test data where we don't
expect users to navigate to the URLs.
2025-01-16 18:17:35 +00:00
rosstimothy 883c53a53c Remove logrus dependency (#50930)
This is the _last_ step required to migrate from logrus to slog.
All components in the repository have been migrated to use slog
allowing the logrus formatter to be deleted.

The slog handler tests that validate the output have been updated
to assert the format directly instead of comparing it to the output
from the logrus formatter.
2025-01-10 16:58:56 +00:00
Mike Jensen d0a722d93b Replace UnixShellQuote with shsprintf.EscapeDefaultContext from github.com/google/safetext (#40046)
This change is a change in how we are handling the untrusted input.  Instead of adopting a strategy of quoting (which was incomplete), this instead escapes any special characters.

Although github.com/google/safetext is new, and without any current tags for us to reference, I believe it would be better to reference their implementation than to update the UnixShellQuote to handle the newly identified cases.
2024-03-29 21:49:07 +00:00
Mike Jensen b0992936b8 Quote user supplied inputs provided to scripts to avoid RCE (#39644)
* Quote user supplied inputs provided to scripts to avoid RCE

This change introduces the func `utils.UnixShellQuote` which will quote any inputs which could potentially allow execution or script escape.
This is utilized to ensure that scripts produced from a potential Phishing link could not contain code execution which may expose a user.

* awsAccessGraphOIDCSync: Ensure role parameter is quoted correctly

* join_tokens: Move shell quote to `getJoinScript` rather than where parameters are extracted

This will increase safety moving forward, but it requires a more conservative quoting strategy.
2024-03-26 14:47:19 +00:00
rosstimothy df76ec95cd Bump github.com/gravitational/trace from 1.3.1 to 1.4.0 (#39292)
* Bump github.com/gravitational/trace from 1.3.1 to 1.4.0

## Changelog
- Bump google.golang.org/grpc from 1.43.0 to 1.53.0 by @dependabot in #94
- Bump golang.org/x/net from 0.8.0 to 0.17.0 by @dependabot in #100
- Bump google.golang.org/grpc from 1.53.0 to 1.56.3 by @dependabot in #101
- Bump golang.org/x/crypto from 0.14.0 to 0.17.0 by @dependabot in #105

## Breaking Changes
- Remove logrus dependency by @rosstimothy in #107
- Remove references to UDP logrus hook from README by @rosstimothy in #108

Full Changelog: https://github.com/gravitational/trace/compare/v1.3.1...v1.4.0

* remove final references to removed trace functionality

* fix: formatter error handling
2024-03-15 19:51:53 +00:00
rosstimothy 7511eafd6c Stop populating the http reverse proxy ErrorLog (#36653)
When creating a reverse proxy the ErrorLog was being created
with the writer returned from logrus.WriterLevel. This writer
uses an io.Pipe and a goroutine to get any log messages written
from a standard log.Logger to our custom formated logrus.Entry.
The ErrorLog only ever omits output in a few very rare (hopefully)
error cases, which means we were creating an extra goroutine per
reverse proxy which in most cases would never be used to produce
any added output. Additionally, now that we are starting to support
log/slog, any output from a log.Logger will now be formatted via
our registered default slog handler. Meaning that we can still
get the benefits of producing output from the ErrorLog in the
desired format without the penalty incurred by using logrus.WriterLevel.

Partially addresses #36541.
2024-01-13 14:42:53 +00:00
rosstimothy b4df3778a1 Update slog handlers to support configured extra_fields (#36372)
* Update slog handlers to support configured extra_fields

In addition to configuring output format users can configure the
fields which are included in log messages. Prior to this our slog
handlers didn't support this feature and always output the default
fields. Now, both the slog and logrus output is identical no matter
the extra_fields configuration as verified by TestExtraFields. It
was also found that due to the way the logurs json formatter was
configuring itself in CheckAndSetDefaults the timestamp was always
included in the final output even if it was not included in the
configured extra_fields.

* fix: update component comment
2024-01-08 16:00:10 +00:00
fheinecke b178b8b732 Updated Teleport codebase to AGPL3 license (#35259)
Signed-off-by: Fred Heinecke <fred.heinecke@goteleport.com>
2023-12-01 17:48:14 +00:00
rosstimothy 2809bbad98 Initialize slog logger alongside logrus logger (#34457)
In all places that a logrus logger is being initialized an equivalent
slog logger is now being intialized as well. The TeleportProcess
was also updated to have a slog.Logger which is created with the
same fields that its logrus equivalent has. This does not convert
any logging to actually use slog yet, but does pave the way for
conversions to start.
2023-11-28 20:39:14 +00:00
Noah Stride fd80ffa23f Improve utils.FatalError error formatting (#34417)
* Use existing error formatting logic from `trace`

* Remove unnecessary layer of indirection

* Add test for UserMessageFromError

* Fix imports
2023-11-20 11:41:21 +00:00
rosstimothy d232e5054d Add slog handlers to match existing logrus formatters (#34072)
Implements two new slog.Handlers that attempt to output text in the
same format as existing logrus.TextFormatter implementations. The
most notable differences are that the order of fields in the json
output does NOT match the logrus order and the additional items
in text output are NOT sorted alphabetically like they are in logrus.

Tests added validate the output roughly matches between the two
loggers given the differences noted above. A benchmark test is also
included to demonstrate the improvements slog offers over logrus.
2023-11-09 15:29:25 +00:00
Tiago Silva ebecb59468 Replace graviational/oxy.Forwarder with httputil.ReverseProxy (#27761)
This PR replaces the usage of `gravitational/oxy.Forwarder` in our codebase with `httputil.ReverseProxy`.

`httputil.ReverseProxy` is part of Go's standard library and thus it is
 maintained by the Go team. Converting everything to use the std lib
 allows us to drop our `oxy` fork.

 There are some operational changes between the two versions:

 1. `httputil.ReverseProxy` handles WebSockets upgrades internally and
    reuses the `Transport` provided for the initial request. Thus, it does
    not require any special dialer or rewriter mechanisms for WebSockets only.

 2. `httputil.ReverseProxy` calls the `ErrorHandler` with the request
       after it was rewritten and after roundtrip was called. This was a
       problem because our `web.transport` deletes Teleport associated
       cookies and when the request failed, the request received by the
       `ErrorHandler` missed the cookies to generate a new session. This was
       fixed by cloning the request at `web.transport` round tripper.

 3. `httputil.ReverseProxy` uses std's `log.Logger`. `logrus` exposes a
       method `Writer` that allows it to be used with standard lib logger.

The API is similar to what our `oxy` fork has available.

Fixes #27412
2023-06-29 13:50:07 +00:00
Grzegorz Zdunek 9d05287cc9 Update kingpin & allow autocompletion (#26238)
* Update kingpin version

* Convert `defaultUsageTemplate` to "text/template"

* Add // replaced

* Sort deps

* Change kingpin v2.3.1 to v2.3.2

* Add missing indirect dep

* Update go.sum

* Delete kingpin_deleteme.go
2023-05-19 07:10:53 +00:00
Steven Martin eaa651ca38 check for correct kube and ssh listen address in starting message (#25780)
* check for correct kube listen address in starting message

* fix for ssh proxy and usage of String function

* remove consolef output and simplify output

* remove consolef output

* Remove consolef from services for startup

* fix imports

* remove all consolef usage
2023-05-09 13:52:55 +00:00
rosstimothy 5f99927888 Add ability to enable trace logging level (#25800)
Closes #25737
2023-05-08 17:40:16 +00:00
Edward Dowling d29a9c62c6 Change init logger to include timestamp for debug level (#21732)
* Change init logger to include timestamp for debug level

* Disable timestamps for tsh in dev mode
2023-02-17 16:48:18 +00:00
Gavin Frazar a761523609 Allow horizontal and vertical tabs in cli output (#20066)
* Allow horizontal and vertical tabs in cli output
2023-01-13 05:42:48 +00:00
Edoardo Spadolini 14640c80de Fix CertificateInvalidError in formatCertError (#20049) 2023-01-10 19:36:04 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Edward Dowling d0a602deb6 Add initial OSS part of license expiry code. (#16753)
In “tsh login” show only alerts with on-login label.
    In “tsh status” show only alerts with “high” severity. Which license warning should match.
    In all “tctl” commands show only alerts with “high” severity.
2022-10-13 14:59:47 +00:00
Alan Parra a75fcc21d8 Update golangci-lint to 1.49.0 (#16507)
Update metalinter, fix a few lint warnings and replace deprecated linters.

`deadcode`, `structcheck` and `varcheck` are abandoned and now replaced by [`unused`][1].

Since 1.19, `go fmt` reformats godocs according to https://go.dev/doc/comment. I've done a bulk-reformatting of the codebase to keep the linter happy. Backporting is mostly harmless (the exception being `lib/services/role_test.go`, that for some reason breaks the _old_ linter using the new format).

[1]: https://golangci-lint.run/usage/linters/

* Bump golangci-lint version
* Replace abandoned linters
* Fix bodyclose on lib/auth/github.com
* Fix bodyclose on lib/kube/proxy/streamproto/proto_test.go
* Fix bodyclose on lib/srv/alpnproxy/proxy_test.go
* Fix bodyclose on lib/web/conn_upgrade_test.go
* Silence staticcheck on lib/kube/proxy/forwarder_test.go
* Silence staticcheck on lib/utils/certs_test.go
* Address BuildNameToCertificate deprecation warnings
* Run `go fmt ./...`
* Run `go fmt ./...` on api/
* Ignore formatting in role_test.go
* Remove redundant initializers in lib/srv/uacc/
* Update e/
2022-09-19 22:38:59 +00:00
Noah Stride 3a853cdfd0 Self signed certificates tsh TTL fixes (#14985)
* start work on self signed tsh fixes

* fix go sum

* Adjust error formatting

* Complete less explicit error checks last

* Adjust PR feedback

* Further PR review

* Support darwin and linux certificate errors
2022-07-28 20:43:40 +00:00
Krzysztof SkrzętnickiandMarek Smoliński 0e9d621b46 Alias support for tsh (#13305)
* aliases are read from global and user configs.
* we prevent Kingpin from terminating `tsh`; we handle parsing errors better.
* added support for `TELEPORT_DEBUG` env variable, changed how logging is initialized.
* debugging aliases is possible via `TELEPORT_DEBUG=1` env variable; `--debug` is ineffective as it comes into play too late.
* if alias definition calls `tsh`, we call the `Run()` function directly instead of spawning fresh `tsh`; this improves the UX.
* alias loops are detected and a proper error is shown.
* all flags are made repeatable; if only one value for a given flag is possible, the last instance of the flag will be effective. 

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-07-27 11:14:55 +00:00
Edoardo Spadolini c2c4e4a630 Use JSON logging in tests (#13977)
* Use JSON logging in tests

* log to logrus
2022-07-01 11:09:39 +00:00
Lisa Kim 6116ccf37a Improve error message for resource predicate query (#12262) 2022-04-29 21:29:27 +00:00
STeve (Xin) Huang 3d7de736e3 Improve cli usage when command name is long (#10981) 2022-03-23 19:08:42 +00:00
Zac Bergquist 55cbd0ac97 Remove use of deprecated ioutil package (#11296)
* Remove use of deprecated ioutil package
* Add lint rule to check for ioutil imports
2022-03-21 18:00:34 +00:00
32e48017d3 Implement tbot init subcommand and ACL management (#10289)
* Add certificate renewal bot

This adds a new `tbot` tool to continuously renew a set of
certificates after registering with a Teleport cluster using a
similar process to standard node joining.

This makes some modifications to user certificate generation to allow
for certificates that can be renewed beyond their original TTL, and
exposes new gRPC endpoints:
 * `CreateBotJoinToken` creates a join token for a bot user
 * `GenerateInitialRenewableUserCerts` exchanges a token for a set of
   certificates with a new `renewable` flag set

A new `tctl` command, `tctl bots add`, creates a bot user and calls
`CreateBotJoinToken` to issue a token. A bot instance can then be
started using a provided command.

* Cert bot refactoring pass

* Use role requests to split renewable certs from end-user certs
* Add bot configuration file
* Use `teleport.dev/bot` label
* Remove `impersonator` flag on initial bot certs
* Remove unnecessary `renew` package
* Misc other cleanup

* Do not pass through `renewable` flag when role requests are set

This adds additional restrictions on when a certificate's `renewable`
flag is carried over to a new certificate. In particular, it now also
denies the flag when either role requests are present, or the
`disallowReissue` flag has been previously set.

In practice `disallow-reissue` would have prevented any undesired
behavior but this improves consistency and resolves a TODO.

* Various tbot UX improvements; render SSH config

* Fully flesh out config template rendering
* Fix rendering for SSH configuration templates
* Added `String()` impls for destination types
* Improve certificate renewal logging; show more detail
* Properly fall back to default (all) roles
* Add mode hints for files
* Add/update copyright headers

* Add stubs for tbot init and watch commands

* Add gRPC endpoints for managing bots

* Add `CreateBot`, `DeleteBot`, and `GetBotUsers` gRPC endpoints
* Replace `tctl bot (add|rm|ls)` implementations with gRPC calls
* Define a few new constants, `DefaultBotJoinTTL`, `BotLabel`,
  `BotGenerationLabel`

* Fix outdated destination flag in example tbot command

* Bugfix pass for demo

* Fixed a few nil pointer derefs when using config from CLI args
* Properly create destination if `--destination-dir` flag is used
* Remove improper default on CLI flag
* `DestinationConfig` is now a list of pointers

* Address first wave of review feedback

Fixes the majority of smaller issues caught by reviewers, thanks all!

* Add doc comments for bot.go functions

* Return the token TTL from CreateBot

* Split initial user cert issuance from `generateUserCerts()`

Issuing initial renewable certificate ended up requiring a lot of
hacks to skip checks that prevented anonymous bots from getting
certs even though we'd verified their identity elsewhere (via token).

This reverts all those hacks and splits initial bot cert logic into a
dedicated `generateInitialRenewableUserCerts()` function which should
make the whole process much easier to follow.

* Set bot traits to silence log messages

* tbot log message consistency pass

* Implement `tbot init` subcommand

This adds a new CLI subcommand to initialize a tbot destination
directory by creating required files ahead of time and assigning
proper permissions (and ACLs, where possible).

* Resolve lints

* Add config tests

* Remove CreateBotJoinToken endpoint

Users should instead use the CreateBot/DeleteBot endpoints.

* Create a fresh private key for every impersonated identity renewal

* Hide `config` subcommand

* Rename bot label prefix to `teleport.internal/`

* Use types.NewRole() to create bot roles

* Clean up error handling in custom YAML unmarshallers

Also, add notes about the supported YAML shapes.

* Fetch proxy host via gRPC Ping() instead of GetProxies()

* Update lib/auth/bot.go

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Fix some review comments

* Add renewable certificate generation checks (#10098)

* Add renewable certificate generation checks

This adds a new validation check for renewable certificates that
maintains a renewal counter as both a certificate extension and a
user label. This counter is used to ensure only a single certificate
lineage can exist: for example, if a renewable certificate is stolen,
only one copy of the certificate can be renewed as the generation
counter will not match

When renewing a certificate, first the generation counter presented
by the user (via their TLS identity) is compared to a value stored
with the associated user (in a new `teleport.dev/bot-generation`
label field). If they aren't equal, the renewal attempt fails.
Otherwise, the generation counter is incremented by 1, stored to the
database using a `CompareAndSwap()` to ensure atomicity, and set on
the generated certificate for use in future renewals.

* Add unit tests for the generation counter

This adds new unit tests to exercise the generation counter checks.

Additionally, it fixes two other renewable cert tests that were
failing.

* Remove certRequestGeneration() function

* Emit audit event when cert generations don't match

* Fully implement `tctl bots lock`

* Show bot name in `tctl bots ls`

* Lock bots when a cert generation mismatch is found

* Make CompareFailed respones from validateGenerationLabel() more actionable

* Update lib/services/local/users.go

Co-authored-by: Nic Klaassen <nic@goteleport.com>

* Backend changes for tbot IoT and AWS joining (#10360)

* backend changes

* add token permission check

* pass ctx from caller

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* fix comment typo

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* use UserMetadata instead of Identity in RenewableCertificateGenerationMismatch event

* Client changes for tbot IoT joining (#10397)

* client changes

* delete replaced APIs

* delete unused tbot/auth.go

* add license header

* don't unecessarily fetch host CA

* log fixes

* s/tunnelling/tunneling/

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* auth server addresses may be proxies

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* comment typo fix

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* move *Server methods out of auth_with_roles.go (#10416)

Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>

Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Tim Buckley <tim@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>

* Address another batch of review feedback

* Addres another batch of review feedback

Add `Role.SetMetadata()`, simplify more `trace.WrapWithMessage()`
calls, clear some TODOs and lints, and address other misc feedback
items.

* Fix lint

* Add missing doc comments to SaveIdentity / LoadIdentity

* Remove pam tag from tbot build

* Update note about bot lock deletion

* Another pass of review feedback

Ensure all requestable roles exist when creating a bot, adjust the
default renewable cert TTL down to 1 hour, and check types during
`CompareAndSwapUser()`

* Remove ModeHint

* Rename Identity.Cert and Identity.XCert

* Add `symlinks` flag to tbot config

The optional symlinks flag for directory destinations allows users to
opt in / out of whichever symlink attack hardening mode is selected
by default.

* Add mostly-working secure implementation of botfs.Create/Write

This adds symlink mode selection (secure, try-secure, insecure) and
Linux `Create()`/`Write()` implementations to open files safely.

* Add configurable ACL modes and verify ACL support in tbot init

* Initialize destinations at startup and test before renewal

This initializes destinations at startup (to create directories if
not using `tbot init`) and tests them to ensure the bot can write
_before_ attempting to renew certificates; this should prevent most
accidental generation counter locks.

* Hide watch for now

* Issue a new identity if a token change is detected

* Warn if identity appears to be expired on startup

* Fully implement ACL Verify and Configure

 - Fully implements ACL support for Linux
 - Adds bot-side verification support to ensure ACLs are configured
   properly at runtime.
 - Gracefully falls back to no ACLs if the platform / filesystem
   doesn't support them
 - Clear up outstanding lints

* Make `tbot init` work without a config file

* Show init instructions in tctl bots add

Also:
 - Make --bot-user a flag in init (the tctl instructions were
   confusing otherwise)
 - Handle IsOwnedBy sanely on unsupported platforms
 - Add Bold colorizing support

* Clear some TODOs and rephrase tctl help

* Fix typo

* Fix token hash detection bug

* Actually read and write certs with symlink enforcement

Also, fix a config loading bug where CheckAndSetDefaults() wasn't
being called in all cases with CLI destinations.

* Add workaround for OpenSSH permissions check with ACLs

OpenSSH has an overly-paranoid permissions check that forces key
files to be exclusively owner-readable. Unfortunately, for POSIX
compatibility purposes, when ACLs are set, the ACL mask is set as
the group permissions. This effectively makes any ACL incompatible
with OpenSSH.

However, OpenSSH's check does have an escape hatch: it only applies
if the current user is the owner of the file. Therefore, this change
tweaks the `tbot init` flow to create files as root, owned by a
separate user (either `nobody` or even the bot user), with ACL
permissions granting both the bot and reader user access to the
certificates. This effectively bypasses OpenSSH's permissions check
and should preserve our security boundaries.

* Fix lints

* Fix an improper directory chmod to 0600 if ACL test fails

* First pass of tbot init unit tests

* Add symlink tests and fix bug with resolving the default owner

* Fix err misuse

* Fix an ACL error if the bot or reader user is the owner.

* Fix typo

* Fix missing error case in VerifyACL causing unreadable directories

* Address review feedback

- Rename ACLOn -> ACLRequired
- Simplify fs_linux.Read()
- Add missing fs_other.Read()
- Hoist renewal loop logic into its own function
- A few misc bugfixes

* Apply suggestions from code review

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>

* Address review feedback

- Only log syscall warning once
- Formatting and wording changes
- Improve error handling for `--clean`

* Fix lint error

* Fix imports in fs_other

* Fix possible nil pointer deref if storage is unset

* Use the bot user as default owner

This is more likely to be a safe owner choice than `nobody:nobody`.

* Apply suggestions from code review

Co-authored-by: Roman Tkachenko <roman@goteleport.com>

* Code review fixes

Co-authored-by: Zac Bergquist <zmb3@users.noreply.github.com>
Co-authored-by: Nic Klaassen <nic@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2022-03-10 06:09:01 +00:00
Jakub Nyckowski d616f7c31f Use teleport logger instead of gravitational/trace (#9738)
Fix incorrect caller in CLI and tests logs.
2022-01-11 23:04:47 +00:00
Tim Buckley 6cac803d36 Disable colorized error formatting on Windows (#8227)
* Disable colorized error formatting on Windows

This disables colorized error formatting on Windows. While recent
versions of Windows can render ANSI sequences, this functionality
needs to be explicitly enabled at runtime and then reset before
exiting. As it stands today, Windows clients see the raw ANSI
escapes, for example:

    ←[31mERROR: ←[0mfailed connecting to node example [...]

Due to compatibility concerns and `tsh`'s lack of a single exit
point, this just disables ANSI escapes when
`runtime.GOOS == "windows"`. The `ERROR:` text won't be colorized,
but also won't be surrounded by garbage characters.

* Add TODO note about why we disable colors on Windows.
2021-09-16 12:47:09 -07:00
Roman Tkachenko b4bc767a7c Buddy: https://github.com/gravitational/teleport/pull/6250 (#7165) 2021-06-03 11:37:10 -07:00
Lisa Kim 940c83c161 Make SSO login failure event emit more specific errors (#6108)
Purpose is to allow users with admin privilege that are able to view audit logs, 
to be able to debug SSO login failures from the UI as much as possible

* Return generic error message for sso console login failures to hide
  sensitive data from reaching client. Previously errors were returning as
  empty messages b/c of a trace bug.
* Remove emit event for createOIDCClient to allow outer caller to
  emit event and prevent double emits on error.
* Temporarily direct users to check teleports log on errors that come back 
  empty to tsh client.
2021-03-25 10:36:47 -07:00