diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/host/default.nix | 16 | ||||
| -rw-r--r-- | modules/host/egress.lua | 4 |
2 files changed, 11 insertions, 9 deletions
diff --git a/modules/host/default.nix b/modules/host/default.nix index 1a9375e..7f46064 100644 --- a/modules/host/default.nix +++ b/modules/host/default.nix @@ -188,7 +188,7 @@ ${lib.concatMapStrings (t: " ${t.name}) user=${t.user} ;;\n") taps} fc-egress = pkgs.writeShellScriptBin "fc-egress" '' set -efu - export PATH=${lib.makeBinPath [ pkgs.bash pkgs.coreutils pkgs.findutils pkgs.gawk pkgs.gnugrep pkgs.systemd ]} + export PATH=${lib.makeBinPath [ pkgs.bash pkgs.coreutils pkgs.findutils pkgs.gawk pkgs.gnugrep pkgs.gnused pkgs.systemd ]} user=$(id -un) if ! test -d ${dir}/$user; then echo "fc-egress: $user has no VMs (see modules/host)" >&2 @@ -314,14 +314,16 @@ ${lib.concatMapStrings (t: " ${t.name}) user=${t.user} ;;\n") taps} printf '%s\n' "$2" > ${vmDir}/$tap ;; log) - # HTTPS connections: ALLOW|DENY, user, tap, list, server name, + # HTTPS connections: ALLOW|DENY, user, tap, list, https://SERVER, # guest, upstream, status, bytes sent and received (from the guest's # view: received, sent), seconds. Decrypted requests: ALLOW|DENY, - # user, tap, list, host, method, URI, status, bytes sent. Other - # connections (kernel log, rate-limited): fc-egress ALLOW|DENY, - # user, tap, and the packet. + # user, tap, list, method, https://HOST/URI, status, bytes sent. + # Other connections (kernel log, rate-limited): fc-egress + # ALLOW|DENY, user, tap, tcp://DST:DPT (or udp://; added here), and + # the packet. The URIs are as rules take them, for copying. journalctl -o short-iso _SYSTEMD_UNIT=fcbr0-egress.service + _TRANSPORT=kernel "$@" | - grep --line-buffered -E " (ALLOW|DENY) $user " + grep --line-buffered -E " (ALLOW|DENY) $user " | + sed -u -E 's/( fc-egress (ALLOW|DENY) [^ ]+ [^ ]+ )(.* DST=([0-9.]+) .*PROTO=(TCP|UDP) .*DPT=([0-9]+).*)$/\1\L\5\E:\/\/\4:\6 \3/' ;; help|-h|--help) usage @@ -422,7 +424,7 @@ ${lib.concatMapStrings (u: " limit_conn user_${u} ${toString (users.${u} http { lua_package_path "${egressLua}/?.lua;;"; include ${runDir}/resolver.conf; - log_format egress '$egress_verdict $egress_guest $host $request_method $request_uri $status $body_bytes_sent'; + log_format egress '$egress_verdict $egress_guest $request_method https://$host$request_uri $status $body_bytes_sent'; # Only requests that got to egress.lua (others, like a TLS # handshake without request, have no verdict). access_log syslog:server=unix:/dev/log,nohostname,tag=fc_egress egress if=$egress_verdict; diff --git a/modules/host/egress.lua b/modules/host/egress.lua index 37411df..172805a 100644 --- a/modules/host/egress.lua +++ b/modules/host/egress.lua @@ -102,11 +102,11 @@ function _M.preread() who = who or "- - -" if p == "pass" then ngx.var.egress_upstream = sni:lower() .. ":443" - ngx.var.egress_log = "ALLOW " .. who .. " " .. sni:lower() + ngx.var.egress_log = "ALLOW " .. who .. " https://" .. sni:lower() elseif p then ngx.var.egress_upstream = "unix:" .. RUN .. "/decrypt-" .. guest.tap .. ".sock" else - ngx.var.egress_log = "DENY " .. who .. " " .. (sni ~= "" and sni or "-") + ngx.var.egress_log = "DENY " .. who .. " " .. (sni ~= "" and "https://" .. sni or "-") return ngx.exit(403) end end |
