Skip to content

Add-AzureAnalysisServicesAccount to support login with Service Principal #4389

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 6 commits into from
Aug 5, 2017

Conversation

liangyong79
Copy link
Contributor

@liangyong79 liangyong79 commented Jul 31, 2017

( both using password and certificate )

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.

@msftclas
Copy link

@liangyong79,
Thanks for your contribution as a Microsoft full-time employee or intern. You do not need to sign a CLA.
Thanks,
Microsoft Pull Request Bot

@azuresdkci
Copy link

Can one of the admins verify this patch?

@cormacpayne
Copy link
Member

@azuresdkci add to whitelist

Copy link
Member

@cormacpayne cormacpayne left a comment

Choose a reason for hiding this comment

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

@liangyong79 a few minor comments. Also, please add tests for this new functionality so we can catch future regressions. You can view the Profile login tests for examples of how to test this functionality.

private const string ServicePrincipalWithCertificateParameterSet = "ServicePrincipalWithCertificateParameterSetName";

[Parameter(ParameterSetName = UserParameterSet,
Mandatory = true, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to", Position = 0)]
Copy link
Member

Choose a reason for hiding this comment

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

@liangyong79 RolloutEnvironment is being changed from optional to mandatory, which is a breaking change. Please make sure the parameters (RolloutEnvironment and Credential) in the previous parameter set have the same attributes in UserParameterSet as they did in the old one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually this RolloutEnvironment is required even in previous version, they just forget to mark it as required.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is true. You can log in currently as a user without this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Mandatory = true)]
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet,
Mandatory = true)]
public SwitchParameter ServicePrincipal { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

@liangyong79 this parameter doesn't seem to provide any value since the presence of TenantId, ApplicationId or CertificateThumbprint signify that you using one of the ServicePrincipal parameter sets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will make it clear that ServicePrincipal will be used, and also the other Add-AzureRmAccount used the same parameter for SPN: https://docs.microsoft.com/en-us/powershell/module/azurerm.profile/add-azurermaccount?view=azurermps-4.2.0

@@ -33,14 +33,49 @@ namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane
[OutputType(typeof(AsAzureProfile))]
public class AddAzureASAccountCommand : AzurePSCmdlet, IModuleAssemblyInitializer
{
[Parameter(Position = 0, Mandatory = false, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to")]
Copy link
Member

Choose a reason for hiding this comment

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

@liangyong79 now that there are multiple parameter sets used in this cmdlet, there will need to be a DefaultParameterSetName defined at the top (inside of the Cmdlet attribute). I would recommend using UserParameterSet as the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -32,12 +45,38 @@ This example will add the account specified by the $UserCredential variable to t

## PARAMETERS

### -ApplicationId
SPN```yaml
Copy link
Member

Choose a reason for hiding this comment

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

@liangyong79 please make sure that the ```yaml strings appear on a line by themselves so the markdown gets rendered properly. You can look at the Credential parameter below for an example.

This change should be made for all parameters with this issue in this file.

Also, can we change "SPN" to be a more meaningful description?

@@ -62,6 +113,34 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -ServicePrincipal
{{Fill ServicePrincipal Description}}
Copy link
Member

Choose a reason for hiding this comment

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

@liangyong79 please fill out this description if you decide to keep this parameter

@@ -129,6 +129,10 @@
<Project>{70527617-7598-4aef-b5bd-db9186b8184b}</Project>
<Name>Commands.Common.Authentication.Abstractions</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Common\Commands.Common.Authentication\Commands.Common.Authentication.csproj">
Copy link
Member

Choose a reason for hiding this comment

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

This is problematic. Since you are using ADAL directly, you should not include a dependency on this library. This will cause problems when the ADAL library is updted in the runtime.

@@ -123,6 +173,7 @@ public void OnImport()
{
try
{
AzureSessionInitializer.InitializeAzureSession();
Copy link
Member

Choose a reason for hiding this comment

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

Do not add this - this potentially causes problems for all Azure RM modules, because you are taking chanreg of injecting depednencies used by all modules. If your cmdlet needs to use AzureSession, then it shoudl use the existing authentication mechanism. If it does not, then it should not initialize it.

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 base class AzurePSCmdlet.BeginProcessing() call SetupDebuggingTraces(), which call DebugStreamTraceListener.AddAdalTracing( ), and AddAdalTracing( ) require that AzureSession.Instance not be null:

public static void AddAdalTracing(DebugStreamTraceListener listener)
{
AzureSession.Instance.AuthenticationTraceListeners.Add(listener);
AzureSession.Instance.AuthenticationTraceSourceLevel = SourceLevels.All;
}

Copy link
Contributor Author

@liangyong79 liangyong79 left a comment

Choose a reason for hiding this comment

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

Addressed the review comments, please take a look again.

Mandatory = true)]
[Parameter(ParameterSetName = ServicePrincipalWithCertificateParameterSet,
Mandatory = true)]
public SwitchParameter ServicePrincipal { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will make it clear that ServicePrincipal will be used, and also the other Add-AzureRmAccount used the same parameter for SPN: https://docs.microsoft.com/en-us/powershell/module/azurerm.profile/add-azurermaccount?view=azurermps-4.2.0

@@ -123,6 +173,7 @@ public void OnImport()
{
try
{
AzureSessionInitializer.InitializeAzureSession();
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 base class AzurePSCmdlet.BeginProcessing() call SetupDebuggingTraces(), which call DebugStreamTraceListener.AddAdalTracing( ), and AddAdalTracing( ) require that AzureSession.Instance not be null:

public static void AddAdalTracing(DebugStreamTraceListener listener)
{
AzureSession.Instance.AuthenticationTraceListeners.Add(listener);
AzureSession.Instance.AuthenticationTraceSourceLevel = SourceLevels.All;
}

@cormacpayne cormacpayne changed the base branch from preview to release-4.3.0 August 4, 2017 16:03
private const string ServicePrincipalWithCertificateParameterSet = "ServicePrincipalWithCertificateParameterSetName";

[Parameter(ParameterSetName = UserParameterSet,
Mandatory = true, HelpMessage = "Name of the Azure Analysis Services environment to which to logon to", Position = 0)]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is true. You can log in currently as a user without this

@markcowl
Copy link
Member

markcowl commented Aug 4, 2017

@taiwu
Copy link
Contributor

taiwu commented Aug 5, 2017

According to the log, the build failed due to no work space for the build.

@markcowl
Copy link
Member

markcowl commented Aug 5, 2017

@azuresdkci retest this please

@markcowl
Copy link
Member

markcowl commented Aug 5, 2017

@markcowl markcowl dismissed cormacpayne’s stale review August 5, 2017 01:38

All comments addressed

@liangyong79
Copy link
Contributor Author

Ondemand build 1818 passed. :)

@markcowl markcowl merged commit 497a8de into Azure:release-4.3.0 Aug 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants