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

Add support for MySQL AAD Users #1315

Merged
merged 7 commits into from
Nov 24, 2020
Merged

Conversation

matthchr
Copy link
Member

@matthchr matthchr commented Nov 19, 2020

What this PR does / why we need it:
Adds support for AAD users in MySQL. These users can only be created or managed if the identity ASO is operating as is:

  1. A managed identity
  2. The "Active Directory Administrator" of the MySQL DB. Users can make the ASO Managed Identity this admin using the resource added in Add support for MySQL Administrators #1314.

This also includes updates to the Managed Identity documentation to help improve clarity of the feature. As part of this I deleted the tool createMi.go as all it really did was run 3 az cli commands to create a managed identity and assign it permissions. It made assumptions about what permissions you wanted the identity to have. Additionally it suggested to install aad-pod-identity, but this guidance is not appropriate for installations via Helm because Helm already installs that dependency as part of the chart. Rather than having a script try to be one-size fits all it makes more sense to give customers the instructions they need to create the managed identity and allow them to choose what permissions they want to give it.

Special notes for your reviewer:
I may need to update this resource to also work with non-managed identities, as we have customers asking for that use case as well... so there may be some updates to the PR.

Testing this in our existing test infrastructure is basically not doable, as you need to be deployed to a VM in Azure and have a pod running with an MSI assigned. Going forward we will want to fix that, but for now I tested this manually to unblock us.

How does this PR make you feel:
gif

If applicable:

  • this PR contains documentation
  • this PR contains tests

Copy link
Member

@theunrepentantgeek theunrepentantgeek left a comment

Choose a reason for hiding this comment

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

I admit I didn't follow a few pieces, but looks good otherwise. A few minor comments.

README.md Outdated
@@ -60,6 +60,7 @@ Ready to quickly deploy the latest version of Azure Service Operator on your Kub
helm repo add azureserviceoperator https://raw.githubusercontent.com/Azure/azure-service-operator/master/charts
```
3. Create an Azure Service Principal. You'll need this to grant Azure Service Operator permissions to create resources in your subscription.
For more information about other forms of authentication supported by ASO, see []
Copy link
Member

Choose a reason for hiding this comment

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

MIssing link.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, good eye!

api/v1alpha1/mysqlaaduser_types.go Show resolved Hide resolved
config/samples/azure_v1alpha1_mysqlaaduser.yaml Outdated Show resolved Hide resolved
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=AzureSQLUsers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=azure.microsoft.com,resources={AzureSQLUsers/status,AzureSQLUsers/finalizers},verbs=get;update;patch
// +kubebuilder:rbac:groups=azure.microsoft.com,resources=azuresqlusers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=azure.microsoft.com,resources={azuresqlusers/status,azuresqlusers/finalizers},verbs=get;update;patch
Copy link
Member

Choose a reason for hiding this comment

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

Is this casing change a breaking one?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. As I mentioned below to @babbageclunk, the issue is that these were duplicate entries and the ones in main.go were winning. The ones in main.go were lowercase so I just moved them here to match the pattern all of the other resources had with the RBAC permissions being on the _controller file.

I just went and manually confirmed as well that in master in the generated role.yaml file, the permissions for azuresqlusers are lowercase:

  resources:
  - azuresqlusers


2. Apply the AzureIdentity and Binding manifests. This binds the identity to the Azure Service Operator.
Where a particular `resourceID` or `clientID` is referenced in the template below, ensure that you replace it with your Managed Identity `resourceID` and `clientID`.
If you used the script mentioned [here](managedidentity.md), this should be automatically done for you.
Copy link
Member

Choose a reason for hiding this comment

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

Should the bash shell stuff below have specific subscription and identities removed, to encourage people to fill out their own?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not really aware of a way to templatize this and still leave it "clean" -- but what I can do at least is change the subscription ID to all 0's.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually... I can just do <your-x-here>, maybe that's cleaner? I'll do that.

// TODO: looks like here? https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/internal/iam/authorizers.go

// TODO: No we need to actually delete this file and all of its usage I think...
// TODO: just use https://github.com/Azure/go-autorest/blob/master/autorest/azure/auth/auth.go NewAuthorizerFromEnvironment
Copy link
Member

Choose a reason for hiding this comment

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

Should these TODOs be addressed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are actually wrong, will fix and remove TODO as what remains is mostly "notes" rather than a TODO.

babbageclunk
babbageclunk previously approved these changes Nov 23, 2020
Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

This looks great - I don't fully understand the pod identity details. From the reading I did today it seems like the magic is in NMI rewriting the node's iptables so it can intercept MSI requests and add extra information about the identity on the way. Is that right?

README.md Outdated Show resolved Hide resolved
api/v1alpha1/mysqlaaduser_types.go Show resolved Hide resolved
api/v1alpha1/mysqlaaduser_types.go Outdated Show resolved Hide resolved
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package cmd
Copy link
Member

Choose a reason for hiding this comment

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

Could you add something in the description explaining why this was deleted? I'm guessing because it's obsolete now? Although this change is specific to MySQL - is there any need for a more general facility as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the following:

This also includes updates to the Managed Identity documentation to help improve clarity of the feature. As part of this I deleted the tool createMi.go as all it really did was run 3 az cli commands to create a managed identity and assign it permissions. It made assumptions about what permissions you wanted the identity to have. Additionally it suggested to install aad-pod-identity, but this guidance is not appropriate for installations via Helm because Helm already installs that dependency as part of the chart. Rather than having a script try to be one-size fits all it makes more sense to give customers the instructions they need to create the managed identity and allow them to choose what permissions they want to give it.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome, thanks!

clientID: 5bb69783-06a1-4277-82b7-97820b357503
---
apiVersion: "aadpodidentity.k8s.io/v1"
kind: AzureIdentityBinding
Copy link
Member

Choose a reason for hiding this comment

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

Something I don't understand about aad-pod-identity from reading the docs is: why is the AzureIdentityBinding needed? The pods are annotated with a label matching the selector on the binding, but why wouldn't the label refer directly to the identity instead? I don't understand why there's an extra layer of indirection.

Hmm. I guess it would mean that you could switch the identity being used by the pods without having to update them all, you could just update the binding. So maybe that's it? It would be good if they could spell out the reasons in the docs though.

They also have an example of having more than one binding with selectors that match the label on a pod, so the identity used would be random? It seems very weird.

pkg/resourcemanager/mysql/mysqlaaduser/reconcile.go Outdated Show resolved Hide resolved
pkg/resourcemanager/mysql/mysqlhelper.go Outdated Show resolved Hide resolved
pkg/resourcemanager/mysql/mysqlhelper.go Outdated Show resolved Hide resolved
pkg/resourcemanager/mysql/mysqluser/mysqluser.go Outdated Show resolved Hide resolved
@matthchr matthchr force-pushed the feature/mysql-aad branch 2 times, most recently from 0558d1c to 62784ed Compare November 24, 2020 00:50
Copy link
Member

@theunrepentantgeek theunrepentantgeek left a comment

Choose a reason for hiding this comment

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

Looks good.

README.md Outdated Show resolved Hide resolved
babbageclunk
babbageclunk previously approved these changes Nov 24, 2020
Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

Looks great now thanks!

Co-authored-by: Christian Muirhead <christian.muirhead@microsoft.com>
@matthchr matthchr merged commit 1b6f19d into Azure:master Nov 24, 2020
@matthchr matthchr deleted the feature/mysql-aad branch November 24, 2020 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants