Skip to content

net.createConnection needs an option to set the permissions of a named pipe #30823

Description

@andrewhodel
  • Version:

13.3.0

  • Platform:

Linux

  • Subsystem:

Debian

If I were to create a "server" for IPC using a named pipe like:

const ipc_server = net.createServer((c) => {
        // 'connection' listener.
        console.log('ipc client connected');
        c.on('end', () => {
                console.log('ipc client disconnected');
        });
        c.write('hello\r\n');
        c.pipe(c);
});

ipc_server.listen('/tmp/collect.sock', () => {
        console.log('ipc connected at /tmp/pipe_name.sock');
});

There are permission issues if I am accessing that named pipe from a process which has a different linux profile permission mask than the user which started the server.

It would be really nice to just have the ability to set the permissions on the named pipe file when creating the server with net.createServer().

You get something like this when trying to connect to the named pipe in a process ran by a user with different permissions on his account.

ipc client error { Error: connect EACCES /tmp/pipe_name.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
  errno: 'EACCES',
  code: 'EACCES',
  syscall: 'connect',
  address: '/tmp/pipe_name.sock' }

Activity

  1. bnoordhuis commented on Dec 7, 2019

    @bnoordhuis
    Member

    No new API or option is necessary:

    const filename = '/tmp/collect.sock';
    server.listen(filename, () => {
      fs.chmod(filename, 0o666);
    });

    Node.js wouldn't be able to do any better because the UNIX APIs for creating a socket/named pipe don't let you set the permissions, it's always created with mode 0o666 & ~process.umask().

  2. added
    feature requestIssues requesting new Node.js features.
    netIssues and PRs related to the net subsystem.
    wontfixIssues that will not be fixed.
    on Dec 7, 2019
  3. andrewhodel commented on Dec 7, 2019

    @andrewhodel
    Author
  4. andrewhodel commented on Dec 7, 2019

    @andrewhodel
    Author
  5. bnoordhuis commented on Dec 7, 2019

    @bnoordhuis
    Member

    mkfifo is a wrapper around mknod(2) but that doesn't create a socket, only socket(2) does.

  6. andrewhodel commented on Dec 7, 2019

    @andrewhodel
    Author
  7. bnoordhuis commented on Dec 8, 2019

    @bnoordhuis
    Member

    So if you are using mknod to create a Unix socket

    Stop right there: you don't use mknod() to create UNIX sockets. Check man 2 mknod, you use it to create character and block devices, the files that usually live under /dev.

    a Unix socket, aka pipe or named pipe or fifo

    Those are all different things and covered by different system calls.

  8. andrewhodel commented on Dec 8, 2019

    @andrewhodel
    Author
  9. bnoordhuis commented on Dec 8, 2019

    @bnoordhuis
    Member

    Node.js does not use mkfifo(2)... I'm sorry but I don't know of a nicer way to phrase this: you're arguing from a position of ignorance here. Please educate yourself on the subject before you go on.

  10. andrewhodel commented on Dec 8, 2019

    @andrewhodel
    Author
  11. andrewhodel commented on Dec 8, 2019

    @andrewhodel
    Author
  12. bnoordhuis commented on Dec 8, 2019

    @bnoordhuis
    Member

    I already told you node uses socket(2) and a quick grep would have informed you that deps/uv/src/unix/pipe.c is the code you're interested in.

    And call me weird, but I always check the source code before I start making specific suggestions - that avoids the kind of pointless back-and-forth we just witnessed.

  13. andrewhodel commented on Dec 8, 2019

    @andrewhodel
    Author
  14. andrewhodel commented on Dec 8, 2019

    @andrewhodel
    Author
  15. bnoordhuis commented on Dec 8, 2019

    @bnoordhuis
    Member

    I think you may need to read more closely; that's F_GETFL, not F_SETFL. :-)

  16. andrewhodel commented on Dec 8, 2019

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.netIssues and PRs related to the net subsystem.wontfixIssues that will not be fixed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions