Skip to content

Remove dependency on Azure Account extension - #551

Merged
peterbom merged 15 commits into
Azure:mainfrom
peterbom:feature/new-az-auth
Apr 26, 2024
Merged

peterbom merged 15 commits into
Azure:mainfrom
peterbom:feature/new-az-auth

Conversation

@peterbom

@peterbom peterbom commented Mar 12, 2024 •

Copy link
Copy Markdown
Contributor

Addresses #566

This removes our dependence on the deprecated Azure Account extension.

The following commands were originally only in the Azure Account extension, and so have been re-implemented in the AKS extension:

  • Filter selected subscriptions
  • Sign-in to Azure

This required a new configuration setting in the AKS extension: aks.selectedSubscriptions. This behaves identically to the equivalent setting in the Azure Account extension (azure.resourceFilter). If the Azure Account setting exists, our extension will still use that, until the selected subscriptions for the AKS extension are changed.

The recommended alternative to the Azure Account extension is the @microsoft/vscode-azext-azureauth package. However, this does not provide good support for getting credentials that we can use to create clients for other Azure SDKs. It was necessary to use the VS Code authentication API directly, in addition to the Azure Auth API. This duplication made the session state confusing and potentially inconsistent. To simplify, I removed the dependency on the Azure Authentication package in favour of consuming just the VS Code API (see azureAuth.ts).

Until now we have also been using the @microsoft/vscode-azext-azureutils package which provides base class implementations of Account and Subscription nodes for our Cloud Explorer treeview. Unfortunately these classes are very tightly coupled to the Azure Account extension. Since our code base makes heavy use of credentials retrieved from tree nodes (via ISubscriptionContext), using these base classes means we are still using the Azure Account extension. So, this PR removes that package dependency too, and now implements the Account and Subscription tree nodes directly (based on classes in the @microsoft/vscode-azext-utils library, which is not tied to the Azure Account extension). This change means the Account and Subscription icons are now in our own repository, and so the webpack configuration for copying these files has also been removed.

For AAD clusters, we were previously using the low-level MSAL library to get an access token using the cluster's tenant and server scopes. This made use of a refresh token retrieved from the ISubscriptionContext credentials. With the authentication changes, this is now no longer available. Besides, the refresh token flow was not recommended anyway. Fortunately, the VS Code authentication API handles this scenario, without us having to resort to lower-level libraries, and so that dependency is also removed.

Other notes:

  • The clusters.ts contains functions for creating ARM clients for other resource types (not just clusters). I'd like to move these to the new arm.ts file so they're in one place, and so it's easier to verify that we're using credentials in a consistent manner. We can do that in a separate PR.
  • To avoid the temptation to add more ARM functionality that's not related to clusters into clusters.ts, I created subscriptions.ts. I think we can follow a similar pattern of having separate files for other ARM resources.
  • The azureAccount.ts file needs more work. It was previously used to get the Azure Account extension API, plus some miscellaneous ASO functionality (which is now broken on the MS tenant, see Install ASO command fails on some tenantsΒ #552). As part of fixing the ASO functionality, we should probably delete this file entirely.

@Tatsinnit Tatsat (Tats) Mishra πŸ‰ (Tatsinnit) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks heaps and looks good to me, lets get more eyes for testing and Hariharan Subramanian (@hsubramanianaks) eyes as well as he was keen to monitor these changes as well. + Prabhakaran S (@sprab) and Quentin Petraroia (@qpetraroia) for testing help please β€οΈβ€οΈβ˜•οΈ (Might be testing from non-msft account as well)

  • Question: Given the nature of this PR - do we want to release this separately as lighter but kind of breaking drop , as this will need re-signin from all users who are suing this extension?

This definitely seems progressive PR.

Screenshot 2024-03-19 at 7 22 36β€―PM Screenshot 2024-03-19 at 7 22 44β€―PM

@peterbom

Copy link
Copy Markdown
Contributor Author

Hariharan Subramanian (@hsubramanianaks) found a bug where the following happens:

  • You sign in using the "AKS: Sign in to Azure..." command
  • You select the "Sign in to another account" option (or it's your first time signing in)
  • A browser authentication window opens up
  • You close that window without completing the sign-in process

In that case VS Code thinks you're still signing in (there's no way it can be notified you've closed the browser tab). And if you try to sign in again, it waits for the original sign-in request to complete. This behaviour is part of the VS Code API and beyond our control. It is documented as a feature request in the VS Code repo, with the request being to support cancellation. The discussion suggests the request will eventually time out, but that did not happen for me after several minutes and I got tired of waiting. The issue has been in its current state for 3 years, so it doesn't look as if it'll see any movement anytime soon.

If it were to be fixed (i.e. the API changed to support cancellation) we could present a popup similar to the Azure Account one:
image

As it is, I'm reluctant to make further changes at this stage, for what I hope is a relatively infrequent scenario.

One thing we could do is display a cancellation dialog (like the one above), and if the user cancels we invoke the 'reload window' command. It's a bit of a sledgehammer approach, but it's currently the only way I can see for the user to get out of the trap. I think it'd make sense to try something like this in a separate PR, so it's easier to roll it back and replace with a better solution if we think of something.

Any thoughts, Hariharan Subramanian (@hsubramanianaks) and Tatsat (Tats) Mishra πŸ‰ (@Tatsinnit)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, more unbiased test will be if Hariharan Subramanian (@hsubramanianaks) can please share his testing or anyone else who kindly help for testing, thanks heaps for hits.

@peterbom

Copy link
Copy Markdown
Contributor Author

Testing checklist:

  • Uninstall Azure Account extension
  • Edit user settings (JSON)
    • Make a note of any subscriptions listed under "azure.resourceFilter"
    • If settings contains the key "aks.selectedSubscriptions", delete it and reload window
  • Run command: "AKS: Sign in to Azure..." and sign in to corp account
  • Expand cloud explorer treeview
    • Check listed subscriptions match those under "azure.resourceFilter"
  • Run command: "AKS: Select subscriptions..."
    • Select a different set of subscriptions
    • Check the "aks.selectedSubscriptions" setting is updated
    • Check the treeview refreshes
  • Run command: "AKS: Sign in to Azure..." and sign in to personal account
    • Check treeview refreshes
    • Check all subscriptions appear (it shouldn't be necessary to set filters)
  • Right-click on a cluster in a non-MSIT tenant and run "Install Azure Service Operator"
    • Enter a service principal clientId and secret and click "check"
    • Verify this runs without error
    • NOTE: this fails on the MSIT tenant for unrelated reasons (we have an issue for this)
  • Sign back into MSIT tenant ("AKS: Sign in to Azure...")
    • This time there should be only one confirmation dialog
    • Cloud explorer treeview should refresh
  • Repeat switching between tenants to make sure it keeps working smoothly
  • Check the Account icon in bottom-left of screen
    • Verify the treeview matches one of the signed-in accounts
  • Create a cluster using VS Code (in personal and/or MSIT tenant)
    • Check it completes successfully
    • After it's created, search for Action Group "RecommendedAlertRules-AG-11" in the Azure Portal
    • Check the email address in the Overview section of the portal (it should be the correct email address for the signed-in account)
  • Show Properties
  • Compare AKS clusters
  • Delete a cluster
  • Show in Azure Portal
  • Reconcile a cluster
  • Rotate cluster certificate
  • Run AKS Periscope

@Tatsinnit
Tatsat (Tats) Mishra πŸ‰ (Tatsinnit) dismissed their stale review April 24, 2024 21:03

Things moved fast in last 8 hours, want to make sure I am merging this PR out of too much zeal. Thanks

@alexweininger

Copy link
Copy Markdown

If you want to pursue using the package, my suggestion is that we meet to go over your requirements in more detail to see if it's the right fit.

@peterbom

Copy link
Copy Markdown
Contributor Author

Alex Weininger (@alexweininger), Tatsat (Tats) Mishra πŸ‰ (@Tatsinnit), Hariharan Subramanian (@hsubramanianaks) - thank you all for the comments.

I'd really like to work on a shared implementation for the authentication library, which I'm keen to devote some careful thought to and work with Alex Weininger (@alexweininger) on building. I think this will take some time and should not be rushed.

The core changes here are centralised in a couple of files, with the implementations abstracted away behind interfaces. I think that gives us a path forward:

  1. We continue with this PR as is (subject to any further comments on the implementation as it stands).
  2. We work on building any missing functionality/features into the wrapper library
  3. We swap out our implementation for the shared one as soon as we're confident it supports all our requirements.

There is no need for these later changes to have any impact on UX. The wrapper code uses the same underlying VS Code API, so user sessions should remain intact if we swap out implementations. The wrapper also supports custom subscription filters so we can continue to use the same user settings introduced in this PR.

@qpetraroia

Copy link
Copy Markdown

+1 to peterbom's vision here and thank you Alex Weininger (@alexweininger) for being open to meeting us and discussing our requirements!

@qpetraroia

Copy link
Copy Markdown

Signing off. I have opened a bug on our side to alert customers of the current issues with Azure login and the appropriate steps on how to fix it #639.

@peterbom
peterbom merged commit 127ed98 into Azure:main Apr 26, 2024
Tejhan Diallo (tejhan) pushed a commit to tejhan/vscode-aks-tools that referenced this pull request Dec 4, 2024
* Use vscode authentication library instead of Azure Account extension

* remove msal-node dependency

* remove azure auth

* remove duplication of getDefaultScope function and add error handling

* auth fixes for switching between signed-in tenants

* If no subscriptions are selected, display them all in the treeview

* remove unused properties from jwt interface

* fix URLs in select-subscriptions command

* get tenant id from auth session and new filter option for listing subs

* avoid passing treenodes to cluster library functions

* avoid exposing ISubscriptionContext from tree nodes

* handle session changes when tenants change and not when we triggered the change, and get session silently whenever possible

* Select a tenant by default rather than forcing user to do that

* list clusters using resource management client (as we were before)

* dedicated command for tenant selection, and abstract session provider with interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement πŸš€ New feature or request or improvements on existing code.

Projects

Development

Successfully merging this pull request may close these issues.

Remove Dependency on Azure Account extension

5 participants