-
Notifications
You must be signed in to change notification settings - Fork 563
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
Feat support for managed identity authentication in azure locking #1896
base: develop
Are you sure you want to change the base?
Conversation
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.
PR Summary
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here: app.greptile.com/review/github.
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
3 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
WalkthroughThis change adds a new authentication method "MANAGED_IDENTITY" across the documentation, implementation, and testing for Azure DevOps locking connection methods. The documentation now includes "MANAGED_IDENTITY" with details on setting the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User/Application
participant SA as Storage Account Lock Creator
participant ENV as Environment Variables
participant MIC as Managed Identity Client Creator
U->>SA: Request to create Storage Account Lock
SA->>ENV: Read DIGGER_AZURE_AUTH_METHOD
alt Method is MANAGED_IDENTITY
SA->>ENV: Verify DIGGER_AZURE_SA_NAME exists
SA->>MIC: Call getManagedIdentitySvcCLient()
MIC-->>SA: Return service client or error if DIGGER_AZURE_SA_NAME missing
else Other Methods
SA->>SA: Process with SHARED_KEY/CLIENT_SECRET flow
end
SA->>U: Return Storage Account Lock instance (or error)
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
libs/locking/azure/storage_account.go (1)
194-213
: Function implementation looks good, minor typo in function nameThe getManagedIdentitySvcCLient function is well-structured and follows the same pattern as the other authentication methods. However, there's a minor typo in the function name: "CLient" should be "Client".
Fix the typo in the function name:
-func getManagedIdentitySvcCLient() (*aztables.ServiceClient, error) { +func getManagedIdentitySvcClient() (*aztables.ServiceClient, error) {Don't forget to update the function call on line 132 as well:
- return getManagedIdentitySvcCLient() + return getManagedIdentitySvcClient()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/ce/azure-specific/azure-devops-locking-connection-methods.mdx
(1 hunks)libs/locking/azure/storage_account.go
(3 hunks)libs/locking/azure/storage_account_test.go
(3 hunks)
🔇 Additional comments (10)
docs/ce/azure-specific/azure-devops-locking-connection-methods.mdx (4)
15-15
: Looks good - MANAGED_IDENTITY auth method addedThe addition of the managed identity authentication method to the documentation is clear and consistent with the existing format.
19-21
: Formatting update looks goodThe formatting change for the SHARED_KEY section maintains consistency with the other methods, improving readability.
23-30
: Formatting update looks goodThe reformatting of CONNECTION_STRING and CLIENT_SECRET sections ensures a consistent documentation style.
32-33
: MANAGED_IDENTITY documentation is well-structuredThe documentation for the new MANAGED_IDENTITY authentication method clearly specifies the required environment variable.
libs/locking/azure/storage_account.go (3)
30-30
: Error message updated correctly for new auth methodThe error message has been properly updated to include the new MANAGED_IDENTITY authentication method.
131-133
: Managed Identity support added correctlyThe implementation correctly handles the MANAGED_IDENTITY case by calling the new getManagedIdentitySvcCLient function.
203-206
:✅ Verification successful
Verify managed identity behavior in Azure environments
The code uses NewManagedIdentityCredential with nil options, which will use the system-assigned managed identity. It's worth confirming that this works in your target Azure environments (VMs, App Services, Azure Functions, etc.)
🌐 Web query:
How does Azure SDK for Go's NewManagedIdentityCredential function behave in different Azure environments?
💡 Result:
The
NewManagedIdentityCredential
function in Azure SDK for Go adapts its behavior based on the Azure environment and configuration. Here's how it operates across different scenarios:System-Assigned Managed Identity
- Default behavior: When created without parameters (
azidentity.NewManagedIdentityCredential(nil)
), it uses the system-assigned identity of the Azure resource (e.g., VM, App Service, AKS)[1][4].- Environment detection: Automatically works in supported Azure services like:
- Azure Virtual Machines
- Azure App Service
- Azure Kubernetes Service (AKS)
- Azure Functions[2][6]
User-Assigned Managed Identity
- Client ID specification: Pass
ManagedIdentityCredentialOptions
withID: ClientID("your-client-id")
[7][16]:opts := &azidentity.ManagedIdentityCredentialOptions{ID: azidentity.ClientID("abcd1234-...")} cred, err := azidentity.NewManagedIdentityCredential(opts)- Environment variable: Alternatively, set
AZURE_CLIENT_ID
to use a user-assigned identity[5][16].Platform-Specific Constraints
The function throws errors when specifying user-assigned identities in environments with unsupported APIs:
- Azure Arc
- Cloud Shell
- Service Fabric
- Azure ML (when using resource ID)[10][16]
Example error trigger:
// Fails in Azure Arc/Cloud Shell: cred, err := azidentity.NewManagedIdentityCredential(&azidentity.ManagedIdentityCredentialOptions{ ID: azidentity.ClientID("invalid-for-this-platform"), })Environment Variable Interactions
The credential checks these variables for configuration:
Variable Purpose Example Platforms IDENTITY_ENDPOINT
Managed identity endpoint App Service 2019+, Azure Arc IDENTITY_HEADER
Authentication header App Service 2019+, Service Fabric MSI_ENDPOINT
Legacy MSI endpoint App Service 2017, Cloud Shell[5][9] Error Handling Changes
Since v1.8.0-beta.2:
- Strict validation: Returns errors instead of warnings for unsupported user-assigned identity configurations[10]
- Improved fallback:
DefaultAzureCredential
continues credential chain if IMDS probe fails[10]For production reliability, Microsoft recommends:
// Explicit credential selection if isProduction { cred = azidentity.NewManagedIdentityCredential(nil) // System-assigned } else { cred = azidentity.NewAzureCLICredential(nil) // Local development }This behavior ensures consistent authentication while accommodating Azure's diverse hosting environments[3][8][13].
Citations:
- 1: https://learn.microsoft.com/en-us/azure/developer/go/sdk/authentication/authentication-azure-hosted-apps
- 2: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md
- 3: https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication/best-practices
- 4: https://learn.microsoft.com/en-us/azure/developer/go/sdk/authentication/authentication-overview
- 5: https://blog.jongallant.com/2021/08/azure-identity-202/
- 6: https://www.nuget.org/packages/Azure.Identity/1.13.1
- 7: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity
- 8: https://nestenius.se/azure/default-azure-credentials-under-the-hood/
- 9: https://ravichaganti.com/blog/azure-sdk-for-go-authentication-methods-environmental-credential/
- 10: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azidentity/CHANGELOG.md
- 11: https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication/credential-chains
- 12: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md
- 13: https://ravichaganti.com/blog/azure-sdk-for-go-authentication-methods-chained-credentials/
- 14: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet
- 15: https://devblogs.microsoft.com/azure-sdk/azure-identity-with-sql-graph-ef/
- 16: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azidentity/README.md
- 17: https://learn.microsoft.com/en-us/dotnet/api/azure.identity.environmentcredential?view=azure-dotnet
- 18: https://azure.github.io/azure-sdk/general_implementation.html
- 19: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/service
- 20: https://developercommunity.visualstudio.com/t/azureidentity-is-broken-in-cloud-envir/10513028?q=spelling+error+-+Elements+is+not+a+word
Verify Managed Identity Configuration in Target Environments
The current implementation correctly uses
azidentity.NewManagedIdentityCredential(nil)
, which defaults to using the system-assigned managed identity as expected. Documentation confirms that this behavior applies to common Azure services (e.g., Virtual Machines, App Services, AKS, and Functions). Please ensure that your deployment targets support system-assigned identities. If you need to use a user-assigned identity, consider configuringManagedIdentityCredentialOptions
with the appropriate Client ID.libs/locking/azure/storage_account_test.go (3)
67-77
: Test case for managed identity looks goodThe test case for managed identity authentication is properly structured and includes a check to skip the test when not using a real storage account, which makes sense since managed identity only works in Azure environments.
151-158
: Negative test case implementation is correctThe negative test for managed identity with missing environment variables follows the same pattern as the other authentication methods and provides good test coverage.
396-400
: Environment setup function implemented correctlyThe loadManagedIdentityEnv function correctly sets up the required environment variables for managed identity testing.
Summary by CodeRabbit