Skip to content

Commit 74a8eff

Browse files
wadepicketttdykstraJamesNK
authored
gRPC:PipeSecurity for Named Pipes (#35691)
* gRPC:PipeSecurity for Named Pipes * Update metadata tags * Corrected code fencing. * Fixed xref * fix xref * xref fix again * Added info on CreateNamedPipeServerStream * Fixed typo Endpoint * Removed xref link that does not exist * Update aspnetcore/grpc/interprocess-namedpipes.md Co-authored-by: Tom Dykstra <[email protected]> * Update aspnetcore/grpc/interprocess-namedpipes.md Co-authored-by: James Newton-King <[email protected]> * Apply suggestions from JamesNK code review --------- Co-authored-by: Tom Dykstra <[email protected]> Co-authored-by: James Newton-King <[email protected]>
1 parent 8f0edaf commit 74a8eff

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

aspnetcore/grpc/interprocess-namedpipes.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ author: jamesnk
44
description: Learn how to use gRPC for inter-process communication with Named pipes.
55
monikerRange: '>= aspnetcore-8.0'
66
ms.author: wpickett
7-
ms.date: 01/18/2023
7+
ai-usage: ai-assisted
8+
ms.date: 08/01/2025
89
uid: grpc/interprocess-namedpipes
910
---
1011
# Inter-process communication with gRPC and Named pipes
@@ -47,6 +48,75 @@ The preceding example:
4748
* Calls `ListenNamedPipe` to listen to a named pipe with the specified name.
4849
* Creates a named pipe endpoint that isn't configured to use HTTPS. For information about enabling HTTPS, see [Kestrel HTTPS endpoint configuration](xref:fundamentals/servers/kestrel/endpoints#listenoptionsusehttps).
4950

51+
### Configuring PipeSecurity for Named Pipes
52+
53+
To control which users or groups can connect, use the [`NamedPipeTransportOptions`](xref:Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.NamedPipeTransportOptions) class. This allows a custom [`PipeSecurity`](xref:System.IO.Pipes.PipeSecurity) object to be specified.
54+
55+
Example:
56+
57+
```csharp
58+
using Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes;
59+
using System.IO.Pipes;
60+
using System.Security.AccessControl;
61+
62+
var builder = WebApplication.CreateBuilder(args);
63+
builder.WebHost.ConfigureKestrel(serverOptions =>
64+
{
65+
serverOptions.ListenNamedPipe("MyPipeName", listenOptions =>
66+
{
67+
listenOptions.Protocols = HttpProtocols.Http2;
68+
69+
// Configure PipeSecurity
70+
listenOptions.UseNamedPipes(options =>
71+
{
72+
var pipeSecurity = new PipeSecurity();
73+
// Grant read/write access to the Users group
74+
pipeSecurity.AddAccessRule(new PipeAccessRule(
75+
"Users",
76+
PipeAccessRights.ReadWrite,
77+
AccessControlType.Allow));
78+
// Add additional rules as needed
79+
80+
options.PipeSecurity = pipeSecurity;
81+
});
82+
});
83+
});
84+
```
85+
86+
The preceding example:
87+
88+
* Uses `UseNamedPipes` to access and configure <xref:Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.NamedPipeTransportOptions>.
89+
* Sets the <xref:System.IO.Pipes.PipeSecurity> property to control which users or groups can connect to the named pipe.
90+
* Grants read/write access to the `Users` group. Additional security rules can be added as needed for the scenario.
91+
92+
### Customize Kestrel named pipe endpoints
93+
94+
Kestrel's named pipe support enables advanced customization, allowing you to configure different security settings for each endpoint using the `CreateNamedPipeServerStream` option. This approach is ideal for scenarios where multiple named pipe endpoints require unique access controls. The ability to customize pipes per endpoint is available starting with .NET 9.
95+
96+
An example of where this is useful is a Kestrel app that requires two pipe endpoints with different access security. The `CreateNamedPipeServerStream` option can be used to create pipes with custom security settings, depending on the pipe name.
97+
98+
```csharp
99+
100+
var builder = WebApplication.CreateBuilder();
101+
builder.WebHost.ConfigureKestrel(options =>
102+
{
103+
options.ListenNamedPipe("pipe1");
104+
options.ListenNamedPipe("pipe2");
105+
});
106+
107+
builder.WebHost.UseNamedPipes(options =>
108+
{
109+
options.CreateNamedPipeServerStream = (context) =>
110+
{
111+
var pipeSecurity = CreatePipeSecurity(context.NamedPipeEndpoint.PipeName);
112+
113+
return NamedPipeServerStreamAcl.Create(context.NamedPipeEndpoint.PipeName, PipeDirection.InOut,
114+
NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte,
115+
context.PipeOptions, inBufferSize: 0, outBufferSize: 0, pipeSecurity);
116+
};
117+
});
118+
```
119+
50120
## Client configuration
51121

52122
`GrpcChannel` supports making gRPC calls over custom transports. When a channel is created, it can be configured with a <xref:System.Net.Http.SocketsHttpHandler> that has a custom <xref:System.Net.Http.SocketsHttpHandler.ConnectCallback>. The callback allows the client to make connections over custom transports and then send HTTP requests over that transport.

0 commit comments

Comments
 (0)