Understand OpenBSD sandboxing with pledge() and unveil()
masterOpenBSD provides two primary mechanisms for sandboxing processes to limit their capabilities and access to system resources:
pledge(promises): Limits the system calls a process can make. Once a promise is made, it can only be tightened (restricted), never widened. Callingpledge("")restricts the process to only computation on memory shared with another process. Violating a promise results in aSIGABRT.unveil(path, mode): Limits the filesystem paths a process can see and access. Themodespecifies access levels (e.g.,rfor read,wfor write,cfor create). Callingunveil(NULL, NULL)prevents any further changes to the unveiled filesystem view. Violating an unveil restriction results inENOENTorEACCESSerrors.
These tools are used to prevent unwanted access to sensitive files like ~/.ssh, GPG keys, or /etc/master.passwd.