Skip to content
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

Unix domain socket binding on WCF Client #5172

Merged
merged 4 commits into from
Oct 24, 2023
Merged

Conversation

birojnayak
Copy link
Contributor

Phase 1 ensuring no auth and posix identity works

@birojnayak birojnayak marked this pull request as ready for review June 26, 2023 19:17
@mconnew
Copy link
Member

mconnew commented Sep 12, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

<value>The specified channel type {0} is not supported by this channel manager.</value>
</data>
<data name="TcpConnectError" xml:space="preserve">
<value>Could not connect to {0}. TCP error code {1}: {2}. </value>
Copy link
Member

Choose a reason for hiding this comment

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

Are the string resources that start with Tcp used? If so, they should probably be renamed and the message modified.

public class UnixDomainSocketBinding : Binding
{
//private OptionalReliableSession _reliableSession;
// private BindingElements
Copy link
Member

Choose a reason for hiding this comment

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

This binding is to provide similar capabilities to NetNamedPipe so won't ever support reliable sessions. Remove the commented out reliable sessions fields.

}

public UnixDomainSocketBinding(string configurationName)
: this()
Copy link
Member

Choose a reason for hiding this comment

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

Remove this method. It's only in the other bindings for legacy reasons. This is a new type so no need to start with this unsupported constructor.

_transport = new UnixDomainSocketTransportBindingElement();
_encoding = new BinaryMessageEncodingBindingElement();
//_session = new ReliableSessionBindingElement();
// _reliableSession = new OptionalReliableSession(_session);
Copy link
Member

Choose a reason for hiding this comment

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

Cleanup reliable sessions commented code


// add security (*optional)
//SecurityBindingElement wsSecurity = CreateMessageSecurity();
//if (wsSecurity != null)
Copy link
Member

Choose a reason for hiding this comment

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

We likely won't ever want to support message security as NetNamedPipe doesn't.


/*
private SecurityBindingElement CreateMessageSecurity()
{
Copy link
Member

Choose a reason for hiding this comment

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

Remove

{
None,
Default ,
Certificate ,
Copy link
Member

Choose a reason for hiding this comment

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

Fix formatting

}

internal BindingElement CreateTransportProtectionOnly()
{
Copy link
Member

Choose a reason for hiding this comment

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

This method should be used when SecurityMode is Transport and ClientCredentialType is None. We still need to secure the connection use TLS, we just don't provide a client certificate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

return CreatePosixIdentityOnlyBinding();
}
}else if (_clientCredentialType == UnixDomainSocketClientCredentialType.Certificate )
{
Copy link
Member

Choose a reason for hiding this comment

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

Formatting

}

internal bool InternalShouldSerialize()
{
Copy link
Member

Choose a reason for hiding this comment

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

Remove, this was used when writing out the binding to config and would be used to know if it was using defaults or not. If using defaults, no need to write it out to the xml. This is left over dead code.

if (!IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidEnumArgumentException("value", (int)value,
typeof(SslProtocols)));
Copy link
Member

Choose a reason for hiding this comment

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

nameof(value)

internal static class ConnectionOrientedTransportDefaults
{
//public const bool AllowNtlm = SspiSecurityTokenProvider.DefaultAllowNtlm;
//public const int ConnectionBufferSize = 8192;
Copy link
Member

Choose a reason for hiding this comment

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

Remove unused commented members

using System.Runtime.CompilerServices;

[assembly:TypeForwardedTo(typeof(System.ServiceModel.Channels.ConnectionOrientedTransportBindingElement))]
[assembly:TypeForwardedTo(typeof(System.ServiceModel.Channels.SslStreamSecurityBindingElement))]
Copy link
Member

Choose a reason for hiding this comment

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

You don't need these. These were in nettcp to tell existing code that these types had been moved from nettcp to NetFramingBase, which is not for case for UDS


[DefaultValue(Net.Security.ProtectionLevel.EncryptAndSign)]
public ProtectionLevel ProtectionLevel
{
Copy link
Member

Choose a reason for hiding this comment

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

I thought we removed this from the service side? This binding element doesn't do any encryption or signing of the data transmitted so it doesn't make sense to have it. If it's still there on the service side, please open an issue to remove it there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tracking here on the server side CoreWCF/CoreWCF#1214 (comment) and removing client

internal IdentityVerifier IdentityVerifier { get; private set; }

public ProtectionLevel ProtectionLevel { get; }

Copy link
Member

Choose a reason for hiding this comment

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

Remove

return null;;
}
public override string GetNextUpgrade()
{
Copy link
Member

Choose a reason for hiding this comment

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

Formatting. Need a blank line between methods.

private class UnixPosixIdentitySecurityUpgradeInitiator : StreamSecurityUpgradeInitiator
{
string upgradeString = UnixPosixUpgradeString;
public UnixPosixIdentitySecurityUpgradeInitiator()
Copy link
Member

Choose a reason for hiding this comment

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

Missing acessor modifier (private). Naming convention should begin with _

internal static class UnsafeNativeMethods
{
//public const int ERROR_SUCCESS = 0;
//public const int ERROR_FILE_NOT_FOUND = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Remove unused commented values

@mconnew
Copy link
Member

mconnew commented Sep 12, 2023

Now that CoreWCF UDS has been released, can you add a scenario test. The folder for them is under the System.Private.ServiceModel\tests\Scenario folder

@mconnew
Copy link
Member

mconnew commented Oct 5, 2023

Feedback from our call, we need to introduce a new security mode similar to BasicHttpSecurityMode.TransportCredentialOnly to use the Posix identity client credential type. This is because security mode Transport is intended to have the connection have integrity and confidentiality which the Posix credential type doesn't provide. We could potentially add support for using the posix identity with Ssl (service side certificate only) later if there's demand.

{
private UnixDomainSocketTransportBindingElement _transport;
private BinaryMessageEncodingBindingElement _encoding;
// private ReliableSessionBindingElement _session;
Copy link
Member

Choose a reason for hiding this comment

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

Remove commented line

{
internal const SecurityMode DefaultMode = SecurityMode.Transport;

private SecurityMode _mode;
Copy link
Member

Choose a reason for hiding this comment

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

Need to create a UDS specific enum for this as we aren't supporting Message or TransportWithMessageCredentials. See NetNamedPipeSecurityMode Enum docs.

Copy link
Member

Choose a reason for hiding this comment

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

This also goes with my comment here where we need TransportCredentialOnly for IdentityOnly

Certificate,
Windows,
IdentityOnly,
}
Copy link
Member

Choose a reason for hiding this comment

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

As we're making a change to add a TransportCredentialOnly security mode, I don't think Only needs to be on here now. Also as it's now clearly only for *nix based systems like mac and Linux, I think PosixIdentity would be clearer, or maybe just Posix as we have just "Windows"

private UnixDomainSocketSecurityMode _mode;

public UnixDomainSocketSecurity()
{
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this inline, make DefaultMode a private static field and use the original constructor. Then you can use the default mode in the exception message of the private constructor

if (_mode == UnixDomainSocketSecurityMode.Transport || _mode == UnixDomainSocketSecurityMode.TransportCredentialOnly)
{
if(_mode == UnixDomainSocketSecurityMode.TransportCredentialOnly && Transport.ClientCredentialType != UnixDomainSocketClientCredentialType.PosixIdentity)
{
Copy link
Member

Choose a reason for hiding this comment

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

Also throw when _mode it Transport and credential type is PosixIdentity as it should only be used for TransportCredentialOnly

@mconnew mconnew merged commit 6a652f6 into dotnet:main Oct 24, 2023
8 checks passed
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.

2 participants