Linux and macOS users are familiar with sudo, a programme that allows
you to run a command as another user, usually root (the administrator).
Although sudo can be installed on OpenBSD, doas is used instead, as it
is part of the system.
Why I wanted to contribute to doas
When configuring doas via the /etc/doas.conf file, you can use
the “persist” directive, which means you don’t have to re-enter your password
for 5 minutes. This way, if you have several commands to enter, you don’t
have to re-enter your password each time.
However, this 5-minutes timeout cannot be configured; it is a decision made by the OpenBSD team. And this is precisely an issue that comes up from time to time (such as here or there ), as some people would like to be able to choose how long the password is not requested again. Generally, these people would prefer a longer time, such as 15 minutes. Personally, I would prefer a shorter time, so that the password is remembered just long enough to type 2-3 commands, and then forgotten.
That’s why I decided to delve into the doas code and submit a patch to the OpenBSD team.
My doas patch
If you simply want to access the patch, it is available on Github .
The goal
To help you understand the change I have proposed, here is how doas is currently configured ( doas.conf(5) ):
# /etc/doas.conf
# Members of the "wheel" group are authorised to use doas; their password
# is stored for 5 minutes using "persist"
permit persist :wheel
# Newline required after a rule
Note: in my article about
doason OpenBSD Desktop , I mentioned that it was required to add a newline (\n) after each rule so that it is taken into account. Now that I’ve studied the parser, as well as knowing it, I understand why.
The patch I have developed adds an optional parameter to persist, allowing
you to choose how many seconds the password is stored for:
# /etc/doas.conf
permit persist 60 :wheel
# Newline required after a rule
For 60 seconds, the user is not prompted to re-enter their password; this timeframe is shorter than the current 5 minutes. If the timeframe is not specified in the configuration, the default 5-minutes timeframe is used, meaning that this change is backwards-compatible: it adds a new feature without breaking the existing functionality.
How I did it
If you are thinking of contributing to OpenBSD, you might find this method of interest.
- OpenBSD uses CVS, but I prefer Git, so I cloned the repository from GitHub:
git clone https://github.com/openbsd/src. - As stated in the documentation
, I have executed the following
commands in the Git repository:
git config diff.noprefix trueandgit config diff.renames false. This was useful when generating the diff file. which doastold me that the doas programme is located in the directory/usr/bin, so I’ve navigated to the correct folder in the repository :cd usr.bin/doas/.- Once in the correct folder, I looked through the various files:
doas.1anddoas.conf.5are man pages, which can be viewed usingman doasandman doas.conf.Makefileis the file thatmakeuses to compile doas.make objcreates a subfolder calledobj/, after whichmakecompiles doas.env.ccontains C code for managing the environment.doas.handdoas.ccontain C code, themain()function is located indoas.cand is a good starting point for understanding how the programme works.parser.yis a rather special file, used by yacc . It defines the grammar used by the configuration filedoas.conf; to add a configuration option, you need to edit this file. To do this, you’ll need to familiarise yourself with yacc, as it’s not just C code.
- After studying the documentation and the code, and making my changes,
I generated a diff from the
usr.bin/doasdirectory using the commandgit diff --relative . > doas-persist-timeout.patch. - Finally, after reading the instructions , I sent an email to the mailing list with my patch attached.
The response from the OpenBSD team
A few hours after sending my message, I received a reply from Theo, the founder of OpenBSD, he didn’t like the idea of making the timeout configurable, and he put forward some good arguments. The 5-minutes timeout was chosen because it is neither too long to cause problems nor too short to be a nuisance, it keeps doas simple, without complicating configuration management.
A snub? Not at all. Of course I would have liked the patch to be accepted, but the explanation for the rejection makes sense, is consistent, and above all I learnt a great deal by digging into the code. And besides, I still have my patch, nothing stops me from using it even though it was rejected.
Understand the OpenBSD philosophy
OpenBSD is a system designed to be simple, having fewer features reduces the attack surface and the number of bugs.
Security is at the heart of everything: every feature added is considered from the perspective of security, risk and the complexity it introduces. A telling example is Bluetooth, which is deliberately not supported by OpenBSD.
In line with this focus on security is a commitment to writing correct code, and this is achieved through code reviews. Every patch is reviewed by other developers to identify any issues.
Advises to contribute
Here are a few tips if you’d like to contribute to OpenBSD:
- Read the documentation. This applies to users too. OpenBSD
has excellent documentation:
man 1 doasfor thedoascommand,man 5 doas.confto understand thedoas.conffile, as well asman 2 pledgeto find out more about thepledgesystem call, orman 3 getoptto access the documentation for the C functiongetopt. - Communicate via the mailing lists . There are several of them, some for general discussion, others for submitting patches.
- Accept rejection. Whether on OpenBSD or another open-source project, developers are under no obligation to accept your proposals. That doesn’t necessarily mean they’re bad, though.
Conclusion
Contributing to OpenBSD is challenging, but rewarding. Even if the patch is rejected, the learning experience is invaluable, and getting as far as submitting the patch is a victory in itself.
Need an OpenBSD expert who knows the system inside out? Let’s discuss your project .