Commit Graph
80 Commits
Author SHA1 Message Date
Gavin Frazar 76ef907743 update tests for auto user deactivation (#41497)
* expect deactivation audit event
2024-05-15 17:44:47 +00:00
Gavin Frazar 54d2e903d5 add RDS MariaDB e2e tests (#40066)
* add AWS RDS MariaDB e2e tests

* fix spurious teardown error logs

* if a role or user doesn't exist, that is not an error nor is it worth
  logging during auto user teardown.

* check for admin option

* add some extra secret fetching checkings

* only drop redshift user if the user exists
2024-04-08 21:46:17 +00:00
Krzysztof SkrzętnickiandLisa Kim 4867f02ff4 Add events for auto user provisioning (#39394)
* Add events for auto user provisioning

* Prettier

* Fix typo in event formatting

* Apply suggestions from code review

Co-authored-by: Lisa Kim <lisa@goteleport.com>

* Use shared base type for db session events

---------

Co-authored-by: Lisa Kim <lisa@goteleport.com>
2024-03-21 10:13:48 +00:00
Krzysztof Skrzętnicki 20503dfddd Implement label templates for db objects (#38630)
* Implement label templates for db objects

- Expose template parsing utilities.
- Interpolate label templates using `typical` library.
- Validate label templates as part of import rule validation.
- Refactor code to fix cyclic imports.

* Use database_service_name and object_kind for label key in preset

* revert changes to `lib/utils/parse/parse.go`

* Reimplement splitExpression locally for import rules

* Update RFD with recent changes and mark it as implemented

* rename files, add test coverage, use empty spec for validation

* Log template errors directly with debug logs, log total error count as info.

* Update logs
2024-03-18 09:37:20 +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
dependabot[bot]andAlan Parra e1bc8f070a Bump github.com/jackc/pgx/v4 from 4.18.1 to 4.18.2 (#39246)
* Bump github.com/jackc/pgx/v4 from 4.18.1 to 4.18.2

Bumps [github.com/jackc/pgx/v4](https://github.com/jackc/pgx) from 4.18.1 to 4.18.2.
- [Changelog](https://github.com/jackc/pgx/blob/v4.18.2/CHANGELOG.md)
- [Commits](https://github.com/jackc/pgx/compare/v4.18.1...v4.18.2)

---
updated-dependencies:
- dependency-name: github.com/jackc/pgx/v4
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix pgproto3 breaking changes

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
2024-03-12 18:11:26 +00:00
Krzysztof Skrzętnicki d6915c8dea Implement granular db permissions for Postgres (RFD 151) (#37808)
* Implement granular db permissions for Postgres (RFD 151)

* docs, whitespace

* Make sure query is closed, even in case of errors along the way

* fix imports
2024-03-04 19:28:22 +00:00
Krzysztof Skrzętnicki 2f069ed51b Fix corner case of NULL/empty arrays comparison for roles (#38429) 2024-02-22 13:53:25 +00:00
Krzysztof Skrzętnicki 469f3bd3ab Qualify oid colum fixing Postgres v16 incompatibility (#38428) 2024-02-22 11:53:24 +00:00
STeve (Xin) Huang 6684370580 Improve error message when auto-user provisioning fails on reader endpoints (#37557)
* Improve error message when auto-user provisioning fails on reader endpoints

* fix lint
2024-02-08 19:48:07 +00:00
rosstimothy b7318b5c7e Enable errorlint via golangci-lint (#37669)
Adds the new linter and configures it to prevent direct error
comparisions and type assertions in favor of errors.Is and errors.As.
All current violations caught by the linter have been updated
accordingly.
2024-02-02 15:59:24 +00:00
STeve (Xin) Huang 505a21c7a7 Fix an issue tsh uses wrong default username for auto-user provisioning enabled databases in remote clusters (#37274)
* Fix an issue `tsh` uses wrong default username for auto-user provisioning enabled databases in remote clusters

* fix lint and improve message

* fix godoc

* remove extra quote
2024-01-29 14:10:05 +00:00
Gabriel Corado 49c2be0867 Always close io.Pipe when io.Copy is done (PostgresSQL engine) (#37220)
* fix(postgres): close pipe after io.Copy is done

* chore(postgres): add comment
2024-01-26 15:07:51 +00:00
STeve (Xin) Huang 3a6d10fa01 Fix an issue AWS Redshift auto-provisioned user not deleted in drop mode (#36828)
* Fix an issue AWS Redshift auto-provisioned user not deleted in drop mode

* update comment with link
2024-01-22 17:28:15 +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
STeve (Xin) Huang 7f3c58df1f Add default database support for PostgreSQL Auto-user provisioning (#34420)
* Added "defaultDatabase" support for Postgres auto-user provisioning

* update doc
2023-11-15 15:26:10 +00:00
Gavin Frazar 56d3acd676 improve postgres bind params audit logging (#34321)
* log with same format for all params when one format code is given
* log binary format params as base64 encoded string
2023-11-09 21:22:47 +00:00
Gabriel Corado df2bb63da6 feat(postgres): support auto-provisioned user deletion Redshift (#34006) 2023-11-01 17:06:27 +00:00
STeve (Xin) Huang 9da436281e Fix an issue auto-provisioned PostgreSQL user may keep old roles indefinitely (#33969)
* Fix an issue auto-provisioned PostgreSQL user may keep old roles indefinitely

* upper case the sql scripts
2023-11-01 16:48:57 +00:00
STeve (Xin) Huang 8180618c30 Database Automatic User Provisioning support for MariaDB (#33018)
* User auto-provisioning support for MariaDB

* fix lint

* revoke all-in-one role on deactivation

* review comments

* MariaDB to fallback on DeleteUser

* move sql files to a folder
2023-10-23 20:03:56 +00:00
STeve (Xin) Huang 4dce835487 Database Automatic User Provisioning support for Redshift (#33307)
* Database Automatic User Provisioning support for Redshift

* capitalize sql script

* DeleteUser to fallback to deactivate.

* add TPxxx code to RAISE messages

* fix missing space in scripts
2023-10-23 18:44:38 +00:00
Gabriel Corado 9582262a82 Add PostgreSQL auto-user deletion (#32792)
* feat: add auto-user deletion postgres

* refactor: change to IsEnabled func to check auto-user

* test: fix linting and test

* refactor(db): code review suggestions

* refactor: rename option to best effort drop

* refactor(api): rename createa database user mode property

* refactor(services): review suggestions

* feat(postgres): add log for user deletion result

* refactor(integrations): regenerate crd manifests

* feat(examples): update operator role spec

* refactor(db): use common sql state codes
2023-10-16 17:03:45 +00:00
Krzysztof Skrzętnicki 818d9edb2a Fix data race in Postgres engine on connection close (#32650)
* Fix data race in Postgres engine.

* Use channel instead of `sync.WaitGroup`.
2023-09-29 07:24:09 +00:00
Krzysztof Skrzętnickiandrosstimothy 8d5025a104 Postgres: avoid tiny writes to improve performance in read-heavy scenarios (#29812)
* Postgres: avoid tiny writes to improve performance.

To count the messages, consume copied message stream in a separate goroutine.

* Apply suggestions from code review

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

* Improve comments.

* Implement benchmark for read-heavy Postgres usage.

* Update lib/srv/db/postgres/engine.go

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

* Update lib/srv/db/postgres/test.go

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

* Linter.

* Improve benchmark accuracy - prepare test bench without a timer.

---------

Co-authored-by: rosstimothy <39066650+rosstimothy@users.noreply.github.com>
2023-08-18 09:54:07 +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
Krzysztof Skrzętnicki 9ac76d65cb Postgres: reduce logging level for individual messages. (#29810) 2023-08-01 08:01:54 +00:00
Roman Tkachenko 79b54d859d Add support for automatic database users for Postgres (#25614) 2023-05-18 23:22:14 +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
Gavin Frazar 3dd0b6f21f handle postgres cancel requests (#22173)
* support cancel requests in proxy and engine
* add cert leaf init util func
* init local proxy cert leaves
* inspect non-tunnel local proxy connections
  - check for postgres cancel requests
  - tunnel postgres cancel requests "on-demand"
2023-03-17 21:26:46 +00:00
Anton Miniailo 3633c6181e Add secure client IP propagation throughout teleport (#21080) 2023-02-28 20:38:12 +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
David Boslee cc36d290a1 Add metrics to track connection ingress (#19734)
* Add metrics to track connection ingress

* Add connection unwrapping

* Add license

* Remove debug logging

* Add ingress reporter tests

* Remove circular dependency

* Fix import formatting

* Missing defer

* Fix spelling of accepted

* Add _total suffix to counters

* Add godocs and fix nits

* Add test for http conn state reporter

* Use loop to unwrap netConnGetters

* Test meterics after http conn closed

* Ensure conns implement conn getter interface
2023-02-01 23:45:34 +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
Gavin Frazar ef43b4cef9 azure mysql and postgresql flex server discovery (#19759)
* Move GCP cloud clients into a separate interface
* Add azure mysql/postgresql flex server support
* Add teleport db configure create support for azure postgres/mysql flex servers
* discover both single and flexi server with 'mysql' and 'postgres' db types.
* go doc gcp interface
* Add is_flexi_server to database Azure config
2023-01-09 18:48:08 +00:00
STeve (Xin) Huang 6c858c09ee Register database engines directly from db lib (#19279) 2022-12-18 05:59:47 +00:00
STeve (Xin) Huang f2cf36a450 AWS Redshift Serverless engine support (#18651) 2022-12-01 15:36:48 +00:00
STeve (Xin) Huang 1b0a083b9d Database access AWS RDS Proxy support (#17005) 2022-10-31 15:21:31 +00:00
Jakub Nyckowski 0ee91f6c37 Enable GCI linter (#17894) 2022-10-28 20:20:28 +00:00
Gavin Frazar a6c7107ebd handle postgres GSSEncRequest startup message (#17614)
* Recognize GSSEncRequest as postgres proto

* Respond to GSSEncRequest with 'N' for 'not supported' in postgres engine

* Add test for GSSEncRequest to postgres via proxy

* Save gssencmode=disable in .pg_service.conf and test it

* Check for repeated startup encryption request

* Refactor postgres startup test code into its own test

* Test covers all code paths in the proxy startup handler

* Make postgres proxy tests run in parallel

* Reduced test execution time from 15 seconds to 4.5 seconds.
* Ran with race detector and all tests passed.

* Make sure we read at least one byte

* Fix lint

* Fix lint

* Change err to bad parameter

* Update test
2022-10-25 02:35:02 +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
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
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
Gabriel Corado a3a65e863b TLS routing ping for database protocols (#14887) 2022-08-26 16:42:23 +00:00
Roman Tkachenko 97c0b5cb83 Add auth'd tunnel mode to tsh proxy db command (#11720) 2022-04-07 18:33:39 +00:00
Jim Bishopp 06fef2abf1 SQL Backend (#11048)
Add a new backend supporting PostgreSQL and CockroachDB. 

Implements #10253 without cloud connectivity.
2022-03-29 00:18:09 +00:00
STeve (Xin) Huang 0d12750b78 Common database connect errors (#11111) 2022-03-15 16:28:23 +00:00
Roman Tkachenko 41899806fd Add SQL Server support for database access (#10097) 2022-02-17 02:20:33 +00:00
Roman Tkachenko 21b6b17a74 Refactor database engines registration (#10074) 2022-02-01 21:02:43 +00:00
Jim Bishopp 4511f7a687 Client Certificate Authentication for GCP Cloud SQL (#9991)
Allow users to secure GCP Cloud SQL instances by setting "Allow only SSL
connections", which enforces client certificate authentication.

This implementation does not require any configuration changes for Teleport
users. Teleport will detect whether client certificate authentication is
required and handle either case automatically.

Client certificates are ephemeral. They are created for every connection by
calling the GCP Cloud SQL API's GenerateEphemeralCert function. Certificates
are only created when the destination Cloud SQL instance is configured to
require client certificate authentication. The configuration is detected by
requesting instance settings from the GCP Cloud SQL API on every connection
attempt.

A special case was implemented for MySQL. MySQL servers in GCP Cloud SQL do not
trust the ephemeral certificate's CA but GCP Cloud Proxy does. To work around
this issue, the implementation will connect to the MySQL Cloud Proxy port using
a TLS dialer instead of the default MySQL port when client certificate
authentication is required.

The common.CloudClients interface and implementation now return an interface
(GCPSQLAdminClient) from the GetGCPSQLAdminClient function instead of the GCP
client's sqladmin.Service. Returning an interface simplified calling code and
allowed for the client to be mocked for testing.

Existing GCP Cloud SQL tests are configured to not require client certificate
authentication by default. A new test named TestGCPRequireSSL was created to
simulate client certificate authentication for both Postgres and MySQL. This
required some minor changes to the test server code.

A new ConnectWithDialer function was added to the
github.com/gravitational/go-mysql fork. This function is available upstream in
v1.4.0 but other changes upstream resulted in a number of errors and a panic
processing network packets. So instead of upgrading, the dialer function was
copied to the Teleport fork and a custom version was created instead:
v1.1.1-teleport.1.
2022-01-31 20:52:03 +01:00
Jakub Nyckowski c7c94111cd Add "limiter" support to database service (#9087)
Add rate and connection limiter to database service.
2022-01-07 22:23:22 +00:00