title: UNIX Socket permissions (Linux)
body: <p>I am using UNIX sockets in C to develop a server. From the manual:</p>
  
  <blockquote>
    <p>In the Linux implementation, sockets which are visible in the filesystem honor the per‐
           missions of the directory they are in.  Their owner, group and their permissions can be
           changed.  Creation of a new socket will fail if the process does  not  have  write  and
           search  (execute)  permission on the directory the socket is created in.  Connecting to
           the socket object requires read/write permission.  This behavior differs from many BSD-
           derived  systems  which  ignore permissions for UNIX domain sockets.  Portable programs
           should not rely on this feature for security.</p>
  </blockquote>
  
  <p>I have a path that is world writeable.</p>
  
  <pre><code>    $ ls -ld api
      drwxrwxrwx 2 root www-data 4096 Feb 15 21:57 api
  </code></pre>
  
  <p>A process under root creates a socket in this path:</p>
  
  <pre><code>    $  ls -l api/socket
      srwxr-xr-x 1 root root 0 Feb 15 21:57 api/socket
  </code></pre>
  
  <p>Another process that is running as a user cannot connect to the socket due to permissions issues. If I manually change socket permissions to be writeable by everyone, then other processes can successfully connect.</p>
  
  <ol>
  <li>Why parent permissions are not enough to make the socket writeable as the doc says?</li>
  <li>What is the best practice in that case? </li>
  </ol>