-
Notifications
You must be signed in to change notification settings - Fork 794
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
Fix ImdsManagedIdentityProvider (#4096) #4193
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,8 +50,17 @@ pub(crate) const RFC1123_FMT: &str = "%a, %d %h %Y %T GMT"; | |
const CONTENT_TYPE_JSON: &str = "application/json"; | ||
const MSI_SECRET_ENV_KEY: &str = "IDENTITY_HEADER"; | ||
const MSI_API_VERSION: &str = "2019-08-01"; | ||
|
||
/// OIDC scope used when interacting with OAuth2 APIs | ||
/// | ||
/// <https://learn.microsoft.com/en-us/azure/active-directory/develop/scopes-oidc#the-default-scope> | ||
const AZURE_STORAGE_SCOPE: &str = "https://storage.azure.com/.default"; | ||
|
||
/// Resource ID used when obtaining an access token from the metadata endpoint | ||
/// | ||
/// <https://learn.microsoft.com/en-us/azure/storage/blobs/authorize-access-azure-active-directory#microsoft-authentication-library-msal> | ||
const AZURE_STORAGE_RESOURCE: &str = "https://storage.azure.com"; | ||
|
||
#[derive(Debug, Snafu)] | ||
pub enum Error { | ||
#[snafu(display("Error performing token request: {}", source))] | ||
|
@@ -383,16 +392,16 @@ struct MsiTokenResponse { | |
/// This authentication type works in Azure VMs, App Service and Azure Functions applications, as well as the Azure Cloud Shell | ||
/// <https://learn.microsoft.com/en-gb/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token#get-a-token-using-http> | ||
#[derive(Debug)] | ||
pub struct ImdsManagedIdentityOAuthProvider { | ||
pub struct ImdsManagedIdentityProvider { | ||
msi_endpoint: String, | ||
client_id: Option<String>, | ||
object_id: Option<String>, | ||
msi_res_id: Option<String>, | ||
client: Client, | ||
} | ||
|
||
impl ImdsManagedIdentityOAuthProvider { | ||
/// Create a new [`ImdsManagedIdentityOAuthProvider`] for an azure backed store | ||
impl ImdsManagedIdentityProvider { | ||
/// Create a new [`ImdsManagedIdentityProvider`] for an azure backed store | ||
pub fn new( | ||
client_id: Option<String>, | ||
object_id: Option<String>, | ||
|
@@ -415,7 +424,7 @@ impl ImdsManagedIdentityOAuthProvider { | |
} | ||
|
||
#[async_trait::async_trait] | ||
impl TokenCredential for ImdsManagedIdentityOAuthProvider { | ||
impl TokenCredential for ImdsManagedIdentityProvider { | ||
/// Fetch a token | ||
async fn fetch_token( | ||
&self, | ||
|
@@ -424,7 +433,7 @@ impl TokenCredential for ImdsManagedIdentityOAuthProvider { | |
) -> Result<TemporaryToken<String>> { | ||
let mut query_items = vec![ | ||
("api-version", MSI_API_VERSION), | ||
("resource", AZURE_STORAGE_SCOPE), | ||
("resource", AZURE_STORAGE_RESOURCE), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the entirety of the change |
||
]; | ||
|
||
let mut identity = None; | ||
|
@@ -709,7 +718,7 @@ mod tests { | |
)) | ||
}); | ||
|
||
let credential = ImdsManagedIdentityOAuthProvider::new( | ||
let credential = ImdsManagedIdentityProvider::new( | ||
Some("client_id".into()), | ||
None, | ||
None, | ||
|
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
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.
I removed the OAuth part from the name to highlight that this isn't an OAuth flow