-
Notifications
You must be signed in to change notification settings - Fork 203
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
Don't use global credentials in low-level methods #1309
Conversation
These are now retrieved using config.GlobalCredentials(), which will eventually be pushed further and further up the call stack, to make implementing flexible auth easier.
All functions that used the global credentials now require creds passed in - all callers are updated to pass in the global credentials. Eventually this will push all creds-getting up to the level of the reconcile loop so that we can change it to get them from somewhere else.
This allows tests to pass their own credentials without having to set the global ones.
21a6d52
to
be3fa93
Compare
...Other than in tests.
7b2d1ce
to
b1a1c38
Compare
...Other than in tests. Credentials are now passed in when creating a Manager or APIMgmtServiceManager.
0347fd8
to
14d3b5f
Compare
Credentials are now passed in when constructing a Manager.
Credentials are now passed in when constructing a manager.
Credentials are now passed in when constructing a Manager.
Credentials are now passed in when constructing Managers.
...Other than in tests. Credentials are now passed in when constructing a manager. Eliminate global KeyVaultManager used in tests - now it's constructed with credentials in the affected tests instead.
Credentials are now passed in when constructing a Client.
Credentials are now passed in when constructing managers/clients.
Credentials are now passed in when constructing the Client.
Credentials are now passed in when constructing a Client.
Credentials are now passed in when constructing a PollClient.
Credentials are now passed in when constructing a client or manager.
Credentials are now passed in when constructing managers.
Credentials are now passed in when constructing a manager. Converted package level functions ListGroups, GetGroup, DeleteAllGroupsWithPrefix and WaitForDeleteCompletion into methods on AzureResourceGroupManager. There didn't seem to be a reason that they were functions when they would now need credentials.
Credentials are now passed in when constructing a manager.
Credentials are now passed in when constructing the client.
Credentials are now passed in when constructing a client.
Credentials are now passed in when a client is constructed.
fb4999a
to
8b47a7f
Compare
Credentials are now passed in when constructing a manager.
8b47a7f
to
750f3e8
Compare
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.
That was quite a PR to review!
// TODO(creds-refactor): can we just use the tenant and client id from | ||
// the creds here? Depends whether the client code uses them to | ||
// override the creds. | ||
func getObjectID(ctx context.Context, creds config.Credentials, tenantID string, clientID string) (*string, error) { |
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.
This function is used in 2 places. One of those places is CreateVaultWithAccessPolicies
which as far as I can tell is only used in tests... may be worth moving to tests directly if that's really a test helper method not used at all in production code.
The other location is ParseAccessPolicy
which seems to use a clientId/tenantId other than the one in the credentials (supplied by the user?)
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.
I've removed the comment - I've left the method for now even though it's used from tests. If it was only used in the tests for keyvault I'd move it, but it's kind of tricky to share testing code between two packages.
@@ -13,8 +13,6 @@ import ( | |||
"github.com/Azure/azure-service-operator/pkg/resourcemanager" | |||
) | |||
|
|||
var AzureKeyVaultManager KeyVaultManager = &azureKeyVaultManager{} |
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.
Why remove this?
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.
Instead just do var _ KeyVaultManager = &azureKeyVaultManager{}
seems reasonable?
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.
This was being used by code in other packages - I needed to remove the global variable because it needs to have creds when it's constructed. I'll reinstate the interface assertion part though!
This is a refactoring to pull the use of global credentials up to the level of the reconcile loop for resources to enable switching where we look for credentials in a future PR. This is part of implementing #1173 based on the work in #1206.
This PR doesn't change the behaviour of the operator - the controller loops will still use global credentials. Making this mechanical change first in a separate PR to simplify reviewing.
Tips for reviewers - the first three commits are the most interesting ones, the others are basically just mechanical. Although the resource groups one was slightly fiddlier than the others.
How does this PR make you feel: