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