VMOD Unix-Unix域套接字实用程序¶
SYNOPSIS¶
import unix [as name] [from "path"] 字符串User() 字符串组() Int uid() Int gid()
DESCRIPTION¶
此VMOD提供有关通过Unix域套接字连接到Varnish侦听器的对等进程(进程所有者的用户和组)凭据的信息(如果平台支持它的话)。
示例:
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) );
}
}
可以在支持以下选项之一的平台上获取对等凭据:
getpeereid(3) (如FreeBSD和其他从BSD派生的系统)
套接字选项
SO_PEERCRED
为 getsockopt(2) (Linux)getpeerucred(3C) (SunOS及其后代)
在SunOS和Friends上, PRIV_PROC_INFO
在加载VMOD时将权限集添加到Varnish子进程中,请参见 setppriv(2) 。
在大多数平台上,返回的值是对等进程启动连接时有效的用户或组。
字符串User()¶
返回对等进程所有者的用户名。
仅限于: client
, backend
。
字符串组()¶
返回对等进程所有者的组名。
仅限于: client
, backend
。
Int uid()¶
返回对等进程所有者的数字用户ID。
仅限于: client
, backend
。
Int gid()¶
返回对等进程所有者的数字组ID。
仅限于: client
, backend
。
ERRORS¶
本VMOD中的所有功能均受以下限制:
他们中的任何一个都不能被召回
vcl_init{}
或vcl_fini{}
。如果他们中的一个被叫来vcl_init{}
,则VCL程序将无法加载,并显示来自VMOD的错误消息。如果在不受支持的平台上调用,则调用VCL失败。一条错误消息将写入日志(带有
VCL_Error
标记),以及所有VCL子例程(vcl_synth{}
,控制被立即定向到vcl_synth{}
,响应状态设置为503,原因字符串设置为“VCL失败”。如果故障发生在
vcl_synth{}
,那么vcl_synth{}
则中止,并发送响应行“503 VCL FAILED”。如果当前侦听器不是Unix域套接字,或者如果尝试读取凭据失败,则会引发
VCL_Error
消息将写入日志。字符串函数 (unix.user() 和 unix.group() )退货NULL
,而int函数 (unix.uid() 和 unix.gid() )返回-1。
另请参阅¶
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>