我用 ocserv
搭建了一个 AnyConnect 服务器,用的是 certificate
验证模式,我想对每个用户做流量统计。
我从样例配置文件里面知道 ocserv
支持 connect-script
,并且会把 REASON, USERNAME, GROUPNAME, HOSTNAME, DEVICE, IP_REAL, IP_LOCAL, IP_REMOTE
作为变量传递给脚本。但问题是,我写了一个脚本把以上变量打印出来,结果 USERNAME, GROUPNAME, HOSTNAME
是空的,这样就无法识别用户了。
所以应该怎么解决呢?
The certificate need also contain user identifying information, for example, the user ID of the client must be embedded in the certificate’s Distinguished Name (DN), i.e., in the Common Name, or UID fields. For the server to read the name, the cert-user-oid configuration option must be set.
使用证书验证的时候,ocserv根据cert-user-oid
和cert-group-oid
选项寻找证书对应的区域来确定USERNAME
和GROUPNAME
。
比如我客户端证书中是这么写的:
CN=VPNUser
UNIT=Group A
在ocserv.conf
里需要启用下面的设置(默认是被注释掉的):
cert-user-oid = 2.5.4.3
cert-group-oid = 2.5.4.11
ocserv.conf在这两个选项的上面有详尽的注释,也指出了常用的区域,比如CN
是2.5.4.3
,UNIT(OU/organizational unit)
是2.5.4.11