VMOD_UNIX(3)
π VMOD_UNIX π
okay bestie, we're in the Library Functions Manual and this one is vmod_unix β utilities for Unix domain sockets β¨
πΈ NAME πΈ
vmod_unix β utilities for Unix domain sockets π¦
β¨ SYNOPSIS β¨
import unix [as name] [from "path"]
STRING user()
STRING group()
INT uid()
INT gid()
π«Ά DESCRIPTION π«Ά
So basically, this VMOD hands you the credentials of the peer process β like, the user and the group of whoever owns the process β that's connected to a Varnish listener over a Unix domain socket. That's it, that's the vibe. But only if the platform supports it, bestie. No cap. π
Examples, because we love a demo:
import unix;
sub vcl_recv {
# Return "403 Forbidden" if the connected peer is
# not running as the user "trusteduser".
if (unix.user() != "trusteduser") {
return( synth(403) );
}
# Require the connected peer to run in the group
# "trustedgroup".
if (unix.group() != "trustedgroup") {
return( synth(403) );
}
# Require the connected peer to run under a specific numeric
# user id.
if (unix.uid() != 4711) {
return( synth(403) );
}
# Require the connected peer to run under a numeric group id.
if (unix.gid() != 815) {
return( synth(403) );
}
}
Getting the peer credentials is a whole thing that's only possible on a platform that supports one of these, periodt:
getpeereid(3)β like on FreeBSD and other BSD-derived systems π- the socket option
SO_PEERCREDforgetsockopt(2)β that's the Linux girlies π getpeerucred(3C)β SunOS and its descendants βοΈ
On SunOS and friends, the PRIV_PROC_INFO privilege set gets added to the Varnish child process while the VMOD is loaded β see setppriv(2). iconic behaviour honestly π
On most platforms, what you get back is the effective user or group that was valid back when the peer process initiated the connection. iykyk
π STRING user()
Returns the user name of the peer process owner. π
Restricted to: client, backend.
π§ STRING group()
Returns the group name of the peer process owner. π
Restricted to: client, backend.
β INT uid()
Returns the numeric user id of the peer process owner. π₯
Restricted to: client, backend.
πΈ INT gid()
Returns the numeric group id of the peer process owner. π¦
Restricted to: client, backend.
π ERRORS π
Every single function in this VMOD has to live by these rules, no exceptions bestie:
- None of them may be called in
vcl_init{}orvcl_fini{}. If one of them is called invcl_init{}, then the VCL program fails to load, with an error message from the VMOD. not the moment, truly π - If it's called on a platform that isn't supported, then VCL failure is invoked. An error message gets written to the log (with the
VCL_Errortag), and for all VCL subroutines except forvcl_synth{}, control is directed immediately tovcl_synth{}, with the response status set to503and the reason string set to"VCL failed".
If the failure happens during vcl_synth{}, then vcl_synth{} is aborted, and the response line "503 VCL failed" is sent. rip π«
- If the current listener is not a Unix domain socket, or if the attempt to read credentials fails, then a
VCL_Errormessage is written to the log. TheSTRINGfunctions (unix.user()andunix.group()) returnNULL, while theINTfunctions (unix.uid()andunix.gid()) return-1.
π SEE ALSO π
varnishd(1)vcl(7)getpeereid(3)getsockopt(2)getpeerucred(3C)setppriv(2)
π COPYRIGHT π
This document is licensed under the same conditions as Varnish itself.
See LICENSE for details.
SPDX-License-Identifier: BSD-2-Clause
Authors: Geoffrey Simmons <geoffrey.simmons@uplex.de>
and that's the whole page, bestie π this was VMOD_UNIX(3) from the Library Functions Manual β go off, you understood all of it, main character energy fr fr β¨ππ¦
π¦ where this page comes from
- alpine 3.22: varnish-doc 7.7.3-r0 Β· BSD-2-Clause
- alpine 3.23: varnish-doc 7.7.3-r0 Β· BSD-2-Clause
- alpine 3.24: varnish-doc 7.7.3-r0 Β· BSD-2-Clause
- debian trixie: varnish 7.7.0-3+deb13u1 Β· BSD-2-Clause
- debian trixie: varnish 7.7.0-3+deb13u2 Β· BSD-2-Clause
- fedora 44: varnish 8.0.2-1.fc44 Β· BSD-2-Clause AND (BSD-2-Clause-FreeBSD AND BSD-3-Clause AND LicenseRef-Fedora-Public-Domain AND Zlib)
- fedora 44: varnish 8.0.2-1.fc44 Β· BSD-2-Clause AND (BSD-2-Clause-FreeBSD AND BSD-3-Clause AND LicenseRef-Fedora-Public-Domain AND Zlib)
- opensuse-leap 16.0: varnish 7.7.3-bp160.1.1 Β· BSD-2-Clause
- opensuse-leap 16.0: varnish 7.7.3-bp160.1.1 Β· BSD-2-Clause
- opensuse-leap 16.0: varnish 7.7.3-bp160.1.1 Β· BSD-2-Clause
- opensuse-leap 16.0: varnish 7.7.3-bp160.1.1 Β· BSD-2-Clause
- ubuntu questing: varnish 7.7.3-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms