Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Nov 21, 2019

PR Summary

Fix #11067

PR Checklist

@vexx32 vexx32 added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 21, 2019
Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

LGTM

@TravisEz13
Copy link
Member

should this be marked as rc.1-consider milestone?

@SteveL-MSFT
Copy link
Member Author

Need to update PR based on @PowerShell/powershell-committee decision that -Force on ConvertTo-SecureString shouldn't be mandatory

@SteveL-MSFT SteveL-MSFT added this to the rc.1-consider milestone Dec 5, 2019
@SteveL-MSFT
Copy link
Member Author

Codacy appears to be wrong, VSCode complains if I remote the assignment since the finally block may use an unassigned variable.

@KirkMunro
Copy link
Contributor

KirkMunro commented Dec 5, 2019

I think removing the hard requirement for -Force when using ConvertTo-SecureString -AsPlainText is a bad idea. I also think ConvertFrom-SecureString -AsPlainText should require -Force to use it.

The reason is really simple: someone looking for how to perform such a task in PowerShell is -Forced to consider the ramifications/risk and think twice about what they are trying to do (there may be a more secure way to do so).

Ease of use is less important than guiding scripters towards a better understanding of the security implications when working with plain-text passwords in scripts.

People are lazy. Make it too easy for them, and they'll take the easy way without thinking about why they shouldn't do that.

Also, FWIW, if the @PowerShell/powershell-committee thinks -Force shouldn't be mandatory in this case, I would like that put in front of the PowerShell Community at large via an RFC rather than just forced in quietly.

@rkeithhill
Copy link
Collaborator

rkeithhill commented Dec 5, 2019

What's the point on non-Windows platforms where "SecureString" is a bit of a lie anyway? Requiring -Force on those platforms would be misleading IMO because those strings aren't really that secure. See https://docs.microsoft.com/en-us/dotnet/api/system.security.securestring?view=netcore-3.0#HowSecure and the recommendation to not use this type anymore: https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md

That said, once we get the Secrets management module, I don't see the *-SecureString cmdlets being that useful anymore.

guiding scripters towards a better understanding of the security implications guiding scripters towards a better understanding of the security implications

Wouldn't PSScriptAnalyzer serve this purpose better?

Represents text that should be kept confidential, such as by deleting it from computer memory when no longer needed. This class cannot be inherited.
GitHub
Roslyn analyzer that finds usages of APIs that will throw PlatformNotSupportedException on certain platforms. - dotnet/platform-compat

@KirkMunro
Copy link
Contributor

KirkMunro commented Dec 5, 2019

What's the point on non-Windows platforms where "SecureString" is a bit of a lie anyway? Requiring -Force on those platforms would be misleading IMO because those strings aren't really that secure. See https://docs.microsoft.com/en-us/dotnet/api/system.security.securestring?view=netcore-3.0#HowSecure and the recommendation to not use this type anymore: https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md

In my mind it's not about SecureString and whether or not it is a bit of a lie since you can pull the text out of the string using APIs. It's about interactions between PowerShell and other things -- files on disk, credentials being sent in plain text over a connection, etc. Raising awareness of the potential risk with those type of activities is helpful, as is discouraging use of secrets in plain text.

That said, once we get the Secrets management module, I don't see the *-SecureString cmdlets being that useful anymore.

Agreed.

guiding scripters towards a better understanding of the security implications guiding scripters towards a better understanding of the security implications

Wouldn't PSScriptAnalyzer serve this purpose better?

PSScriptAnalyzer could and should raise warnings for various things related to plain text passwords, but that's only helpful if folks use PSSA. In my opinion, from a security/awareness perspective, pairing -AsPlainText with -Force is helpful.

@SteveL-MSFT
Copy link
Member Author

My motivation for adding this capability is specifically for Secrets Management module. Secrets Management will always return a SecureString type. You would use this cmdlet to convert to plain text, if needed. As for -Force, the discussion in @PowerShell/powershell-committee is that the noun SecureString is already an indicator that care should be taken when using these cmdlets. The user already has to specify -AsPlainText to get plain text. Having them also add a superfluous -Force is unnecessary and just adds to annoyance or worst invites users to add Force = true in PSDefaultParameters.

@rkeithhill
Copy link
Collaborator

Secrets Management will always return a SecureString type

Even though the CoreFx team is clearly recommending not to use this type for new development?

@SteveL-MSFT
Copy link
Member Author

SteveL-MSFT commented Dec 5, 2019

@rkeithhill Until corefx provides a SensitiveString type to replace SecureString, we still need a type that doesn't implement ToString() and dump the contents accidentally to a transcript or the screen. And it doesn't make sense for PowerShell to define its own type for this purpose.

@KirkMunro
Copy link
Contributor

KirkMunro commented Dec 5, 2019

As for -Force, the discussion in @PowerShell/powershell-committee is that the noun SecureString is already an indicator that care should be taken when using these cmdlets. The user already has to specify -AsPlainText to get plain text. Having them also add a superfluous -Force is unnecessary and just adds to annoyance or worst invites users to add Force = true in PSDefaultParameters.

For the uncommon occurrence where you want to convert plain text into a SecureString, requiring -Force isn't superfluous. It's a safety precaution -- a reminder to think twice about what you're doing. And it only requires 6 extra characters.

When you say it's unnecessary and just adds to annoyance or invites users to add $PSDefaultParameterValues['ConvertTo-SecureString:Force'] = $true, do you have evidence that users are really annoyed by this or using $PSDefaultParameterValues to do that? There are zero open/closed issues in this GitHub repository complaining about ConvertTo-SecureString requiring -Force when it is used with -AsPlainText. Plus, when it comes to $PSDefaultParameterValues, by the time a user would apply a default value to change the way they invoke ConvertTo-SecureString when working with it interactively, they're likely knowledgeable enough that we should have no problem with them making that decision if they want to. I'm sure -Force might annoy a few people who don't want the reminder. I've spoken with others who appreciate the cmdlet drawing their attention to what they're doing.

@rkeithhill Until corefx provides a SensitiveString type to replace SecureString, we still need a type that doesn't implement ToString() and dump the contents accidentally to a transcript or the screen...

...or into a file as a stored secret, or pull plain text from a file to use as a secret. -Force in these scenarios helps discourage such accidents.

IMHO the change in behavior of -Force is out of scope for this PR, unjustified, and undesirable.

@adityapatwardhan
Copy link
Member

@TravisEz13 Is this ready to merge?

@adityapatwardhan adityapatwardhan merged commit 03f10f0 into PowerShell:master Dec 11, 2019
@SteveL-MSFT SteveL-MSFT deleted the convertfrom-securestring branch December 12, 2019 19:28
@ghost
Copy link

ghost commented Dec 16, 2019

🎉v7.0.0-rc.1 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Convert SecureString to string

8 participants