1.\" $OpenBSD: authpf.8,v 1.38 2005/01/04 09:57:04 jmc Exp $ 2.\" 3.\" Copyright (c) 2002 Bob Beck (beck@openbsd.org>. All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 3. The name of the author may not be used to endorse or promote products 14.\" derived from this software without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd January 10, 2002 28.Dt AUTHPF 8 29.Os 30.Sh NAME 31.Nm authpf 32.Nd authenticating gateway user shell 33.Sh SYNOPSIS 34.Nm authpf 35.Sh DESCRIPTION 36.Nm 37is a user shell for authenticating gateways. 38It is used to change 39.Xr pf 4 40rules when a user authenticates and starts a session with 41.Xr sshd 8 42and to undo these changes when the user's session exits. 43It is designed for changing filter and translation rules for an individual 44source IP address as long as a user maintains an active 45.Xr ssh 1 46session. 47Typical use would be for a gateway that authenticates users before 48allowing them Internet use, or a gateway that allows different users into 49different places. 50.Nm 51logs the successful start and end of a session to 52.Xr syslogd 8 . 53This, combined with properly set up filter rules and secure switches, 54can be used to ensure users are held accountable for their network traffic. 55.Pp 56.Nm 57can add filter and translation rules using the syntax described in 58.Xr pf.conf 5 . 59.Nm 60requires that the 61.Xr pf 4 62system be enabled before use. 63.Nm 64can also maintain the list of IP address of connected users 65in the "authpf_users" 66.Pa table . 67.Pp 68.Nm 69is meant to be used with users who can connect via 70.Xr ssh 1 71only. 72On startup, 73.Nm 74retrieves the client's connecting IP address via the 75.Ev SSH_CLIENT 76environment variable and, after performing additional access checks, 77reads a template file to determine what filter and translation rules 78(if any) to add. 79On session exit the same rules that were added at startup are removed. 80.Pp 81Each 82.Nm 83process stores its rules in a separate ruleset inside a 84.Xr pf 4 85.Pa anchor 86shared by all 87.Nm 88processes. 89By default, the 90.Pa anchor 91name "authpf" is used, and the ruleset names equal the username and PID of the 92.Nm 93processes as "username(pid)". 94The following rules need to be added to the main ruleset 95.Pa /etc/pf.conf 96in order to cause evaluation of any 97.Nm 98rules: 99.Bd -literal -offset indent 100nat-anchor "authpf/*" 101rdr-anchor "authpf/*" 102binat-anchor "authpf/*" 103anchor "authpf/*" 104.Ed 105.Pp 106The "/*" at the end of the anchor name is required for 107.Xr pf 4 108to process the rulesets attached to the anchor by 109.Nm authpf . 110.Sh FILTER AND TRANSLATION RULES 111Filter and translation rules for 112.Nm 113use the same format described in 114.Xr pf.conf 5 . 115The only difference is that these rules may (and probably should) use 116the macro 117.Em user_ip , 118which is assigned the connecting IP address whenever 119.Nm 120is run. 121Additionally, the macro 122.Em user_id 123is assigned the user name. 124.Pp 125Filter and translation rules are stored in a file called 126.Pa authpf.rules . 127This file will first be searched for in 128.Pa /etc/authpf/users/$USER/ 129and then in 130.Pa /etc/authpf/ . 131Only one of these files will be used if both are present. 132.Pp 133Per-user rules from the 134.Pa /etc/authpf/users/$USER/ 135directory are intended to be used when non-default rules 136are needed on an individual user basis. 137It is important to ensure that a user can not write or change 138these configuration files. 139.Pp 140The 141.Pa authpf.rules 142file must exist in one of the above locations for 143.Nm 144to run. 145.Sh CONFIGURATION 146Options are controlled by the 147.Pa /etc/authpf/authpf.conf 148file. 149If the file is empty, defaults are used for all 150configuration options. 151The file consists of pairs of the form 152.Li name=value , 153one per line. 154Currently, the allowed values are as follows: 155.Bl -tag -width Ds 156.It anchor=name 157Use the specified 158.Pa anchor 159name instead of "authpf". 160.It table=name 161Use the specified 162.Pa table 163name instead of "authpf_users". 164.El 165.Sh USER MESSAGES 166On successful invocation, 167.Nm 168displays a message telling the user he or she has been authenticated. 169It will additionally display the contents of the file 170.Pa /etc/authpf/authpf.message 171if the file exists and is readable. 172.Pp 173There exist two methods for providing additional granularity to the control 174offered by 175.Nm 176- it is possible to set the gateway to explicitly allow users who have 177authenticated to 178.Xr ssh 1 179and deny access to only a few troublesome individuals. 180This is done by creating a file with the banned user's login name as the 181filename in 182.Pa /etc/authpf/banned/ . 183The contents of this file will be displayed to a banned user, thus providing 184a method for informing the user that they have been banned, and where they can 185go and how to get there if they want to have their service restored. 186This is the default behaviour. 187.Pp 188It is also possible to configure 189.Nm 190to only allow specific users access. 191This is done by listing their login names, one per line, in 192.Pa /etc/authpf/authpf.allow . 193If "*" is found on a line, then all usernames match. 194If 195.Nm 196is unable to verify the user's permission to use the gateway, it will 197print a brief message and die. 198It should be noted that a ban takes precedence over an allow. 199.Pp 200On failure, messages will be logged to 201.Xr syslogd 8 202for the system administrator. 203The user does not see these, but will be told the system is unavailable due to 204technical difficulties. 205The contents of the file 206.Pa /etc/authpf/authpf.problem 207will also be displayed if the file exists and is readable. 208.Sh CONFIGURATION ISSUES 209.Nm 210maintains the changed filter rules as long as the user maintains an 211active session. 212It is important to remember however, that the existence 213of this session means the user is authenticated. 214Because of this, it is important to configure 215.Xr sshd 8 216to ensure the security of the session, and to ensure that the network 217through which users connect is secure. 218.Xr sshd 8 219should be configured to use the 220.Ar ClientAliveInterval 221and 222.Ar ClientAliveCountMax 223parameters to ensure that a ssh session is terminated quickly if 224it becomes unresponsive, or if arp or address spoofing is used to 225hijack the session. 226Note that TCP keepalives are not sufficient for 227this, since they are not secure. 228Also note that 229.Ar AllowTcpForwarding 230should be disabled for 231.Nm 232users to prevent them from circumventing restrictions imposed by the 233packet filter ruleset. 234.Pp 235.Nm 236will remove state table entries that were created during a user's 237session. 238This ensures that there will be no unauthenticated traffic 239allowed to pass after the controlling 240.Xr ssh 1 241session has been closed. 242.Pp 243.Nm 244is designed for gateway machines which typically do not have regular 245(non-administrative) users using the machine. 246An administrator must remember that 247.Nm 248can be used to modify the filter rules through the environment in 249which it is run, and as such could be used to modify the filter rules 250(based on the contents of the configuration files) by regular 251users. 252In the case where a machine has regular users using it, as well 253as users with 254.Nm 255as their shell, the regular users should be prevented from running 256.Nm 257by using the 258.Pa /etc/authpf/authpf.allow 259or 260.Pa /etc/authpf/banned/ 261facilities. 262.Pp 263.Nm 264modifies the packet filter and address translation rules, and because 265of this it needs to be configured carefully. 266.Nm 267will not run and will exit silently if the 268.Pa /etc/authpf/authpf.conf 269file does not exist. 270After considering the effect 271.Nm 272may have on the main packet filter rules, the system administrator may 273enable 274.Nm 275by creating an appropriate 276.Pa /etc/authpf/authpf.conf 277file. 278.Sh EXAMPLES 279.Sy Control Files 280\- To illustrate the user-specific access control 281mechanisms, let us consider a typical user named bob. 282Normally, as long as bob can authenticate himself, the 283.Nm 284program will load the appropriate rules. 285Enter the 286.Pa /etc/authpf/banned/ 287directory. 288If bob has somehow fallen from grace in the eyes of the 289powers-that-be, they can prohibit him from using the gateway by creating 290the file 291.Pa /etc/authpf/banned/bob 292containing a message about why he has been banned from using the network. 293Once bob has done suitable penance, his access may be restored by moving or 294removing the file 295.Pa /etc/authpf/banned/bob . 296.Pp 297Now consider a workgroup containing alice, bob, carol and dave. 298They have a 299wireless network which they would like to protect from unauthorized use. 300To accomplish this, they create the file 301.Pa /etc/authpf/authpf.allow 302which lists their login ids, one per line. 303At this point, even if eve could authenticate to 304.Xr sshd 8 , 305she would not be allowed to use the gateway. 306Adding and removing users from 307the work group is a simple matter of maintaining a list of allowed userids. 308If bob once again manages to annoy the powers-that-be, they can ban him from 309using the gateway by creating the familiar 310.Pa /etc/authpf/banned/bob 311file. 312Though bob is listed in the allow file, he is prevented from using 313this gateway due to the existence of a ban file. 314.Pp 315.Sy Distributed Authentication 316\- It is often desirable to interface with a 317distributed password system rather than forcing the sysadmins to keep a large 318number of local password files in sync. 319The 320.Xr login.conf 5 321mechanism in 322.Ox 323can be used to fork the right shell. 324To make that happen, 325.Xr login.conf 5 326should have entries that look something like this: 327.Bd -literal -offset indent 328shell-default:shell=/bin/csh 329 330default:\e 331 ... 332 :shell=/usr/sbin/authpf 333 334daemon:\e 335 ... 336 :shell=/bin/csh:\e 337 :tc=default: 338 339staff:\e 340 ... 341 :shell=/bin/csh:\e 342 :tc=default: 343.Ed 344.Pp 345Using a default password file, all users will get 346.Nm 347as their shell except for root who will get 348.Pa /bin/csh . 349.Pp 350.Sy SSH Configuration 351\- As stated earlier, 352.Xr sshd 8 353must be properly configured to detect and defeat network attacks. 354To that end, the following options should be added to 355.Xr sshd_config 5 : 356.Bd -literal -offset indent 357Protocol 2 358ClientAliveInterval 15 359ClientAliveCountMax 3 360.Ed 361.Pp 362This ensures that unresponsive or spoofed sessions are terminated within a 363minute, since a hijacker should not be able to spoof ssh keepalive messages. 364.Pp 365.Sy Banners 366\- Once authenticated, the user is shown the contents of 367.Pa /etc/authpf/authpf.message . 368This message may be a screen-full of the appropriate use policy, the contents 369of 370.Pa /etc/motd 371or something as simple as the following: 372.Bd -literal -offset indent 373This means you will be held accountable by the powers that be 374for traffic originating from your machine, so please play nice. 375.Ed 376.Pp 377To tell the user where to go when the system is broken, 378.Pa /etc/authpf/authpf.problem 379could contain something like this: 380.Bd -literal -offset indent 381Sorry, there appears to be some system problem. To report this 382problem so we can fix it, please phone 1-900-314-1597 or send 383an email to remove@bulkmailerz.net. 384.Ed 385.Pp 386.Sy Packet Filter Rules 387\- In areas where this gateway is used to protect a 388wireless network (a hub with several hundred ports), the default rule set as 389well as the per-user rules should probably allow very few things beyond 390encrypted protocols like 391.Xr ssh 1 , 392.Xr ssl 8 , 393or 394.Xr ipsec 4 . 395On a securely switched network, with plug-in jacks for visitors who are 396given authentication accounts, you might want to allow out everything. 397In this context, a secure switch is one that tries to prevent address table 398overflow attacks. 399.Pp 400Example 401.Pa /etc/pf.conf : 402.Bd -literal 403# by default we allow internal clients to talk to us using 404# ssh and use us as a dns server. 405internal_if="fxp1" 406gateway_addr="10.0.1.1" 407nat-anchor "authpf/*" 408rdr-anchor "authpf/*" 409binat-anchor "authpf/*" 410block in on $internal_if from any to any 411pass in quick on $internal_if proto tcp from any to $gateway_addr \e 412 port = ssh 413pass in quick on $internal_if proto udp from any to $gateway_addr \e 414 port = domain 415anchor "authpf/*" 416.Ed 417.Pp 418.Sy For a switched, wired net 419\- This example 420.Pa /etc/authpf/authpf.rules 421makes no real restrictions; it turns the IP address on and off, logging 422TCP connections. 423.Bd -literal 424external_if = "xl0" 425internal_if = "fxp0" 426 427pass in log quick on $internal_if proto tcp from $user_ip to any \e 428 keep state 429pass in quick on $internal_if from $user_ip to any 430.Ed 431.Pp 432.Sy For a wireless or shared net 433\- This example 434.Pa /etc/authpf/authpf.rules 435could be used for an insecure network (such as a public wireless network) where 436we might need to be a bit more restrictive. 437.Bd -literal 438internal_if="fxp1" 439ipsec_gw="10.2.3.4" 440 441# rdr ftp for proxying by ftp-proxy(8) 442rdr on $internal_if proto tcp from $user_ip to any port 21 \e 443 -> 127.0.0.1 port 8081 444 445# allow out ftp, ssh, www and https only, and allow user to negotiate 446# ipsec with the ipsec server. 447pass in log quick on $internal_if proto tcp from $user_ip to any \e 448 port { 21, 22, 80, 443 } flags S/SA 449pass in quick on $internal_if proto tcp from $user_ip to any \e 450 port { 21, 22, 80, 443 } 451pass in quick proto udp from $user_ip to $ipsec_gw port = isakmp \e 452 keep state 453pass in quick proto esp from $user_ip to $ipsec_gw 454.Ed 455.Pp 456.Sy Dealing with NAT 457\- The following 458.Pa /etc/authpf/authpf.rules 459shows how to deal with NAT, using tags: 460.Bd -literal 461ext_if = "fxp1" 462ext_addr = 129.128.11.10 463int_if = "fxp0" 464# nat and tag connections... 465nat on $ext_if from $user_ip to any tag $user_ip -> $ext_addr 466pass in quick on $int_if from $user_ip to any 467pass out log quick on $ext_if tagged $user_ip keep state 468.Ed 469.Pp 470With the above rules added by 471.Nm , 472outbound connections corresponding to each users NAT'ed connections 473will be logged as in the example below, where the user may be identified 474from the ruleset name. 475.Bd -literal 476# tcpdump -n -e -ttt -i pflog0 477Oct 31 19:42:30.296553 rule 0.bbeck(20267).1/0(match): pass out on fxp1: \e 478129.128.11.10.60539 > 198.137.240.92.22: S 2131494121:2131494121(0) win \e 47916384 <mss 1460,nop,nop,sackOK> (DF) 480.Ed 481.Pp 482.Sy Using the authpf_users table 483\- Simple 484.Nm 485settings can be implemented without an anchor by just using the "authpf_users" 486.Pa table . 487For example, the following 488.Xr pf.conf 5 489lines will give SMTP and IMAP access to logged in users: 490.Bd -literal 491table <authpf_users> persist 492pass in on $ext_if proto tcp from <authpf_users> \e 493 to port { smtp imap } keep state 494.Ed 495.Pp 496It is also possible to use the "authpf_users" 497.Pa table 498in combination with anchors. 499For example, 500.Xr pf 4 501processing can be sped up by looking up the anchor 502only for packets coming from logged in users: 503.Bd -literal 504table <authpf_users> persist 505anchor "authpf/*" from <authpf_users> 506rdr-anchor "authpf/*" from <authpf_users> 507.Ed 508.Sh FILES 509.Bl -tag -width "/etc/authpf/authpf.conf" -compact 510.It Pa /etc/authpf/authpf.conf 511.It Pa /etc/authpf/authpf.allow 512.It Pa /etc/authpf/authpf.rules 513.It Pa /etc/authpf/authpf.message 514.It Pa /etc/authpf/authpf.problem 515.El 516.Sh SEE ALSO 517.Xr pf 4 , 518.Xr pf.conf 5 , 519.Xr ftp-proxy 8 520.Sh HISTORY 521The 522.Nm 523program first appeared in 524.Ox 3.1 . 525.Sh BUGS 526Configuration issues are tricky. 527The authenticating 528.Xr ssh 1 529connection may be secured, but if the network is not secured the user may 530expose insecure protocols to attackers on the same network, or enable other 531attackers on the network to pretend to be the user by spoofing their IP 532address. 533.Pp 534.Nm 535is not designed to prevent users from denying service to other users. 536