|
1 | 1 | Rationale and details |
2 | 2 | ===================== |
3 | 3 |
|
4 | | -[Werc](http://werc.cat-v.org/), defined as a "sane web anti-framework", is a set of [CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface) scripts that take markdown files and HTML templates and spit out a complete HTML page. It is simple (highly functional core is 150 lines), easily extensible, and fast enough. |
| 4 | +[Werc](http://werc.cat-v.org/), defined as a "sane web anti-framework", is a |
| 5 | +set of [CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface) scripts |
| 6 | +that take markdown files and HTML templates and spit out a complete HTML page. |
| 7 | +It is simple (highly functional core is 150 lines), easily extensible, and fast |
| 8 | +enough. |
5 | 9 |
|
6 | | -Werc is quite popular among [Plan 9](https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs) and [9front](https://9front.org/) users. Two possible and logical reasons are that: |
| 10 | +Werc is quite popular among [Plan |
| 11 | +9](https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs) and |
| 12 | +[9front](https://9front.org/) users. Two possible and logical reasons are that: |
7 | 13 |
|
8 | | -1. It was written using Plan 9's default shell, [Rc](https://p9f.org/sys/doc/rc.html). |
| 14 | +1. It was written using Plan 9's default shell, |
| 15 | +[Rc](https://p9f.org/sys/doc/rc.html). |
9 | 16 | 2. Like I said before, it is simple, and Plan 9 folks like simplicity. |
10 | 17 |
|
11 | | -I didn't have much knowledge or experience with Plan 9 at the time. However, I did have knowledge and experience with Unix-like systems (a lot more, compared to Plan 9) and I knew about the existence of [plan9port](https://9fans.github.io/plan9port/), a port of the Plan 9 user space to Unix-like systems (thank you [Russ Cox](https://swtch.com/~rsc/)). A Unix-like operating system and plan9port were all I needed to make Werc work outside of Plan 9. On one hand, an operating system family that I was familiar with. On the other, the simplicity of Werc and the Plan 9 user space. |
| 18 | +I didn't have much knowledge or experience with Plan 9 at the time. However, I |
| 19 | +did have knowledge and experience with Unix-like systems (a lot more, compared |
| 20 | +to Plan 9) and I knew about the existence of |
| 21 | +[plan9port](https://9fans.github.io/plan9port/), a port of the Plan 9 user |
| 22 | +space to Unix-like systems (thank you [Russ Cox](https://swtch.com/~rsc/)). A |
| 23 | +Unix-like operating system and plan9port were all I needed to make Werc work |
| 24 | +outside of Plan 9. On one hand, an operating system family that I was familiar |
| 25 | +with. On the other, the simplicity of Werc and the Plan 9 user space. |
12 | 26 |
|
13 | | -The choice I made regarding the specific operating system to use was backed by one main thought: *if it is exposed to the internet, it must be **secure***. I could have chosen Linux, but OpenBSD is much more closely related to Unix (Unix as it was intended by its creators), and it has way stricter policies regarding security. |
| 27 | +The choice I made regarding the specific operating system to use was backed by |
| 28 | +one main thought: *if it is exposed to the internet, it must be **secure***. I |
| 29 | +could have chosen Linux, but OpenBSD is much more closely related to Unix (Unix |
| 30 | +as it was intended by its creators), and it has way stricter policies regarding |
| 31 | +security. |
14 | 32 |
|
15 | | -Another thing I really cared about, back when I started writing this script, is that it had to have the least external dependencies possible. In other words, with the reasonable exception of plan9port, it only had to rely on things that were already available in the default OpenBSD install, if possible. I took this decision for two reasons: the first is that I hate when something installs a gazillion dependencies and bloats your system, the second is that external dependencies may introduce security breaches. |
| 33 | +Another thing I really cared about, back when I started writing this script, is |
| 34 | +that it had to have the least external dependencies possible. In other words, |
| 35 | +with the reasonable exception of plan9port, it only had to rely on things that |
| 36 | +were already available in the default OpenBSD install, if possible. I took this |
| 37 | +decision for two reasons: the first is that I hate when something installs a |
| 38 | +gazillion dependencies and bloats your system, the second is that external |
| 39 | +dependencies may introduce security breaches. |
16 | 40 |
|
17 | | -In addition to all I said before, and this was by far the hardest goal to achieve, all this had to comply with OpenBSD's [httpd](https://man.openbsd.org/httpd) way of doing things. That is, the hosted website is served from a `chroot`'ed directory, `/var/www`. By doing so, potential breaches are only limited to that portion of the file system. At first, since [symlinks](https://en.wikipedia.org/wiki/Symbolic_link) cannot be accessed from a `chroot`'ed environment, I solved it the naïve way: I just copied all the Plan 9 utilities, together with their shared objects, into `/var/www`. This was not the best solution, not even close, but it worked for a while. Then, I switched to [hard links](https://en.wikipedia.org/wiki/Hard_link). In theory, hard links consume way less data on disk. In practice, most of the times they are not possible because even OpenBSD's default installation splits the filesystem into many partitions and hard links cannot be created from one disk/partition to the other. At that time I wrote the setup script to only hard link files when possible and to copy them otherwise. Given the probabilities of finding an OpenBSD installation with all files on the same partition, this latter solution was basically the same as the former, naïve solution. |
| 41 | +In addition to all I said before, and this was by far the hardest goal to |
| 42 | +achieve, all this had to comply with OpenBSD's |
| 43 | +[httpd](https://man.openbsd.org/httpd) way of doing things. That is, the hosted |
| 44 | +website is served from a `chroot`'ed directory, `/var/www`. By doing so, |
| 45 | +potential breaches are only limited to that portion of the file system. At |
| 46 | +first, since [symlinks](https://en.wikipedia.org/wiki/Symbolic_link) cannot be |
| 47 | +accessed from a `chroot`'ed environment, I solved it the naïve way: I just |
| 48 | +copied all the Plan 9 utilities, together with their shared objects, into |
| 49 | +`/var/www`. This was not the best solution, not even close, but it worked for a |
| 50 | +while. Then, I switched to |
| 51 | +[hard links](https://en.wikipedia.org/wiki/Hard_link). In theory, hard links |
| 52 | +consume way less data on disk. In practice, most of the times they are not |
| 53 | +possible because even OpenBSD's default installation splits the filesystem into |
| 54 | +many partitions and hard links cannot be created from one disk/partition to the |
| 55 | +other. At that time I wrote the setup script to only hard link files when |
| 56 | +possible and to copy them otherwise. Given the probabilities of finding an |
| 57 | +OpenBSD installation with all files on the same partition, this latter solution |
| 58 | +was basically the same as the former, naïve solution. |
18 | 59 |
|
19 | | -The final solution, introduced in [v2.0](https://github.com/EdoardoLaGreca/werc-on-openbsd/releases/tag/v2.0), is to clone plan9port's git repository into the `chroot`'ed filesystem and install it there, with its hard-coded paths adjusted through the `-r` option. Not only this improves the system's security, since patches can be applied immedately, but it also eliminates the need of work-arounds to make hard-coded paths work. |
| 60 | +The final solution, introduced in |
| 61 | +[v2.0](https://github.com/EdoardoLaGreca/werc-on-openbsd/releases/tag/v2.0), is |
| 62 | +to clone plan9port's git repository into the `chroot`'ed filesystem and install |
| 63 | +it there, with its hard-coded paths adjusted through the `-r` option. Not only |
| 64 | +this improves the system's security, since patches can be applied immedately, |
| 65 | +but it also eliminates the need of work-arounds to make hard-coded paths work. |
0 commit comments