Skip to content

Add Azure resource ID to protos#15673

Merged
GavinFrazar merged 12 commits into
masterfrom
gavinfrazar/azure_mysql_postgres_auto_discovery_proto
Aug 25, 2022
Merged

Add Azure resource ID to protos#15673
GavinFrazar merged 12 commits into
masterfrom
gavinfrazar/azure_mysql_postgres_auto_discovery_proto

Conversation

@GavinFrazar
Copy link
Copy Markdown
Contributor

@GavinFrazar GavinFrazar commented Aug 19, 2022

This PR updates the protobuf for Azure database metadata to include the full resource ID, which will be parsed from the resource ID in form /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}

Mostly protobuf only changes, but I did have to fix a test for serialization which was affected by the metadata change.

This is a part of a larger issue to implement Azure MySQL/PostgreSQL auto-discovery: #14688

This PR branched off #15629 so github will automatically retarget the base branch to master when that PR merges.

@GavinFrazar GavinFrazar self-assigned this Aug 19, 2022
@GavinFrazar GavinFrazar changed the base branch from gavinfrazar/azure_mysql_postgres_auto_discovery_config_create to gavinfrazar/azure_mysql_postgres_auto_discovery_configuration August 19, 2022 01:26
@GavinFrazar GavinFrazar marked this pull request as ready for review August 19, 2022 01:27
@github-actions github-actions Bot added the tsh tsh - Teleport's command line tool for logging into nodes running Teleport. label Aug 19, 2022
@github-actions github-actions Bot requested review from lxea and nklaassen August 19, 2022 01:28
Comment thread api/types/types.proto Outdated
// Region is an Azure cloud region.
string Region = 2 [ (gogoproto.jsontag) = "region,omitempty" ];
// ResourceID is the Azure fully qualified ID for the resource.
AzureResourceID ResourceID = 3
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ResourceID name indicate that this will be some kind of uniq identifier but instead this filed contains struct with other field that makes a resourceID so would would you say about renaming this field to AzureResource

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think for future-proof we should just make this ResourceID a string. I like keeping the fields separate for ease of use and readability, but as I looked at the arm.ResourceID definition I realized that the ID can be nested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The armmysql.Server and armpostgresql.Server have comments that imply the ID can only be of the form /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} though. I'm guessing that the nested form doesn't apply to databases then - what do you guys think?

Copy link
Copy Markdown
Contributor

@greedy52 greedy52 Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current way is fine once the struct name is updated. If one day we run into the nested ID, it can be dealt with separately.

Though I think the real question is what we need these values for, after types.Database is created. I checked the big PR I don't see any use for it yet.

So I may suggest adding these later when there is a use case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed the resource group for making the metadata watcher, since armmysql.ServersClient and armpostgresql.ServersClient require the resource name and group to fetch a resource. The resource group is only specified in the resource ID string, which requires parsing. I added all the relevant fields from parsing the ID so I could just parse once, but the only one I need so far is that resource group. I also added the region, but this has no use right now either.

All that being said I'm not sure if we even have a use-case for metadata watcher service for Azure. We do need the server to have an Azure Active Directory admin set to enable AAD auth. If a user ever unsets the AD admin on the database server then AAD is effectively disabled. So this metadata watcher could act like it does for RDS and detect if AAD auth is disabled. I'm just not sure if that's useful since a user must still login manually and create the user/role in the database identified by the service principal ID - and if we "reenable" AAD auth by setting an AD admin, then we would have to set the admin to the service principal itself...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metadata service is not designed as a watcher currently. The metadata service is only run once per new database (with the exception of ElastiCache and MemoryDB but you can ignore). I believe the metadata service was mainly designed to fetch metadata for non-auto-discovered databases (e.g. from static files), since auto-discovered databases usually come with proper metadata. The auto-discovery watchers should detect any metadata change and the reconciler can push a new database.

Do we have a plan on "auto" enabling AAD auth? Maybe we can revisit this once we work on that.

Is anything else requiring the ResourceID apart from the metadata service?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anything else needs the resource ID. I'll just hold off on changing the protobuf if we want to revisit this in the future. I think we should eventually automate the creation of a role/user in the database itself, but we don't do that for AWS right now either.

@github-actions github-actions Bot removed request for lxea and nklaassen August 19, 2022 12:38
Base automatically changed from gavinfrazar/azure_mysql_postgres_auto_discovery_configuration to master August 19, 2022 19:48
@GavinFrazar
Copy link
Copy Markdown
Contributor Author

GavinFrazar commented Aug 25, 2022

Based on discussions with @smallinsky, I'm going to add the meta data fetching for Azure in meta.go, to check if Azure AD Auth is enabled. This will require querying for whether the Azure AD Admin is set (to anyone). Eventually I will need to automate setting the AD admin to enable AAD auth.

I changed the protobuf in this PR to just include the resource id string itself, since that is the most flexible future-proof option imo. If you look at the AWS protos, we just use the string ARN instead of parsing it into metadata fields.

edit: I also removed the "Region" metadata since it serves no foreseeable purpose in Azure for meta data fetching.

@GavinFrazar GavinFrazar enabled auto-merge (squash) August 25, 2022 20:11
@GavinFrazar GavinFrazar merged commit 66c010d into master Aug 25, 2022
@GavinFrazar GavinFrazar deleted the gavinfrazar/azure_mysql_postgres_auto_discovery_proto branch August 26, 2022 00:14
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

* Update protobuf and fix database serialization

* Update azure database spec/status

* Change proto to use resource id string

* Fix database serialization test
GavinFrazar added a commit that referenced this pull request Aug 31, 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

* Add Azure resource ID to protos (#15673)

* 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 protobuf and fix database serialization

* Update azure database spec/status

* Change proto to use resource id string

* Fix database serialization test

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

tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants