MAC_PORTACL(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… MAC_PORTACL(4) β€” the kernel interfaces manual, but make it make sense

okay bestie, buckle up, because this is mac_portacl β€” the network port access control policy β€” and she is literally the bouncer at the club door of your ports. this is a mac manpage (kernel interfaces manual, iykyk) and we're gonna get through it together πŸŽ€


✨ NAME ✨

mac_portacl β€” network port access control policy πŸ¦‹


🌸 SYNOPSIS 🌸

so to compile the port access control policy into your kernel, you put these lines in your kernel configuration file:

options MAC
options MAC_PORTACL

alternately β€” if you'd rather load the port access control policy module at boot time β€” you put just this line in your kernel configuration file:

options MAC

and then in loader.conf(5) you go:

mac_portacl_load="YES"

easy. slay. periodt πŸ’…


πŸ’– DESCRIPTION πŸ’–

so what does the mac_portacl policy actually do? it lets administrators administratively limit binding to local UDP and TCP ports via the sysctl(8) interface. that's the whole vibe. no cap ✨

but listen, there are prerequisites, because of course there are:

  • in order to enable the mac_portacl policy, MAC policy must be enforced on sockets (see mac(4)), and
  • the port(s) protected by mac_portacl must not be included in the range specified by the net.inet.ip.portrange.reservedlow and net.inet.ip.portrange.reservedhigh sysctl(8) MIBs.

and here's the important lil nuance: the mac_portacl policy only affects ports explicitly bound by a user process (either for a listen/outgoing TCP socket, or a send/receive UDP socket). this policy will not limit ports bound implicitly for outgoing connections where the process has not explicitly selected a port β€” those are automatically selected by the IP stack. so like, don't come for her when the stack picks a port for you, that's not her department πŸ™ˆ

when mac_portacl is enabled, it will control binding access to ports up to the port number set in the security.mac.portacl.port_high sysctl(8) variable. by default, all attempts to bind to mac_portacl controlled ports will fail if not explicitly allowed by the port access control list β€” though binding by the superuser will be allowed, if the sysctl(8) variable security.mac.portacl.suser_exempt is set to a non-zero value. the superuser really said "rules for thee, not for me" and honestly? iconic πŸ‘‘

🧚 Runtime Configuration 🧚

the following sysctl(8) MIBs are available for fine-tuning the enforcement of this MAC policy. all sysctl(8) variables, except security.mac.portacl.rules, can also be set as loader(8) tunables in loader.conf(5). (yes, only that one has to sit out. she's special.)

  • security.mac.portacl.enabled β€” Enforce the mac_portacl policy. (Default: 1).
  • security.mac.portacl.port_high β€” The highest port number mac_portacl will enforce rules for. (Default: 1023).
  • security.mac.portacl.rules β€” The port access control list is specified in the following format:
idtype:id:protocol:port[,idtype:id:protocol:port,...]

and here's what each lil piece means:

  • idtype β€” Describes the type of subject match to be performed. Either uid for user ID matching, or gid for group ID matching.
  • id β€” The user or group ID (depending on idtype) allowed to bind to the specified port. NOTE: User and group names are not valid; only the actual ID numbers may be used. 😭 yeah, numbers only, names do NOT work, don't @ me.
  • protocol β€” Describes which protocol this entry applies to. Either tcp or udp are supported.
  • port β€” Describes which port this entry applies to. NOTE: MAC security policies may not override other security system policies by allowing accesses that they may deny, such as net.inet.ip.portrange.reservedlow / net.inet.ip.portrange.reservedhigh. If the specified port falls within the range specified, the mac_portacl entry will not function (i.e., even the specified user/group may not be able to bind to the specified port). so like, she's not gonna fight the other security systems for you. that's not her job. 🫢
  • security.mac.portacl.suser_exempt β€” Allow superuser (i.e., root) to bind to all mac_portacl protected ports, even if the port access control list does not explicitly allow this. (Default: 1).
  • security.mac.portacl.autoport_exempt β€” Allow applications to use automatic binding to port 0. Applications use port 0 as a request for automatic port allocation when binding an IP address to a socket. This tunable will exempt port 0 allocation from rule checking. (Default: 1).
fr fr though β€” those defaults? 1, 1023, 1, 1. write them down, bestie. πŸ“

🌈 SEE ALSO 🌈

mac(3), ip(4), mac_biba(4), mac_bsdextended(4), mac_ddb(4), mac_ifoff(4), mac_mls(4), mac_none(4), mac_partition(4), mac_seeotheruids(4), mac_test(4), mac(9)

(the whole mac cinematic universe, go read 'em πŸ“)


⭐ HISTORY ⭐

MAC first appeared in FreeBSD 5.0 and mac_portacl first appeared in FreeBSD 5.1. two icons, one era πŸ’œ


πŸ‘‘ AUTHORS πŸ‘‘

This software was contributed to the FreeBSD Project by NAI Labs, the Security Research Division of Network Associates Inc. under DARPA/SPAWAR contract N66001-01-C-8035 (β€œCBOSS”), as part of the DARPA CHATS research program.


and that's the whole page, bestie, you ate it up πŸŽ€πŸ’– this was Debian's build, dated December 9, 2004 β€” shoutout to the version/date corner of the footer, we see you πŸ¦‹βœ¨

πŸ“¦ where this page comes from