I think you're looking for authpf.
http://www.openbsd.org/faq/pf/authpf.html
Authpf(8) is a user shell for authenticating gateways. An authenticating gateway is just like a regular network gateway (a.k.a. a router) except that users must first authenticate themselves to the gateway before it will allow traffic to pass through it. When a user's shell is set to /usr/sbin/authpf (i.e., instead of setting a user's shell to ksh(1), csh(1), etc) and the user logs in using SSH, authpf will make the necessary changes to the active pf(4) ruleset so that the user's traffic is passed through the filter and/or translated using Network Address Translation or redirection. Once the user logs out or their session is disconnected, authpf will remove any rules loaded for the user and kill any stateful connections the user has open. Because of this, the ability of the user to pass traffic through the gateway only exists while the user keeps their SSH session open.
# macros
wifi_if = "wi0"
ext_if = "fxp0"
dns_servers = "{ 10.0.1.56, 10.0.2.56 }"
table <authpf_users> persist
# filter
block drop all
pass out quick on $ext_if inet proto { tcp, udp, icmp } \
from { $wifi_if:network, $ext_if }
pass in quick on $wifi_if inet proto tcp \
from $wifi_if:network to $wifi_if port ssh
pass in quick on $wifi_if inet proto { tcp, udp } \
from <authpf_users> to $dns_servers port domain
anchor "authpf/*" in on $wifi_if