#+TITLE: How BSD Authentication Works
#+DATE: 2020-11-02T16:49:46-05:00
#+DRAFT: true
#+SHOWTOC: true
#+DESCRIPTION:
#+TAGS[]: openbsd
#+KEYWORDS[]: openbsd
#+SLUG:
#+SUMMARY:
#+begin_export html
#+end_export
[[https://web.archive.org/web/20170327150148/http://www.penzin.net/bsdauth/]]
* History
:PROPERTIES:
:CUSTOM_ID: history
:END:
OpenBSD is quite different from many other Unix-like operating
systems in many ways, but one way which I find interesting is the
authentication system. Most systems from AIX, Solaris, and Linux to
most BSDs including MacOS use some form of a system called [[https://en.wikipedia.org/wiki/Pluggable_authentication_module][Pluggable
Authentication Module]] (PAM). The two main implementations of PAM are
[[http://www.linux-pam.org/][Linux PAM]] and [[https://www.openpam.org/][OpenPAM]]. PAM modules are created as dynamically loaded
shared objects, which communicate using a set of somewhat
standardized interfaces ([[https://linux.die.net/man/3/pam][Linux-PAM]] and [[https://www.freebsd.org/cgi/man.cgi?query=pam&apropos=0&sektion=3&manpath=FreeBSD+12.1-RELEASE+and+Ports&arch=default&format=html][OpenPAM]]). PAM is configured
using the [[https://linux.die.net/man/5/pam.d][pam.d]] directory and [[https://www.freebsd.org/cgi/man.cgi?query=pam.conf&sektion=5&apropos=0&manpath=FreeBSD+12.1-RELEASE+and+Ports][pam.conf]]. PAM can best be described as
[[https://www.youtube.com/watch?v=-CXp3byvI1g][unstandardized black magic]].
OpenBSD on the other hand uses a mechanism called BSD
Authentication. It was originally developed for a proprietary
operating system called [[https://en.wikipedia.org/wiki/BSD/OS][BSD/OS]] by [[https://en.wikipedia.org/wiki/Berkeley_Software_Design][Berkeley Software Design Inc.]], who
later donated the system. It was adopted by OpenBSD in release 2.9.
BSD Auth is comparatively much simpler than PAM. Modules or,
authentication "styles", are instead stand alone applications or
scripts that communicate over IPC. The program or script has no
ability to interfere with the parent and can very easily revoke
permissions using [[https://man.openbsd.org/pledge][=pledge(2)=]] or [[https://man.openbsd.org/unveil][=unveil(2)=]]. The BSD Authentication
system of configured through [[https://man.openbsd.org/login.conf][=login.conf(5)=]].
* Why
:PROPERTIES:
:CUSTOM_ID: why
:END:
This one is pretty difficult, since there seems to be very little
information about how BSD Auth works apart from the source code
itself and the man pages, which intentionally keep the internals
opaque. This is my best attempt to understand and describe the flow
of BSD Auth.
* Documentation
:PROPERTIES:
:CUSTOM_ID: documentation
:END:
All of the high level authentication functions are described in
[[https://man.openbsd.org/authenticate][=authenticate(3)=]], with the lower level functions being described in
[[https://man.openbsd.org/auth_subr][=auth_subr(3)=]].
Click on any function prototype in this post to see its definition.
All code snippets from this blog post belong to the OpenBSD contributors.
* BSD Auth Modules
:PROPERTIES:
:CUSTOM_ID: modules
:END:
These programs or scripts are located in =/usr/libexec/auth/= with the
naming convention =login_