Skip to content

Conversation

@msJinLei
Copy link
Contributor

@msJinLei msJinLei commented Nov 19, 2021

The PR is to fix #15427

Service principal secret and service principal certificate are required for service principal user to access Azure resources.
Previously PowerShell can access the plain text values of service principal secret and service principal certificate password using

- (Get-AzContext).Accounts.ExtendedProperties.ServicePrincipalSecret
- (Get-AzContext).Accounts.ExtendedProperties.CertificatePassword

To improve the security, the PR removes the these 2 attributes from (Get-AzContext).Accounts, whose type is PSAzurerRmAccount.

After the change, the context object retrieved by Get-AzContext no longer has ServicePrincipalSecret and CertificatePassword. The cmdlet Set-AzContext, Rename-AzContext accept context object as the input, which brings the risk that the context without ServicePrincipalSecret and CertificatePassword will be added into context list and even be set as current context and then break the current environment.

To solve the issue, the PR also changes the logic when new context object is added to the context list. Firstly find whether there is an existing object with the same account id, tenant and subscription. If found, merge the attributes in the existing one but absent in the new one to the new one and then add the new one to the context list.

Description

Checklist

  • I have read the Submitting Changes section of CONTRIBUTING.md
  • The title of the PR is clear and informative
  • The appropriate ChangeLog.md file(s) has been updated:
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header -- no new version header should be added
  • The PR does not introduce breaking changes
  • If applicable, the changes made in the PR have proper test coverage
  • For public API changes to cmdlets:
    • a cmdlet design review was approved for the changes in this repository (Microsoft internal only)
      • {Please put the link here}
    • the markdown help files have been regenerated using the commands listed here

@msJinLei msJinLei force-pushed the secret branch 3 times, most recently from 64b7ec6 to 20bd3e9 Compare November 24, 2021 09:34
@msJinLei msJinLei marked this pull request as ready for review November 24, 2021 09:45
@msJinLei msJinLei changed the title Remove secrets of PSAzurerRmAccount from display Remove secrets in PSAzurerRmAccount from display Nov 24, 2021
-->

## Upcoming Release
* Removed `ServicePrincipalSecret` and `CertificatePassword` in Account of Context from display [#15427]
Copy link
Member

Choose a reason for hiding this comment

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

from display or we have removed them from Azure Context psobject? I remember it is latter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 2 classes that relate to Account of Context in Az.Accounts, AzureAccount is for internal use and PSAzureRmAccount is for powershell operation. The PR just removes ServicePrincipalSecret and CertificatePassword from PSAzureRmAccount.

@isra-fel
Copy link
Member

/azp run azure-powershell - windows-powershell

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

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.

ServicePrincipalSecret exposed as plain text in memory

3 participants