Skip to content

Managed Service Identity Login #5227

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

Merged
merged 1 commit into from
Jan 19, 2018
Merged

Conversation

markcowl
Copy link
Member

@markcowl markcowl commented Jan 4, 2018

Description


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThru parameter.

Cmdlet Parameter Guidelines

  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module.
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

twitchax
twitchax previously approved these changes Jan 5, 2018
Copy link
Contributor

@twitchax twitchax left a comment

Choose a reason for hiding this comment

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

Awesome! :)

A few random comments.

{
Id = userId,
Type = AzureAccount.AccountType.ManagedService
}; ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: extra semicolon.

Type = AzureAccount.AccountType.ManagedService
}; ;
var environment = AzureEnvironment.PublicEnvironments["AzureCloud"];
string expectedResource = environment.ActiveDirectoryServiceEndpointResourceId;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not var like the others?

builder.Query = string.Format("resource={0}", Uri.EscapeDataString(environment.ActiveDirectoryServiceEndpointResourceId));
var defaultUri = builder.Uri.ToString();

IDictionary<string, ManagedServiceTokenInfo> responses = new Dictionary<string, ManagedServiceTokenInfo>(StringComparer.OrdinalIgnoreCase)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is our guidance on explicit vs. inferred types?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should use type inference where it is possible. In this case, because the test class should be able to handle any usage for any type, it is required to explicitly type the input dictionary.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in the declaration. It doesn't really need to be the interface type, correct?


public IHttpOperations<T> WithHeader(string name, IEnumerable<string> value)
{
return this;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this throw?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because we simply aren't using headers in the test operations factory, but it should allow specifying headers in any code that uses it.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 ... maybe a comment indicating as much?

{
return "ManagedService";
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These can all be expression-bodied members. E.g.,

public string LoginType => "ManagedService"

Copy link
Member Author

Choose a reason for hiding this comment

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

These are implementing an interface

Copy link
Contributor

Choose a reason for hiding this comment

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

That will work, I think? 😄

An expression-bodied member is equivalent to a public get;...? Maybe?


if (string.IsNullOrWhiteSpace(tenant))
{
tenant = environment.AdTenant?? "Common";
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the null-coalesce operator is typically spaced on both sides like the ternary (?:) operator.


public async Task DeleteAsync(string requestUri, CancellationToken token)
{
await SafeSendRequestAsync(new HttpRequestMessage(HttpMethod.Delete, requestUri), token);
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be more succinct as:

public Task Func()
{
    return ThingyThatReturnsATaskAsync();
}

{
var exception = new HttpRequestException(string.Format("Unexpected response status code '{0}' received for request '{{{1} {2}}} Body: {{{3}}}",
response.StatusCode, request.Method, request.RequestUri, response.Content.ReadAsStringAsync().GetAwaiter().GetResult()));
ServiceClientTracing.Error(invocationId, exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to not use string interpolation?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, but this should probably be a string resource, anyway

@@ -257,7 +258,7 @@ public static string GetHttpResponseLog(string statusCode, IDictionary<string, I
httpResponseLog.AppendLine(string.Format("============================ HTTP RESPONSE ============================{0}", Environment.NewLine));
httpResponseLog.AppendLine(string.Format("Status Code:{0}{1}{0}", Environment.NewLine, statusCode));
httpResponseLog.AppendLine(string.Format("Headers:{0}{1}", Environment.NewLine, MessageHeadersToString(headers)));
httpResponseLog.AppendLine(string.Format("Body:{0}{1}{0}", Environment.NewLine, body));
httpResponseLog.AppendLine(string.Format("Body:{0}{1}{0}", Environment.NewLine, TransformBody(body)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for string interpolation.

twitchax
twitchax previously approved these changes Jan 6, 2018
Copy link
Contributor

@maddieclayton maddieclayton left a comment

Choose a reason for hiding this comment

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

A few small comments. Otherwise it all looks reasonable to me.

factory = HttpClientOperationsFactory.Create();
}

_tokenGetter = factory.GetHttpOperations<ManagedServiceTokenInfo>().WithHeader("Metadata", new[] { "true" });
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here if the if statement above evaluates to false? Do you need a null check?

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case, it uses the default implementation of HttpOperationsFactory, which just makes calls using HttpClient

@@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.Common.Authentication.Factories
{
public class AuthenticationFactory : IAuthenticationFactory
{
public const string CommonAdTenant = "Common";
public const string CommonAdTenant = "Common", DefaultMSILoginUri = "http://localhost:50342/oauth2/token";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the default really a localhost? Just curious, I don't entirely understand how MSI works.

Copy link
Member Author

Choose a reason for hiding this comment

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

@maddieclayton Yes, the default is always localhost - it is hosted on a VM at the loopback address.

[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### ManagedServiceLogin
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an example for the new login

Copy link
Member Author

Choose a reason for hiding this comment

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

done

maddieclayton
maddieclayton previously approved these changes Jan 17, 2018
@markcowl markcowl removed their assignment Jan 17, 2018
@maddieclayton
Copy link
Contributor

@maddieclayton
Copy link
Contributor

@azuresdkci Test this please

1 similar comment
@maddieclayton
Copy link
Contributor

@azuresdkci Test this please

@markcowl
Copy link
Member Author

markcowl commented Jan 19, 2018

@maddieclayton maddieclayton removed their assignment Jan 19, 2018
@maddieclayton maddieclayton merged commit 03f08dd into Azure:preview Jan 19, 2018
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.

5 participants