OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Installation
        • Configuration
          • Creating the Configuration File
        • Running the Server
        • Adding Initial Entries
        • Searching and Querying
        • TLS Encryption
        • System Account Integration
        • Firewall Notes
        • YP vs LDAP Recap

        LDAP

        Synopsis #

        LDAP (Lightweight Directory Access Protocol) provides network access to directory records such as users, groups, and hosts. LDAP servers can control access to those records and protect connections with TLS.

        LDAP is not the same as YP (NIS):

        • YP is an older, SunRPC-based protocol included in the OpenBSD base system.
        • LDAP is an extensible, industry-standard protocol (RFC 4511), designed to operate over TCP and optionally with TLS.
        • OpenBSD includes the ldapd(8) LDAP server in base. OpenLDAP, the server documented in this chapter, is available via packages.

        The examples below configure an OpenLDAP server, query it with client tools, and describe integration with OpenBSD account lookups.

        Installation #

        Install the OpenLDAP server and client tools:

        doas pkg_add openldap-server openldap-client
        

        This provides the slapd(8) daemon and tools such as ldapadd, ldapmodify, ldapsearch, and slappasswd.

        The configuration and database directories will be located under:

        • /etc/openldap/: Configuration files (if using legacy slapd.conf)
        • /var/openldap-data/: Backend database
        • /etc/openldap/slapd.d/: Dynamic configuration tree when using cn=config

        Configuration #

        OpenLDAP can be configured in two ways:

        1. Static configuration via /etc/openldap/slapd.conf (simpler, but deprecated)
        2. Dynamic configuration via the cn=config backend

        The examples below use /etc/openldap/slapd.conf. Use cn=config when dynamic configuration is required.

        Creating the Configuration File #

        Example /etc/openldap/slapd.conf:

        include         /etc/openldap/schema/core.schema
        
        pidfile         /var/run/openldap/slapd.pid
        argsfile        /var/run/openldap/slapd.args
        
        loglevel        stats
        
        modulepath      /usr/local/libexec/openldap
        moduleload      back_mdb.la
        
        backend         mdb
        database        mdb
        maxsize         1073741824
        suffix          "dc=example,dc=org"
        rootdn          "cn=admin,dc=example,dc=org"
        rootpw          {SSHA}xxxxxxxxxxxxxxxxxxxxxxx
        directory       /var/openldap-data
        

        Use slappasswd to generate a secure hashed password:

        # slappasswd
        New password:
        Re-enter new password:
        {SSHA}pFhVhOLHbI4YXEbrr4AQF4r+fpdU6xgF
        

        Insert the result as rootpw.

        Create the database and runtime directories before validation:

        doas mkdir -p /var/openldap-data /var/run/openldap
        doas chown _openldap:_openldap /var/openldap-data /var/run/openldap
        doas chmod 700 /var/openldap-data
        doas chmod 755 /var/run/openldap
        

        Running the Server #

        Use the packaged slapd service and explicitly select the legacy configuration used above:

        doas slaptest -u -f /etc/openldap/slapd.conf
        doas rcctl enable slapd
        doas rcctl set slapd flags -u _openldap -f /etc/openldap/slapd.conf
        doas rcctl start slapd
        

        Correct validation errors before starting. Do not start a second manual daemon alongside the rc service.

        Adding Initial Entries #

        Create an LDIF file for the base domain:

        dn: dc=example,dc=org
        objectClass: top
        objectClass: dcObject
        objectClass: organization
        o: Example Organization
        dc: example
        
        dn: cn=admin,dc=example,dc=org
        objectClass: simpleSecurityObject
        objectClass: organizationalRole
        cn: admin
        description: Directory administrator
        userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxx
        

        Add entries with:

        doas ldapadd -x -D "cn=admin,dc=example,dc=org" -W -f base.ldif
        

        Enter the admin password when prompted.

        Searching and Querying #

        To search the directory:

        ldapsearch -x -b "dc=example,dc=org"
        

        To look for users in a specific subtree:

        ldapsearch -x -b "ou=people,dc=example,dc=org" "(uid=wouter)"
        

        Use -D and -W to authenticate as a bind user if necessary.

        TLS Encryption #

        LDAP can operate with or without encryption. To secure connections:

        1. Create a certificate and private key under /etc/ssl/openldap/
        2. Add the following to slapd.conf:
        TLSCertificateFile     /etc/ssl/openldap/server.crt
        TLSCertificateKeyFile  /etc/ssl/openldap/server.key
        TLSCACertificateFile   /etc/ssl/openldap/ca.crt
        
        1. Restart slapd and require StartTLS on the LDAP listener. The certificate must match the server hostname and be trusted by the client:
        ldapsearch -H ldap://ldap.example.org -ZZ -x -b "dc=example,dc=org"
        

        Replace ldap.example.org with the server name from the certificate and make sure it resolves to the LDAP server.

        This example uses TCP 389 with StartTLS. LDAPS additionally requires an ldaps:/// listener in the daemon’s -h flags; certificate directives alone do not open TCP 636.

        System Account Integration #

        OpenBSD does not use /etc/nsswitch.conf or PAM for base-system account lookups and authentication. Advice for nss_ldap, nslcd, or Linux PAM modules does not describe the native OpenBSD setup.

        The base-system ypldap(8) daemon can expose LDAP directory entries as YP maps. It takes the place of ypserv(8); the two daemons must not run together. Configure the LDAP mappings in ypldap.conf(5) , then configure ypbind(8) and the password and group inclusions described in YP Client Configuration .

        Serving account records through YP does not perform an LDAP bind for each login. Password authentication requires a password hash usable by OpenBSD in the account map; home directories and login shells must also be available on each client.

        Firewall Notes #

        Allow TCP access to the desired LDAP port(s) on internal interfaces only:

        pass in on $int_if proto tcp to port { 389, 636 }
        

        Do not expose LDAP services to the public internet without encryption, strict ACLs, and authentication mechanisms in place.

        YP vs LDAP Recap #

        FeatureYP (NIS)LDAP
        ProtocolSunRPCTCP (RFC 4511)
        Base SupportIncluded in OpenBSDldapd(8) in base; OpenLDAP package
        TransportUnencryptedTLS and StartTLS supported
        Access ControlNone (basic map filtering)ACLs, authentication, TLS
        Schema SupportFlat Unix-like mapsExtensible object schema
        Recommended UseSmall trusted LANsSecure identity infrastructure
        Report a bug
        • Synopsis
        • Installation
        • Configuration
          • Creating the Configuration File
        • Running the Server
        • Adding Initial Entries
        • Searching and Querying
        • TLS Encryption
        • System Account Integration
        • Firewall Notes
        • YP vs LDAP Recap