Commit Graph
40 Commits
Author SHA1 Message Date
Marco André Dinis 6286488be3 Database: validate AWS Account ID (#19638)
When the AWS Account ID is provided, we must check that it is a valid
one.

AWS Account ID is a well documented field: 12-digit string

This check is meant to prevent typos when creating Databases mainly from
the Web UI in the context of Teleport Discover.
2022-12-28 12:42:39 +00:00
STeve (Xin) Huang be77dadd55 Move database fetchers to discovery service (#19510) 2022-12-26 20:46:25 +00:00
STeve (Xin) Huang b9a1f77027 Return the actual IAM errors when configure database IAM policy fails (#19282) 2022-12-19 21:37:09 +00:00
Steven Martin e1ebc332f8 spell fixes (#19419) 2022-12-16 19:01:28 +00:00
STeve (Xin) Huang 43529b2653 AWS Redshift Serverless auto-discovery (#18974) 2022-12-09 21:23:56 +00:00
STeve (Xin) Huang f2cf36a450 AWS Redshift Serverless engine support (#18651) 2022-12-01 15:36:48 +00:00
Gabriel Corado fa15a7c4c4 Azure SQL Server auto discovery (#17745) 2022-11-28 15:02:49 +00:00
STeve (Xin) Huang 220cdca786 Delete v9 database iam inline policy migration (#18640) 2022-11-23 17:13:37 +00:00
Mike Jensen aa890efb3a CodeQL Fixes around logging sensitive info (#18588)
* audit.go: Don't log request headers on audit event failure

Reported from CodeQL here:
https://github.com/gravitational/teleport/security/code-scanning/131

It has the potential to reporting the request auth through the copy to the event here:
https://github.com/gravitational/teleport/blob/5085cf0024f94f488976082a1555c499f63f9f4d/lib/srv/db/elasticsearch/engine.go#L359

Logging the type and id hopefully will allow us to correlate these failures for debugging without reporting the request auth.

* users.go: Only log the user id on failures

This is to address the CodeQL Findings:
  https://github.com/gravitational/teleport/security/code-scanning/65
  https://github.com/gravitational/teleport/security/code-scanning/64
  https://github.com/gravitational/teleport/security/code-scanning/63

We see the user object may have secrets which should not be logged from these two points:
  https://github.com/gravitational/teleport/blob/b338fac82dc25e084cb3dbc6ed8dbf1f54ed16e8/lib/srv/db/cloud/users/elasticache.go#L188-L189
  https://github.com/gravitational/teleport/blob/b338fac82dc25e084cb3dbc6ed8dbf1f54ed16e8/lib/srv/db/cloud/users/memorydb.go#L195-L196

The fix here is to only log the user ID which should not be sensitive.
2022-11-18 16:16:53 +00:00
Gavin FrazarandMarek Smoliński 65e35120a1 fix aws rds discovery invalid engine filter (#18328)
* Add helper func to check for AWS unrecognized engine error

* Retry RDS queries with individual filters if engine name is unrecognized

* godoc

* pass engine names instead of filters, to make retry logic simpler

* Update mocks to check/apply RDS engine filters

* Update watcher tests

* Add watcher test for unrecognized RDS engines

* Update lib/srv/db/cloud/mocks.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-11-17 20:46:35 +00:00
Zac Bergquist da7680ad0b Use x/exp/slices instead of home grown utilities (#18524)
We were inconsistent throughout the codebase and would sometimes
use the slices package and other times use our own equivalents
in api/.

This removes our versions in favor of the golang.org/x package that
does the same, which has the added benefit of reducing the surface
area of the public API module.

Note: despite existing uses of the slices package, for some reason
it didn't show up in go.mod or go.sum. Fixed that too.
2022-11-17 15:25:46 +00:00
Tiago Silva e868d2e9e8 Adds GCP GKE auto-discovery (#17831)
This PR presents a watcher for automatic `kube_cluster` discovery for GCP GKE clusters. Given an identity with access to the GCP cloud, the auto-discovery service will scan the cloud and register all clusters available in Kubernetes Engine.

Once the discovery service creates a `kube_cluster` on the Auth Server, the Kubernetes Service will start serving it. The credentials used to access the cluster are short-lived and generated through Google OAuth2 associated with the GCP Service Account configured for the Kubernetes Service.

GCP's Service Account must have the following role def attached:

```yaml
description: 'GKE Auto-Discovery'
includedPermissions:
- container.clusters.impersonate
- container.clusters.get
- container.clusters.list
- container.pods.get
- container.selfSubjectAccessReviews.create
- container.selfSubjectRulesReviews.create
name: projects/{projectID}/roles/GKEKubernetesAutoDisc
stage: GA
title: GKEKubernetesAutoDisc
```

Part of #16135, #13376
Related to  #12048, #16276, #16281, #16633, #14991
2022-11-11 18:10:29 +00:00
STeve (Xin) Huang d8f4581606 Web API for getting database IAM policy (#17635) 2022-11-09 13:58:17 +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
STeve (Xin) Huang d319ee2734 Azure Cache for Redis auto discovery (#16755) 2022-10-03 20:54:44 +00:00
STeve (Xin) Huang aabced42dc Azure Cache for Redis engine support (#16551) 2022-09-29 18:25:53 +00:00
STeve (Xin) Huang 245e67ad1f Fix auto discovery on secondary cluster of a global Aurora database (#16187) 2022-09-26 13:20:37 +00:00
Brian Joerger 4c0a6ff5b1 tsh PIV login integration (#15335)
* Add Yubikey PrivateKey implementation for use by Teleport clients.

  - Add yubikey login logic, reusing previously stored private keys.

  - Fix identity file decoding with PIV keys, which sign ecdsa certificates.

  - Add libpcsclite-dev pre-req for building on linux.

  - Remove unnecessary keys.Signer interface and move its functionality to keys.PrivateKey.

  - Move retry and jitter utils to new api/utils/retryutils package.
2022-09-23 19:44:10 +00:00
rosstimothy 7e036cdf42 Generic retrieval of FnCache values (#16485)
Coverts getting values in the `FnCache` from `FnCache.Get` to
`utils.FnCacheGet[T any]`. This allows us to have compile time
guarantees for the type being loaded, which allows us to remove
some of the manual type checking required of callers today.
2022-09-20 12:36:03 +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
Gavin FrazarandMarek Smoliński f02b30b18e Azure MySQL and PostgreSQL DB Discovery (#15745)
* Add Azure auto-discovery configuration fields

* Init databases if azure matchers are in config

* Use AzureMatchers in db service

* Use all azure subscriptions/resource groups if omitted in matcher

* Add azure config tests

* Go mod tidy to update dependencies

* Add azure response error conversion

* Check for azure access denied and give a helpful error message

* Add azure subscriptions api

* Add azure mysql/postgresql api and wrappers

* Test generic db server for azure

* Make server properties its own type

* Convert server types manually instead of via json

* Move server list method selection logic out of api client

* Update azure db server tests

* Fixup merge

* Update comments

* Update more comments and remove junk code

* Move all azure api into lib/cloud/azure

* Update state and version checks

* Convert Azure DB Server into database

* Add mutex to subscription client for caching, just in case

* Test database conversion from azure db server

* Refactor common code

* Add azure matchers to watch config

* Remove unused imports

* Use common max pages in memorydb users

* Add azure clients to cloud clients

* Add azure fetchers to watcher

* Skip fetcher NotFound errors

* Add azure watcher tests

* Fix test comment

* Add wildcard region matching

* Remove redundant import

* Update lib/srv/db/cloud/watchers/azure.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Move db server listing logic into separate func

* Refactor some db conversion code

* Use local var to cache sub IDs

* Rename azure subscription client

* Rename azure subscription client and remove sub ID caching

* Move azure cloud clients into separate embedded interface

* Update watcher test for 'NotFound' handling

* Embed azureClients struct

* Update lib/cloud/azure/db_server_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Update lib/cloud/azure/subscriptions_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Update lib/cloud/azure/db_server_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Update lib/cloud/azure/db_server_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Update lib/cloud/azure/db_server_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Rename azure subscription client and remove sub ID caching

* Add reference links for azure db ports

* Move indirect dep into group

* Wrap all converted azure response errors

* Remove unreachable panic

* Godoc DBServer

* Remove maxPages arg to azure client funcs

* Gofmt

* Spacing between copyright and package

* import order

* Update lib/srv/db/cloud/watchers/azure.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Fix import order

* Refactor region matching

* Fix usage of azure clients to remove max pages arg

* Query azure subscriptions in fetcher.Get if matching wildcard subscription

* Fix azure matcher construction

* Test azure fetcher discovers new subscriptions

* Remove unused test helper func

* Set azure database resource id metadata

* Log errors when fetching from azure subscription fails

* Use more readable protocol in azure db description

* Get azure mysql engine version from labels

* Update lib/srv/db/cloud/watchers/watcher_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Update lib/srv/db/cloud/watchers/watcher_test.go

Co-authored-by: Marek Smoliński <marek@goteleport.com>

Co-authored-by: Marek Smoliński <marek@goteleport.com>
2022-08-30 23:21:36 +00:00
Alex McGrath 122bda9ad0 Add an AWS EC2 instance fetcher (#13886)
* Add an AWS EC2 instance fetcher

* Resolve comments

- Remove leftover VPCID stuff
- Document public functions
- Return a notfound when there are no nodes fetched instead of nil nil

* Resolve comments

* Fix fileconf_test.go
2022-08-19 10:52:42 +00:00
STeve (Xin) Huang af2824fc9b Change IAM "UnmodifiableEntity" error to a debug log (#14594) 2022-07-27 16:58:23 +00:00
STeve (Xin) Huang 85016a9a3e MemoryDB support (#13069) 2022-06-14 19:09:31 +00:00
STeve (Xin) Huang 50dcd493df Manage ElastiCache Users (#12709) 2022-06-01 01:10:56 +00:00
STeve (Xin) Huang 2fbf94bf50 skip no credential providers error (#12942) 2022-05-27 15:18:24 +00:00
STeve (Xin) Huang 5c6deb7d9d ElastiCache support - the basics (#12209) 2022-05-13 15:09:20 +00:00
STeve (Xin) Huang d9bf1eaf62 Database agents to share same IAM policy (#11320) 2022-05-04 14:09:06 +00:00
6eebe8dfa7 Add MariaDB to AWS RDS auto discovery (#10333)
Add support for MariaDB AWS RDS with IAM authentication version 10.6+.

Co-authored-by: Paul Gottschling <paul.gottschling@goteleport.com>
Co-authored-by: Alan Parra <alan.parra@goteleport.com>
Co-authored-by: Roman Tkachenko <roman@goteleport.com>
2022-03-09 16:32:44 +00:00
STeve (Xin) Huang fa3387785b skip databases that are not available during auto discovery (#10699) 2022-03-04 20:37:32 +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
STeve Huang 47bc1b780c support for redshift auto discovery (#9851) 2022-01-27 17:11:30 +00:00
STeve Huang 09d049ba58 Auto discovery aurora reader and custom endpoints (#9668) 2022-01-24 17:38:14 -05:00
JoelandZac Bergquist 62173e096b use google/uuid instead of pborman/uuid (#9793)
* replace imports

* use google/uuid

* fix test

* reverse changelog changes

* update gomod

* zac steps

* tidy

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2022-01-19 23:44:48 +00:00
STeve Huang 875315cb7a Database auto discovery to be more tolerable to find as many as it can (#9426) 2022-01-19 17:09:13 +00:00
STeve Huang 1be9e81bf1 do not register Aurora serverless db clusters (#9386) 2022-01-06 21:30:47 +00:00
Roman Tkachenko ce547953db Automatically import RDS databases (#8481) 2021-10-15 11:03:10 -07:00
Roman Tkachenko 0897a31ee2 Auto-configure IAM for Redshift databases (#8348) 2021-10-04 10:42:55 -07:00
Roman Tkachenko 9959ea381f Auto-configure IAM for RDS databases (#8339) 2021-10-01 11:06:17 -07:00