-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Authentication Parameter to Web Cmdlets for Basic and OAuth #5052
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
Add Authentication Parameter to Web Cmdlets for Basic and OAuth #5052
Conversation
24d2207 to
882da03
Compare
We could write non-terminating error or just terminating error w/o explicitly Why 'Authorization' ? |
iSazonov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markekraus Great work!
| } | ||
| else | ||
| { | ||
| Debug.Assert(false, String.Format("Unrecognized Authorization value: {0}", Authorization)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use Diagnostics.Assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix. Any idea why VS Code gives me this 'Diagnostics' is inaccessible due to its protection level [Microsoft.PowerShell.Commands.Utility]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the 'Diagnostics' is defined in another assembly SDK but we have InternalsVisibleTo in AssemblyInfo.cs - VS Code is still stuped here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining. This is fixed.
| { | ||
| _authorization = value.ToLower(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should use autoproperty and new public enum type for "Basic","Bearer","OAuth" - 'AuthorizationHeaderEnum' .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoproperty? Please let me know what this is.
As for the new Public Enum. I was following suit with -TransferEncoding which doesn't have a public enum. I'm open to creating one, but I assume this requires committee approval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/auto-implemented-properties
Yes, public API should be approved. I believe it is right place to use it.
| public virtual SwitchParameter SkipCertificateCheck { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// gets or sets the Token property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more detailed description is welcomed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
| [Parameter] | ||
| public virtual SwitchParameter AllowUnencryptedAuthorization { get; set; } | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more detailed description is welcomed.
Please add about correlation with other parameters from PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
|
|
||
| It "Verifies Invoke-WebRequest -Authorization <authorization>" -TestCases @( | ||
| @{ authorization = "bearer"} | ||
| @{ authorization = "OAuth"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting (spaces).
We use it twice - please move to BeforeAll. Below too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
I considered that but I wasn't sure if that should be done in this PR or something separate. This PR is adding new features only without altering existing behavior. It's still not clear to me what is too much for one PR and what is not.
I would take that up with IETF. They are the crazy ones that decided that Authorization is the correct term here regardless of what the dictionary begs to differ. 😆 I think '-AllowUnencryptedAuthentication' How about '-AllowUnencryptedSecrets'? Assuming there may be more uses outside of the 'Authorization'. I wouldn't want to have |
|
Travis CI fail due to #5062 |
|
I believe that the use of |
|
What is the consensus on the parameter names? leave them? change them? |
|
I think adding "HeaderType" is more of an impl detail than the average user will care about. And while the header is named Authorization, in articles and papers the overall process is referred to as |
|
To be consistent with other cmdlets, I think we should call it |
|
I agree with @SteveL-MSFT - really a client do an authentication. |
|
Ok. I have switch Authorization with Authentication, @SteveL-MSFT @iSazonov can I get some guidance on the public enum for the |
|
I think an enum is good because we rid from many string constants and string comparitions, our code becomes more readable. I only worry about extensibility. @markekraus Please correct the PR header and description (Authentication). |
Then we would probably need to include logic that limits the subsets allowed by the authentication parameter. For example, if this enum were used in another cmdlet and it was extended to include |
|
It's overkill. I mean, this is a public type and users can use it. Although it may be better to mark it as obsolete and document that it is for internal use only. |
c642774 to
98f2201
Compare
|
@iSazonov I guess it is overkill. I looked a how other enums are being implemented for parameter options and have tried to follow their conventions. I chose the name @SteveL-MSFT is a comittee review required for the new public enum or is your blessing good enough? @iSazonov and @SteveL-MSFT the other outstanding question in this PR is to add a warning to the legacy |
|
You can add one commit for the warning :-) |
|
@markekraus I'll see if I can get a quick committee review on this |
| { | ||
| if (Uri.Scheme != "https" && !AllowUnencryptedAuthentication) | ||
| { | ||
| WriteWarning(WebCmdletStrings.UnencryptedCredentialWarning); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe WriteError()? It seems we never use WriteWarning().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this is what ConvertTo-SecureString does if -AsPlainText is used without -Force:
2:8ms> $ss = ConvertTo-SecureString "mypassword" -AsPlainText
ConvertTo-SecureString : The system cannot protect plain text input. To suppress this warning and convert the plain
text to a SecureString, reissue the command specifying the Force parameter. For more information ,type: get-help
ConvertTo-SecureString.
At line:1 char:7
+ $ss = ConvertTo-SecureString "mypassword" -AsPlainText
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertTo-SecureString], ArgumentException
+ FullyQualifiedErrorId : ImportSecureString_ForceRequired,Microsoft.PowerShell.Commands.ConvertToSecureStringComm
and
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iSazonov I think an error would be a breaking change here. Recall this piece of code is not part of the new -Authentication parameter, but part of the legacy -Credential usage. If we want this an error here, I will revert and that can be done in a separate PR. If we are going to break it, the better way, IMO, is to remove the legacy usage and have it be completely replaced with the new usage and removing the legacy -Credential usage has some cleanup associated with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the PR is near to merge. I think we shouldn't block it - please revert and open tracking Issue to discuss "warning", "removing" and "force".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe error error with the new -Auth Basic (no -AllowUnen) scenario but not the existing -Credential (no -AllowUnen)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkeithhill that is already part of this PR 😄 the new method is terminating errors when you tery to use non-HTTPS and can only be suppressed with -AllowUnencryptedAuthentication.
This piece of code that this comment thread is on was just to add some more whining to the legacy -Credential usage which has always casually let you send credentials over HTTP with out so much as a peep.
@iSazonov #5112 for the this. I have reverted that commit (with the exception of the minor spelling fix I the other tests in this PR)
|
@PowerShell/powershell-committee brief discussion is that adding an enum used as a parameter type doesn't require committee approval, code review feedback is sufficient. The current name and namespace seems appropriate to me. |
| /// Basic: Requires Credential | ||
| /// OAuth/Bearer: Requires Token | ||
| /// </summary> | ||
| [Parameter] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assign default WebAuthenticationType.None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think ther is a need, The enum is never null so its creation here automatically sets it to None since it is the first enum value... at least.. if i understand everything I read correctly. If it wasn't automatically None, all of the many tests would be failing. Unless setting it here provides some kind of emit somewhere. I didin't see any other enum parameters setting a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If internal logic is based on None we should initialize explicitly to None (Can we sort the enum or add new element on first position?). Another way is to being based on Authentication.IsPresent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
|
@markekraus Thanks for your contribution. I'll allow 24 hours for the code owners to review. @dantraMSFT , @PaulHigin , & @JamesWTruher |
|
|
||
| #region Authorization and Credentials | ||
|
|
||
| /// <summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please replace "gets" -> "Gets"?
Although the old comments start with a small letter, the new ones are already capital. In this case, it's better to follow our rules and use the capital letter.
| public virtual SwitchParameter SkipCertificateCheck { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// gets or sets the Token property. Token is required by Authentication OAuth and Bearer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same "get" -> "Gets".
| <value>Access to the path '{0}' is denied.</value> | ||
| </data> | ||
| <data name="AllowUnencryptedAuthenticationRequired" xml:space="preserve"> | ||
| <value>The cmdlet cannot protect plain text secrets sent over unencrypted connections. To supress this warning and send plain text secrets over unencrypted networks, reissue the command specifying the AllowUnencryptedAuthentication parameter.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is more readable to put parameter names in single quotes AllowUnencryptedAuthentication ...
We use the format in other Resx files.
Please edit messages below too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a mix, from what I have seen, of quoted, unquoted and Hyphen prepended in the project. Since there is no clear set standard, I went with the style used for the Web Cmdlets. Please look at the errors in this Resx. I would rather have a separate PR to address the errors styles as whole for these commands than have a few that do not match in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Could you please open a tracking issue (or PR)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could.. but I think another Issue on standardizing how parameters are displayed in errors within the project is probably warranted first. I'd hate to go through the trouble of changing these error and then have the current way be later selected as the standard (I would hope it's not, because I agree it's not very readable, but its possible). thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
😄 I've been dragged the PR. |
Closes #4274
-Authenticationparameter toInvoke-RestMethodandInvoke-WebRequest-Tokenparameter toInvoke-RestMethodandInvoke-WebRequest-AllowUnencryptedAuthenticationparameter toInvoke-RestMethodandInvoke-WebRequest-Authorizationuses-AuthenticationParameter has 3 options:Basic,OAuth, andBearerBasicrequires-Credentialand provides RFC-7617 Basic Authorization credentials to the remote serverOAuthandBearerrequire the-Tokenwhich is a SecureString containing the bearer token to send to the remote server-AllowUnencryptedAuthenticationswitch to bypass this behavior and send their secrets unencrypted at their own risk.-Authenticationdoes not work with-UseDefaultCredentialsand will result in an error.The existing behavior with
-Credentialis left untouched. When not supplying-Authentication, A user will not receive an error when using-Credentialover unencrypted connections.Code design choice is meant to accommodate more Authentication types in the future.
Documentation Needed
The 3 new parameters will need to be added to the
Invoke-RestMethodandInvoke-WebRequestdocumentation along with examples. Syntax will need to be updated.