最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - NamedPipeClientStream getting permissioned denied even though I can open the FIFO file as a File stream without issue - Sta

programmeradmin1浏览0评论

I have a process on linux that creates a named pipe (FIFO file), then runs a dotnet app, which attempts to read from that named pipe using the NamedPipeClientStream class.

The named pipe is created with the permissions below (names changed for 'its the internet' purposes)

stat myNamedPipe.ext
  File: myNamedPipe.ext
  Size: 0               Blocks: 0          IO Block: 4096   fifo
Device: 802h/2050d      Inode: 117564614   Links: 1
Access: (0640/prw-r-----)  Uid: (10037/    A-user)   Gid: (10038/    b-user)
Context: system_u:object_r:home_root_t:s0
Access: 2025-03-03 18:52:38.393875788 +0000
Modify: 2025-03-03 18:52:38.393875788 +0000
Change: 2025-03-03 18:52:38.393875788 +0000
 Birth: 2025-03-03 18:52:38.393875788 +0000

Dotnet is then ran via dotnet MyNamedPipeReader.dll - and runs under the b-user account

(I've confirmed that with ps aux | grep dotnet and I've also ran ps -u b-user which also returns my dotnet process)

So to summarise

  • FIFO file has permissions 0640/prw-r----- for user b-user
  • dotnet is running my program as b-user.

Now when I attempt to read from the named pipe I get this exception

Failed to connect to named pipe '/full/path/to/MyNamedPipe.ext'. 
System.Net.Sockets.SocketException (13): Permission denied /full/path/to/MyNamedPipe.ext

Here is the code I am using to connect to the named pipe

using var namedPipeClientStream = new NamedPipeClientStream(".", pipeName, PipeDirection.In);
namedPipeClientStream.Connect(); //throws here
Console.WriteLine($"Connected to {pipeName}");
using var reader = new StreamReader(namedPipeClientStream);
while (reader.ReadLine() is { } line)
{
    Console.WriteLine(line);
}

Now if I just read the named pipe like a file

using var pipeStream = File.OpenRead(pipeName);
using var reader = new StreamReader(pipeStream);
while (reader.ReadLine() is { } line)
{
    Console.WriteLine(line);
}

It works without issue.

Am I doing something wrong here? Or is there something more peculiar going on?

Thanks!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论