Skip to content

Comments

light weight Msi auth helper library to be used by SQL#2755

Merged
praries880 merged 14 commits intoAzure:masterfrom
praries880:msi-auth-helper
Dec 13, 2018
Merged

light weight Msi auth helper library to be used by SQL#2755
praries880 merged 14 commits intoAzure:masterfrom
praries880:msi-auth-helper

Conversation

@praries880
Copy link
Contributor

This PR creates a small jar file to be used by sql to pull tokens for managed identities.

@praries880 praries880 self-assigned this Dec 6, 2018
@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@praries880 praries880 assigned anuchandy and unassigned praries880 Dec 10, 2018
private static String getTokenFromResult(String result) {
int startIndex_AT = result.indexOf(ActiveDirectoryAuthentication.ACCESS_TOKEN_IDENTIFIER)
+ ActiveDirectoryAuthentication.ACCESS_TOKEN_IDENTIFIER.length();

Copy link
Member

Choose a reason for hiding this comment

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

should we add a sanity check here?

If substring not found then startIndex_AT is -1 and below substring op with -1 will throw IndexOutOfBoundsException. We could return null instead, thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only time this is gonna happen is if the result does not hold a token in it. That would happen in a error scenario... which would fall into the exception category.

But I do like defensive programming...will add the check mate :)

Copy link
Member

Choose a reason for hiding this comment

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

thanks :) yes if it happens then it's an error scenario. When MSAL take this over, we can ask there preference on handling this, this may never occur or if happens they might want to throw client side exception (like TokenRetrievalException).

} else throw ioEx;
} catch (Exception e){
if (e.getCause()!= null && e.getCause() instanceof SocketException && e.getCause().getMessage().contains("Permission denied: connect")) {
throw new FileNotFoundException("Managed identity not found/configured");
Copy link
Member

@anuchandy anuchandy Dec 12, 2018

Choose a reason for hiding this comment

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

Can we throw an Exception with the actual exception wrapped in it? something like our own
MSITokenRetrievalException with the same msg but inner exception as the actual exception? In case of getTokenForVirtualMachineFromIMDSEndpoint method we throw RuntimeException without loosing the actual exception when possible, but I guess the same specialized exception is better there as well, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ill sync up woith you offline about this...

public Single<MSIToken> getToken(String tokenAudience) {
switch (hostType) {
case VIRTUAL_MACHINE:
return Single.fromCallable(() -> this.getTokenForVirtualMachineFromIMDSEndpoint(tokenAudience == null ? this.configForVM.resource() : tokenAudience));
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: We could make it async all the way down, i.e. by making getTokenForVirtualMachineFromIMDSEndpoint to use rx constructs that way retry-sleep is also async. May be we could keep this in mind and implement if there is a need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am thinking of totally doing away with the rx dependency of this library... its meant to be a really light weight tar with a small footprint. The only reason I left this in was to keep it close to the original implementation here

Copy link
Member

Choose a reason for hiding this comment

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

Completely agree that lib should have light weight footprint. At the same time I'm not sure about exposing only sync variant to retrieve the token. We have had customers asking for full async support including the authentication step, this is why we introduced AsyncServiceClientCredentials. We might want to think how to handle it.

We can always expose sync and let customer use rx/reactor construct to convert that to async. one problem I see is - customer may opt for io thread for this async conversion thinking token retrival is an nw io operation. But our retry strategy has back-off that can put this io thread in sleep mode, which is not recommend.

@praries880 praries880 merged commit f0b600f into Azure:master Dec 13, 2018
@praries880
Copy link
Contributor Author

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.

3 participants