58 Commits
Author SHA1 Message Date
STeve (Xin) HuangandClaude Sonnet 4.5 a32c69b581 Fix TestConnectorSelection flakiness by refactoring connector selection (#63242)
* Fix TestConnectorSelection flakiness by refactoring connector selection

Fixes #62895

Extracted connector selection logic into a separate `selectConnector()`
method that can be tested without performing network connections. This
eliminates the flakiness caused by DNS resolution and context
cancellation races in the original test.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Use t.Context() inline instead of context.Background()

* Add parameter names to function type signatures for clarity

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-29 14:19:47 +00:00
STeve (Xin) Huang 537846890b [flaky] TestConnectorSelection (#62898) 2026-01-16 00:30:17 +00:00
Gavin Frazar 19aa43dbbb Refactor lib/srv/db/endpoints package (#61752)
The endpoints package couples database health checkers together.
This refactor is to register health checkers instead of endpoint resolvers,
to decouple the database health checkers from each other.
2025-11-25 18:02:24 +00:00
STeve (Xin) Huang b124f89a13 fix db_name enforcement docs and minor refactor in db egine checks (#58945) 2025-09-15 18:39:10 +00:00
Tiago Silva fbda3bcd35 feat: expand Session recording RBAC support (#58114)
This PR extends `session` rule RBAC to support access to the user that started the session roles and traits. It also extends ability to restrict and filter recordings for a user that doesn't have view access to the underlying resource via `can_view` function.

As part of a granular permission model, some customers want to restrict access to session recordings to users that belong to session creator's team or share the same/some roles with him.

This PR starts to store the user traits and roles when the session end event is emitted. These values are static over time and won't change even if the same user receives different roles or traits in the future.

It also reconstructs the resource based on session.end's labels, name and hostname. These values are also static and won't change over time. The resource is used to evaluate the function `can_view` result - this function evaluates if the user requesting the session recording has access to  the underlying resource.

Base role:

```yaml
kind: role
metadata:
  name: your-role-name
spec:
  allow:
    rules:
    - resources:
      - session
      verbs:
      - list
      - create
      - read
      where: your_condition_here
version: v7
```

`where: contains(session.participants, user.metadata.name)`

`where: contains(user.spec.traits["group"], "prod")`

`where: contains_any(user.spec.traits["team"], session.user_traits["team"])`

`where: contains_all(user.spec.traits["team"], session.user_traits["team"])`

`where: contains(user.spec.traits["team"], session.server_labels["team"])`

`where: contains(user.spec.traits["team"], session.kubernetes_labels["team"])`

`where: contains(user.spec.traits["team"], session.desktop_labels["team"])`

`where: contains(user.spec.traits["team"], session.db_labels["team"])`

`where: can_view() && contains(user.spec.traits["team"], "admin")`

Fixes #35616
Fixes #13482
Fixes #23039
2025-08-29 19:17:50 +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
Zac Bergquist 07e2fec1b2 Apply more modernize fixes (#55975)
- lib/srv
- lib/limiter
- lib/multiplexer
- lib/usagereporter
2025-06-22 10:54:09 +00:00
rosstimothy 67e5df8d00 Refactor auth.Middleware to reduce dependencies on lib/auth (#55577)
* Refactor auth.Middleware to reduce dependencies on lib/auth

The base functionality of auth.Middleware has been moved to
authz.Middleware to allow decoupling lib/auth from more packages.
Most of the contents of auth.Middleware were better suited for
authz and did not depend on any auth specifics. The auth.Middleware
was not removed entirely, it still has some usefulness to the
auth servers. It now relies on the authz.Middleware to perform
the base functionality.

* fix: add docs to Middleware
2025-06-16 13:24:40 +00:00
Krzysztof Skrzętnicki e86bdba0d0 Update microsoft/go-mssqldb/gravitational/go-mssqldb version (v1.8.1-teleport.2) (#54986)
* Switch go-mssqldb to tip of branch tener/teleport-patches-rebased (https://github.com/gravitational/go-mssqldb/pull/17)

* `go mod tidy`

* Add comment regarding crypto param

* Update `go-mssqldb` to the tip of https://github.com/gravitational/go-mssqldb/tree/teleport.2 (3d675ad5d264048147c06778aa91737818eb73f9)

* Move to nearly identical version, yet one following versioning guidelines: `v1.8.1+teleport.2`

* fix version
2025-05-23 15:51:07 +00:00
Krzysztof Skrzętnicki e9cc68805e Refactor kinit handling (PKINIT) (#54961)
* Refactor `kinit` handling

* Parse result is machine dependent; modify the test to use more flexible check.
2025-05-22 10:48:11 +00:00
Krzysztof Skrzętnicki 89f35ab2ff Add stack trace information around several recover() calls (#54881)
* Add stack trace information around several recover() calls

* downgrade panic logs to warnings
2025-05-16 17:20:40 +00:00
Krzysztof Skrzętnicki 0b5ce57902 Add SID support for PKINIT (#54719)
* Add SID support for PKINIT

* lint fix: snake case

* fix license

* update terraform

* `make derive`

* revert ignoring invalid dbs

* Bubble up SID lookup error in case auth fails

* expand warning message

* use `ParseCertificatePEM` from `tlsutils`

* add the domain and service account to logger
2025-05-16 07:21:31 +00:00
Gavin Frazar 99023fa993 Add database endpoint resolvers (#54618)
* Cassandra
* ClickHoust native and HTTP
* GCP Spanner
* SQLServer
2025-05-09 18:49:05 +00:00
rosstimothy 52816e8427 Bump golangci-lint to v2 (#54410)
* Bump golangci-lint to v2

* fix lints

* update e

* fix: delete removed cli option
2025-05-07 22:14:51 +00:00
Krzysztof Skrzętnicki bb9140f1ae Decouple GetKerberosClient() from DB session context (#52179) 2025-02-14 17:13:54 +00:00
Krzysztof Skrzętnicki d8fe3a6d8f Extract Kerberos functionality from SQL Server engine (#51352)
* Extract Kerberos functionality from SQL Server engine

* fix typo, add missing trace.Wrap()
2025-02-12 11:11:16 +00:00
rosstimothy af2db96d59 Convert lib/srv/db to use slog (#50116) 2024-12-16 20:25:51 +00:00
Krzysztof SkrzętnickiandSTeve Huang 18fe621bab convert db lib to use slog, part 2 (#43849)
* Switch Engine, EngineConfig and SessionContext to slog.

* Apply suggestions from code review

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>

* fix some lint issues, restore trace logs,

* fix tests

* fix some more lint issues

---------

Co-authored-by: STeve (Xin) Huang <xin.huang@goteleport.com>
2024-07-04 15:22:30 +00:00
Forrest 1742c46887 readonly shared cluster configs (#43422) 2024-07-02 17:23:13 +00:00
STeve (Xin) Huang a9d02f6122 convert db lib to use slog, part 1 (#43382)
* convert db lib to use slog, part 1

* fix typo

* fix build and add deprecate

* fix lint
2024-07-02 15:35:18 +00:00
Krzysztof Skrzętnicki 18b6b7f11a Database Access: decouple Auth from Session (#43344)
* Database Access: decouple Auth from Session, add SessionAuth wrapper, share CloudClients instance, update tests.

* Drop `SessionAuth` interface, shift usages over to updated `Auth` interface

* Drop unused params
2024-06-26 06:03:14 +00:00
rosstimothy 1aec5414f1 Replace constants from trace with equivalents defined in teleport (#39307)
* Remove logging from circuit breaker

The logging is never output, and if it was would be very verbose.
Instead of dropping the level down to trace the logger is removed
entirely.

* Add constants from trace library

The logging functionality in trace is being removed in an upcoming
release. To prepare the logging component keys are copied from trace
into teleport.

* Convert trace.ComponentFields to teleport.ComponentFields

* Replace trace.Component with teleport.ComponentKey

* Replace trace logging constants
2024-03-14 13:04:29 +00:00
Gavin Frazar 5c568bbe07 split database CA into server/client CAs (#35949)
* split database CA into server/client CAs

* update migration logging
    * include auth component in migrations
    * debug log when skipping db client ca migration
* update tctl auth sign for cockroachdb
* update tctl auth sign for oracle
* set ExtKeyUsage for DB certs
    * clientAuth for DB Client CA
    * serverAuth for DB Server CA
* inject filter for pre-v14.3.1 clients
* inject a filter instead of dropping events in grpcserver
* add DatabaseClientCA type

* debug log when skipping filter injection

* update CA filter injection version check func name and doc
2024-01-14 23:53:24 +00:00
Tim Buckley f7e97d0c3c Add bot field to certificates and various usage events (#35881)
* Add bot field to certificates and various usage events

This adds a new certificate extension field, `teleport-bot`, to
certificates issued to Machine ID bot users that can definitively
identify certificates as having been issued to a bot user.

Additionally, this uses the new `Bot` identity flag to mark certain
usage events as originating from bot users. As such, it includes a
protobuf update from Cloud [1], which pulled in some small additional
(mostly comment) changes.

[1] https://github.com/gravitational/cloud/pull/7060

* Small bot flag plumbing fixes

* Convert bot flag to BotName and UserKind enum

This makes a few changes to the bot tagging approach:
* The bot name is embedded in the cert rather than just true/false
* UserKind is included in events rather than just a bot flag, to
  allow for an unspecified value for older client nodes.

* Add a quick unit test for bot cert extensions

* Fix outdated grpc

* Include bot flag on initial certs

* Log a warning and override user kind for usage records if they differ

* Fix several unit tests; add a bot metadata test case

* Fix unit tests with UserKind zero value

* Rename SSH cert extension to use standard format

Renames the `teleport-bot` extension to `bot-name@goteleport.com`,
to better follow SSH cert extension naming conventions.

* Attempt to improve unspecified userkind aggregating logic
2024-01-04 23:07:08 +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 d5a796c056 Enable testify lint (#34222)
Updates our golangci-lint configuration to enable testifylint and
fixes all issues found.

Bump e ref to include gravitational/teleport.e#2567
2023-11-06 20:38:38 +00:00
Gabriel Corado 86358c14e4 Support auditing chunked SQL Server packets (#29228)
* feat(sqlserver): parse chunked packets

* chore(sqlserver): fix typo

* fix(sqlserver): assert final packet on flag bit

* refactor(sqlserver): return chunks data using Bytes()

* chore(sqlserver): update comparision logic

* chore(sqlserver): typo
2023-08-09 03:18:52 +00:00
Krzysztof Skrzętnicki 32ccd98af0 Add metrics for database service (#28150)
* Add DB metrics

* Address PR feedback.

- rename functions to better indicate their intent
- drop unused clock field
- cache labels
- add godoc

* Refactoring to return concrete types instead of interfaces.
2023-08-07 08:25:40 +00:00
Mike Jensen b90e362e7b Fuzz Test Improvements (#29918)
* Added Fuzz Seeds for services/fuzz_test.go

* Fuzzing improvements for `lib/srv/db` fuzzing

This ensures that all fuzzing under `lib/srv/db` has the following:
* Good seeds that provide basic levels of coverage
* Enabled in OSS-Fuzz

* Fuzzing improvements for `lib/sshutils`

This improves the fuzzing in `lib/sshutils/sftp/parse_test.go` and `lib/sshutils/x11/display_test.go`.
Seeds were added and additional local fuzzing was done.  In addition these functions are now enabled in `oss-fuzz`.
2023-08-02 18:55:55 +00:00
Marek Smoliński d4805cc428 Extend DatabaseSessionStart posthog event (#28931) 2023-07-14 07:15:02 +00:00
Gavin Frazar 2496e37124 update database and kube name validation (#28841)
* update database name validation

* move name validation into DatabaseV3 CheckAndSetDefaults
* replace use of DNS1305 name validation
  * remove 63 char length restriction
  * remove lowercase restriction

* fix failing tests

* update more tests

* update CHANGELOG.md
* explain breaking change to database discovery name validation
2023-07-12 21:24:25 +00:00
Andrew LeFevre d4b3afe9a1 split recording session events and emitting audit events (#27873)
* split recording session events and emitting audit events

This is a refactor of how audit events and session events are handled.
Previously, all events were emitted using the same interface,
api/types/events.Emitter. This lead to event-related code getting to be
very confusing, as it was often unclear whether a given event was being
recorded as a session event and emitted as an audit event, or only one
of the two. Naturally, a few bugs arose due to this.

To simplify event handling, a separate interface for recording session
events has been created. A api/types/events.Recorder should now only be
used to record session events, and an Emitter should now only be used to
emit audit events. Instead of using a confusing TeeWriter that would
transparently (and confusingly, given its name) hold a few event types
that only belonged in session recordings, callers can now explicitly
record and/or emit an event when necessary.

* ensure e build won't break
2023-07-11 19:53:33 +00:00
Gabriel Corado a80497d287 tests(sqlserver): fix test variable length packet fixture (#25658) 2023-05-15 23:37:23 +00:00
Gavin Frazar a190a2e0fa support cross-account AWS db access (#23680)
* AWS cross account database access

* update aws cloud clients, engines, metadata
* base64 encode semaphor
* update tests for refactored cloud clients

* use TTL cache for AWS sessions
2023-04-08 00:01:56 +00:00
Gabriel Corado 428701b8ca Support SQL Server through RDS Proxy (#23600)
* feat(db): add support for sqlserver rds proxy

* chore(gomod): go mod tidy

* chore(gomod): go mod tidy

* chore(sqlserver): move params keys to constants
2023-04-04 15:15:14 +00:00
Gabriel Corado a4785855c5 Set CRL LDAP path based on certificate authority type (#23814)
* refactor(windows): use CA type to define CRL path

* chore(windows): update updateCRL comment

* chore(windows): fix imports
2023-03-31 15:20:55 +00:00
Gabriel Corado f3dc81b14a SQL Server PKINIT authentication update (#22792)
* feat: fix and improve kinit sqlserver

* test(kinit): use a temp dir for writing ccache files

* chore(services): update validation error message

* chore(kinit): improve field description

* refactor(kinit): use CA from certificate generation

* refactor(kinit): remove unused function

* chore(kinit): remove leftover file
2023-03-28 15:04:29 +00:00
Steven Martin b4e1f39742 Fix DB Query always return success false in audit log (#23270)
* Initialize db query to status of success true

* Init event status as success true
2023-03-18 14:01:30 +00:00
rosstimothy 95d6d0fee1 Migrate GetCertAuthority to gRPC (#22624)
The HTTP client created by `auth.NewClient` has an idle timeout of
30s and each instance periodically gets cert authorities in
`TeleportProcess.syncRotationStateCycle`. If there has been no
activity when the ticker expires then the request will result in a
brand new connection to Auth to be established. This can cause a
spikes in open file descriptors on the Proxy when there are a large
number of instances connected via a tunnel.

To prevent periodic dialing when retrieving cert authorities the
endpoint has been migrated to the new Trust gRPC service. For now
only the get endpoint has been migrated but the rest of the CRUD
operations for cert authorities should be migrated from the HTTP
api to the gRPC service as well.
2023-03-10 14:32:34 +00:00
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +00:00
Gabriel Corado 22dc3dfb2e Update SQL Server library (#21065)
* refactor(sqlserver): change to microsoft fork

* chore(gomod): update mssqldb dep

* test(sqlserver): add server on parsing PLP RPC packets

* fix(db): change mssql import

* chore(gomod): update go-mssqldb reference

* test(protocol): use fuzz arguments

* chore: code review suggestions

* test(sqlserver): add missing protocols attribute
2023-02-10 11:39:11 +00:00
STeve (Xin) Huang 704a514742 AWS IAM role matching for database users (#20610)
* Add database user matching logic for databases require AWS IAM role

* Fix UT

* fix lint/typo

* fix typo in error message

* reduce bool return
2023-02-03 18:33:56 +00:00
Alan Parra 11d58e25c7 Refactor AccessMFAParams and MFAParams to allow additional data (#20300)
Refactor `services.AccessMFAParams` and the accompanying `MFAParams` methods so
they may be extended to carry additional data (eg, information required to
perform device trust checks).

This PR refactors existing code without adding any new functionality, so it may
be backported to older branches to alleviate eventual conflicts. Follow up
changes will take advantage of it to add support for device trust.

Related to gravitational/teleport.e#514.
2023-01-17 20:02:38 +00:00
Isaiah Becker-Mayer 9a06ca404c Windows Certificate SID Mapping (#19340) 2022-12-22 21:54:50 +00:00
STeve (Xin) Huang 6c858c09ee Register database engines directly from db lib (#19279) 2022-12-18 05:59:47 +00:00
Christopher Cooper 9c2192ebb6 Prepare sql server kinit authorization (#18299) 2022-12-06 22:55:20 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Gabriel Corado 65c022893d Add Azure AD user managed identity authentication for SQL server (#17142) 2022-10-21 15:06:51 +00:00
Brian Joerger 2654add770 RequireMFAType (#16034)
Replace role/authPref RequireSessionMFA (bool) with RequireMFAType
(string).

  - Add new RequireMFAType constant values with custom boolean marshalling.

  - Add RequireMFAType to role and auth preference and deprecate
RequireSessionMFA.

  - Add session-mfa override login when hardware_key_touch is enforced.

  - Add protobuf enum for RequireMFAType.

  - Add support for proto enums in protoc-gen-crd and update Kubernetes
Operator manifests.
2022-09-22 20:30:32 +00:00
Trent Clarke 9514a313c3 Break DB integration tests out into their own package (#16133)
Making all of our integration tests run in entirely parallel requires
a large engineering effort to enforce test isolation and remove all race
conditions between tests.

A lower-effort alternative may be to split apart the various test suites
into their own Go packages, and test those packages in parallel, even if
the tests inside are still executed serially. Auditing the test suites
for races on system-level resources (e.g. files, ports) is much easier
than chasing down every p[ossible race in the testing system.

This patch acts as a trial run, breaking a fairly well-defined and
self-contained test suite out into its own package. Note that the goal of
this change is not necessarily to shave minutes off the build (although
that would be nice), but to act as an illustration of how other, less
well-formed test suites might be broken apart.

See-Also: #12421
See-Also: #14408
2022-09-07 11:04:35 +10:00