Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Azure resource fetching in the Discovery service #48843

Open
wants to merge 34 commits into
base: master
Choose a base branch
from

Conversation

mvbrock
Copy link
Contributor

@mvbrock mvbrock commented Nov 12, 2024

Part of of https://github.com/gravitational/access-graph/issues/640 to implement Azure resource fetching in the Discovery service, and originating from the Azure integration POC branch master...mvbrock/azure-integration-poc. This PR is dependent on #48628 which specifies the gRPC messages/methods for transmitting Azure resources to the Access Graph. A new Azure fetcher is introduced alongside the AWS fetcher, as well as the addition of Azure role definition/assignment clients in the Cloud library, per https://github.com/gravitational/access-graph/issues/1314.

@mvbrock mvbrock force-pushed the mvbrock/azure-integration-grpc branch 3 times, most recently from 6c2c286 to 7d10b7c Compare November 14, 2024 19:52
@mvbrock mvbrock force-pushed the mvbrock/azure-integration-fetch branch from 6e1c97f to 4c2df44 Compare November 18, 2024 20:35
@mvbrock mvbrock force-pushed the mvbrock/azure-integration-grpc branch from 7d10b7c to 61e626b Compare November 18, 2024 20:38
@mvbrock mvbrock force-pushed the mvbrock/azure-integration-fetch branch 2 times, most recently from dae5182 to b20ff8b Compare November 18, 2024 23:37
Base automatically changed from mvbrock/azure-integration-grpc to master December 2, 2024 18:00
@mvbrock mvbrock force-pushed the mvbrock/azure-integration-fetch branch from 9f7e308 to a3b84e8 Compare December 2, 2024 18:40
@mvbrock mvbrock marked this pull request as ready for review December 4, 2024 22:04
@mvbrock mvbrock requested a review from tigrato December 4, 2024 22:04
@mvbrock mvbrock requested review from rosstimothy and removed request for bernardjkim and hugoShaka December 4, 2024 22:04
@public-teleport-github-review-bot

@mvbrock - this PR will require admin approval to merge due to its size. Consider breaking it up into a series smaller changes.

lib/cloud/azure/roleassignments.go Show resolved Hide resolved
lib/cloud/azure/roleassignments.go Show resolved Hide resolved
lib/cloud/azure/roleassignments.go Show resolved Hide resolved
lib/cloud/azure/roledefinitions.go Show resolved Hide resolved
lib/config/configuration.go Show resolved Hide resolved
lib/srv/discovery/fetchers/azure-sync/azure-sync_test.go Outdated Show resolved Hide resolved
lib/srv/discovery/fetchers/azure-sync/azure-sync_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

we already have a entraid graph client in lib/msgraph

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will see if it can be used or slightly modified to work here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should probably do this in a followup PR since some significant changes may need to be made to the entraid graph client.

accessgraphv1alpha "github.com/gravitational/teleport/gen/proto/go/accessgraph/v1alpha"
)

const groupType = "#microsoft.graph.group"
Copy link
Contributor

Choose a reason for hiding this comment

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

all this can be replaced with msgraph

@hugoShaka
Copy link
Contributor

hugoShaka commented Dec 5, 2024

This PR is quite large. This make reviewing hard, as reviewers we are more likely to miss bugs, and this makes reverting/backporting your PR harder because of the conflicts and potential protobuf breaking changes.

Working on a single branch to get the full thing working is positive as this avoids having to backtrack and fix things we forgot on a previous PR. However it might be useful to split the resulting changeset into smaller PRs. You will get a higher quality review and it will take less time to get merged.

Teleporters tend to split the PR into at least:

  • one PR with the protobuf/generated content
  • one PR with the client part
  • one PR with the service/cache collection part
  • one or more PR adding the new logic, services, ... (e.g. the new fetchers in the discovery service)

This does not apply to every PR but as a rule of thumb, splitting large PRs into smaller chunks is a best practice and you might want to consider breaking PRs larger than 500 locs.

@mvbrock mvbrock force-pushed the mvbrock/azure-integration-fetch branch 2 times, most recently from a386665 to fd9cc3e Compare December 6, 2024 05:15
Comment on lines +8006 to +8035
// Azure is a configuration for Azure Access Graph service poll service.
repeated AccessGraphAzureSync Azure = 3 [(gogoproto.jsontag) = "azure,omitempty"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please update the PollInterval comment? I assume it will be applied to Azure Sync as well.

Comment on lines +8022 to +8052
repeated string Regions = 1 [(gogoproto.jsontag) = "regions,omitempty"];
string SubscriptionID = 2 [(gogoproto.jsontag) = "subscription_id,omitempty"];
string Integration = 3 [(gogoproto.jsontag) = "integration,omitempty"];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add comments to those?
I assume Integration is required but for the others, can we use the wildcard to indicate all the regions or all the subscriptions?

Copy link
Contributor

Choose a reason for hiding this comment

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

What about resource groups? Should that also be used to filter out resources?
I imagine someone trying TAG and maybe they only want a couple of ResourceGroups to see how it works, before applying to everything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the suggestion for resource group configuration in https://github.com/gravitational/access-graph/issues/1376

)

func (a *Fetcher) fetchVirtualMachines(ctx context.Context) ([]*accessgraphv1alpha.AzureVirtualMachine, error) {
// Fetch the VMs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Fetch the VMs

💅 I don't think this comment is helpful.

return nil, trace.Wrap(err)
}

// Return the VMs as protobuf messages
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Return the VMs as protobuf messages

💅 I don't think this comment is helpful.


func (a *Fetcher) fetchVirtualMachines(ctx context.Context) ([]*accessgraphv1alpha.AzureVirtualMachine, error) {
// Fetch the VMs
vms, err := a.vmClient.ListVirtualMachines(ctx, "*")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a variable saying that "*" is used to get all resource groups?

Comment on lines +1743 to +1746
s.muDynamicTAGAWSFetchers.Lock()
s.dynamicTAGAWSFetchers[dc.GetName()] = awsSyncMatchers
s.muDynamicTAGAWSFetchers.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

No azure dynamic matchers for TAG Sync?

Comment on lines +64 to +67
reconcile(old.VirtualMachines, new.VirtualMachines, azureVmKey, azureVmWrap),
reconcile(old.Principals, new.Principals, azurePrincipalsKey, azurePrincipalsWrap),
reconcile(old.RoleDefinitions, new.RoleDefinitions, azureRoleDefKey, azureRoleDefWrap),
reconcile(old.RoleAssignments, new.RoleAssignments, azureRoleAssignKey, azureRoleAssignWrap),
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a 💅
If we always order the type of resources alphabetically, it will be easier to spot issues/typos

featNameVms = "azure/virtualmachines"
)

const FetcherConcurrency = 5
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a godoc here?
Do we have concurrency in fetching resources? Or is it resources and regions?

}, nil
}

type Features struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing godoc

Copy link
Contributor

Choose a reason for hiding this comment

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

We have lib/msgraph. Can we use that instead?
If something's missing there, can we add it instead of replicating most of the code here?

@mvbrock mvbrock force-pushed the mvbrock/azure-integration-fetch branch from 4947312 to 21da3f3 Compare December 14, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants