-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Adding the Azure sync module functions along with new cloud client functionality #50366
Open
mvbrock
wants to merge
13
commits into
master
Choose a base branch
from
mvbrock/azure-integration-disco-azure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7bbc434
Protobuf and configuration for Access Graph Azure Discovery
mvbrock 0e5e04f
Adding the Azure sync module functions along with new cloud client fu…
mvbrock 646b1c1
Forgot to decouple role definitions fetching function from the fetcher
mvbrock 6d841aa
Moving reconciliation to the upstream azure sync PR
mvbrock 47cbbc9
Moving reconciliation test to the upstream azure sync PR
mvbrock eb6b32d
Updating go.sum
mvbrock 5c89fc7
Fixing rebase after protobuf gen
mvbrock 7c8c247
Nolinting until upstream PRs
mvbrock 672ae8d
Updating to use existing msgraph client
mvbrock 9a96e07
Adding protection around nil values
mvbrock 0b12f0d
PR feedback
mvbrock 4b21960
Updating principal fetching to incorporate metadata from principal su…
mvbrock 7e0979d
Merge branch 'master' into mvbrock/azure-integration-disco-azure
mvbrock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" | ||
"github.com/gravitational/trace" | ||
) | ||
|
||
// RoleAssignmentsClient wraps the Azure API to provide a high level subset of functionality | ||
type RoleAssignmentsClient struct { | ||
cli *armauthorization.RoleAssignmentsClient | ||
} | ||
|
||
// NewRoleAssignmentsClient creates a new client for a given subscription and credentials | ||
func NewRoleAssignmentsClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (*RoleAssignmentsClient, error) { | ||
clientFactory, err := armauthorization.NewClientFactory(subscription, cred, options) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefCli := clientFactory.NewRoleAssignmentsClient() | ||
return &RoleAssignmentsClient{cli: roleDefCli}, nil | ||
} | ||
|
||
// ListRoleAssignments returns role assignments for a given scope | ||
func (c *RoleAssignmentsClient) ListRoleAssignments(ctx context.Context, scope string) ([]*armauthorization.RoleAssignment, error) { | ||
pager := c.cli.NewListForScopePager(scope, nil) | ||
var roleDefs []*armauthorization.RoleAssignment | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefs = append(roleDefs, page.Value...) | ||
} | ||
return roleDefs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package azure | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2" | ||
"github.com/gravitational/trace" | ||
) | ||
|
||
// RoleDefinitionsClient wraps the Azure API to provide a high level subset of functionality | ||
type RoleDefinitionsClient struct { | ||
cli *armauthorization.RoleDefinitionsClient | ||
} | ||
|
||
// NewRoleDefinitionsClient creates a new client for a given subscription and credentials | ||
func NewRoleDefinitionsClient(subscription string, cred azcore.TokenCredential, options *arm.ClientOptions) (*RoleDefinitionsClient, error) { | ||
clientFactory, err := armauthorization.NewClientFactory(subscription, cred, options) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefCli := clientFactory.NewRoleDefinitionsClient() | ||
return &RoleDefinitionsClient{cli: roleDefCli}, nil | ||
} | ||
|
||
// ListRoleDefinitions returns role definitions for a given scope | ||
func (c *RoleDefinitionsClient) ListRoleDefinitions(ctx context.Context, scope string) ([]*armauthorization.RoleDefinition, error) { | ||
pager := c.cli.NewListPager(scope, nil) | ||
var roleDefs []*armauthorization.RoleDefinition | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
roleDefs = append(roleDefs, page.Value...) | ||
} | ||
return roleDefs, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth to add a max items? Even if something configurable and default to pretty high value.
Given that we load everything into memory, I wonder if could ever reach a memory limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably yes at some point in the future--some kind of corresponding paging functionality where results are buffered to the access graph. If we do that, we'd want to do it for all resources in AWS and Azure. Thoughts @tigrato?