title: Running with Packet Capture Permissions under Stack
body: <p>Not sure if this is more appropriate for <a href="https://serverfault.com/">Server Fault</a> so apologies if this is the case.</p>
  
  <p>I am currently trying to capture packets using the <a href="https://hackage.haskell.org/package/pcap-0.4.5.2/docs/Network-Pcap.html" rel="nofollow noreferrer">Network.Pcap</a> library and have written this wrapper function around it:</p>
  
  <pre><code>getRawPacket :: IO B.ByteString
  getRawPacket = do
      deviceName &lt;- lookupDev
      handle &lt;- openLive deviceName 2048 False (-1) 
      setDirection handle Out
      nextBS handle &gt;&gt;= (\(_,p) -&gt; return p)
  </code></pre>
  
  <p>I am using <a href="https://docs.haskellstack.org/en/stable/README/" rel="nofollow noreferrer">stack</a> to manage the build process. When trying to run <code>getRawPacket</code> in ghci, starting it using <code>sudo stack ghci --allow-different-user</code>, I get expected packet data back. However while running as a normal user e.g. <code>testuser</code> in this example,
  I get back the following message:</p>
  
  <pre><code>*Main Pcs.Capture&gt; getRawPacket
  *** Exception: user error (enp0s25: You don't have permission to capture on that device (socket: Operation not permitted))
  </code></pre>
  
  <p>I have followed the steps on <a href="http://daydreamer66.blogspot.co.uk/2014/06/rhel-how-can-non-root-users-can-run.html" rel="nofollow noreferrer">this blog post</a> but these haven't made any difference. Is it possible to give linux permissions to stack(/testuser/ghc?) to allow it to perform packet operations through ghci?</p>
  
  <p>Also when producing a standalone executable with stack, how can I ensure that the executable can carry out packet capture? How could I apply these permissions as part of the build process?</p>