Skip to content

Azure MySQL and PostgreSQL DB Discovery#15745

Merged
GavinFrazar merged 86 commits into
masterfrom
gavinfrazar/azure_mysql_postgres_auto_discovery_watchers
Aug 30, 2022
Merged

Azure MySQL and PostgreSQL DB Discovery#15745
GavinFrazar merged 86 commits into
masterfrom
gavinfrazar/azure_mysql_postgres_auto_discovery_watchers

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar commented Aug 23, 2022

This PR adds:

  • watchers/fetchers for Azure MySQL and PosgreSQL DB servers.
  • construction of types.Database from Azure MySQL/PostgreSQL DB servers.
  • skipping a fetcher inside Watcher.fetchAndSend() if the fetcher returns trace.NotFound.
    • This way, resource groups which are not found do not prevent other fetchers from running.
  • Some refactoring to make MaxPages a common constant, which we were using in a few different places. I needed it for Azure as well.
  • wildcard * matching for regions, resource groups, subscriptions

This is the last (code) PR for the larger issue to implement #14688

It is branched off #15674 and targetting it as a base branch for merge, but github will retarget it to master automatically once the other branch merges.

PR updating documentation for our Azure MySQL/PostgreSQL guide will follow this PR.

@GavinFrazar
Copy link
Copy Markdown
Contributor Author

@smallinsky @greedy52 I think this is ready for re-review

Comment thread lib/services/database.go Outdated
Comment thread lib/services/database.go
Comment thread lib/srv/db/cloud/watchers/watcher.go Outdated
Comment thread lib/srv/db/cloud/watchers/watcher_test.go Outdated
Comment thread lib/srv/db/cloud/watchers/watcher_test.go Outdated
Comment thread lib/srv/db/cloud/watchers/watcher_test.go Outdated
@github-actions github-actions Bot removed the request for review from codingllama August 30, 2022 11:07
@GavinFrazar GavinFrazar enabled auto-merge (squash) August 30, 2022 18:23
@GavinFrazar GavinFrazar merged commit f02b30b into master Aug 30, 2022
@GavinFrazar GavinFrazar deleted the gavinfrazar/azure_mysql_postgres_auto_discovery_watchers branch August 30, 2022 23:42
@GavinFrazar GavinFrazar restored the gavinfrazar/azure_mysql_postgres_auto_discovery_watchers branch August 31, 2022 00:33
GavinFrazar added a commit that referenced this pull request Aug 31, 2022
* 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>
@GavinFrazar GavinFrazar deleted the gavinfrazar/azure_mysql_postgres_auto_discovery_watchers branch August 31, 2022 02:34
GavinFrazar added a commit that referenced this pull request Sep 1, 2022
* Azure mysql postgres auto discovery configuration (#15629)

* 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

* Update lib/services/matchers.go

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>

* Update lib/config/fileconf.go

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

* Update lib/config/fileconf.go

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

* Update lib/services/matchers.go

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

* Remove superfluous cmp option for diffing azure matcher

* Rename AzureMatchers Tags to ResourceTags

* Deduplicate subscription/resource groups and add tests

* Remove azure matcher config fixup

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>
Co-authored-by: Marek Smoliński <marek@goteleport.com>

* Azure mysql postgres auto discovery config create (#15630)

* 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

* Add config create flags for azure matchers

* Add config create tests for azure

* Move discovery flags for azure below aws

* Fixup merge

* Azure API for DB discovery (#15674)

* 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

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

* 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

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

* Bump go.mod version to 1.18

* 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>

Co-authored-by: Krzysztof Skrzętnicki <krzysztof.skrzetnicki@goteleport.com>
Co-authored-by: Marek Smoliński <marek@goteleport.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database-access Database access related issues and PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants