-
Notifications
You must be signed in to change notification settings - Fork 89
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
Acquire token for IMDS SAMI #500
Conversation
Added a simple version of getting token and printing it reformatting code.
Added tests and implementation for SAMI IMDS
Reverted changes in the test app
Formatting changes
Added method for UAMI
Updated the some code and cleaned up some comments and print statement
Updated the key for the resource Co-authored-by: Charles Lowell <[email protected]>
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.
Looks good, some more tests are needed I think, particularly for getting error responses from IMDS (like 400 error with details about the error)
Updated the token from url function to a reaquest based function
…icrosoft-authentication-library-for-go into acquire-token-for-mise
Updated test to fail not only return error
Co-authored-by: Charles Lowell <[email protected]>
…icrosoft-authentication-library-for-go into acquire-token-for-mise
Removed printing token Variable name updated.
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.
Looks good to me
Updated the MI identity for UAMI with "UserAssigned" as prefix
} | ||
if err != nil { | ||
t.Fatal("client New() error while creating client") | ||
} else { |
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.
Not a blocker but this else
is still unnecessary. What you have is like
if err != nil {
os.Exit(1)
} else {
// this block never executes when err != nil, so you don't
// need the else to prevent it executing in that case
}
} | ||
mockClient.AppendResponse(mock.WithHTTPStatusCode(http.StatusOK), mock.WithBody(responseBody), mock.WithCallback(func(r *http.Request) { url = r.URL.String() })) | ||
client, err := New(SystemAssigned(), WithHTTPClient(&mockClient)) | ||
mockClient.AppendResponse(mock.WithHTTPStatusCode(http.StatusOK), mock.WithBody(responseBody)) |
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 delete the callback you had here? Don't you want to validate the request? Now you have this test doing
url := testCase.endpoint
// ... nothing modifies the value of url ...
if !strings.HasPrefix(url, testCase.endpoint) {
t.Fatal("this line will never execute")
}
and you're really only testing that the client can unmarshal the response. That's important, but so is the client's request
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.
Updated to check alot more values in the request.
} else { | ||
if client.miType.value() != tt.id.value() { | ||
t.Fatal("client New() did not assign a correct value to type.") | ||
} | ||
} | ||
}) | ||
} | ||
|
||
} | ||
func TestCreateIMDSAuthRequest(t *testing.T) { |
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 suggested merging this into another test, not simply deleting it; the coverage is important
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 added that test to Test_SystemAssigned_Returns_Token_Success
Co-authored-by: Charles Lowell <[email protected]>
Updated to have more coverage
…icrosoft-authentication-library-for-go into acquire-token-for-mise
apps/tests/devapps/main.go
Outdated
// acquireTokenClientCertificate() | ||
// // this time the token comes from the cache! |
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.
👀 do you intend to make this change?
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 Was testing the api on the VM so, to get these changes there pushed this, now reverted.
Quality Gate failedFailed conditions |
Add ManagedIdentity Class and acquireToken Function for SystemAssigned Identity
Overview
This PR introduces a new
ManagedIdentity
class in the Go codebase, specifically designed to handle operations related to managed identities in Azure. The primary feature added in this PR is theacquireToken
function within theManagedIdentity
class, which currently supports only SystemAssigned managed identities.Changes
ManagedIdentity:
ManagedIdentity
to encapsulate managed identity operations.acquireToken Function:
acquireToken
function in theManagedIdentity
class.Implementation Details
SystemAssigned Identity:
acquireToken
function currently assumes that the managed identity is SystemAssigned.http://127.0.0.1:40342/metadata/identity/oauth2/token
.Error Handling:
Testing
acquireToken
function to ensure it behaves as expected when fetching tokens for a SystemAssigned identity.Checklist
Notes
ManagedIdentity
class with limited functionality. Please review and suggest improvements, especially concerning the design for future extensibility.