Blame


1 b9220ca4 2021-01-11 op # gmid
2 3e4749f7 2020-10-02 op
3 b9231167 2021-02-08 op gmid is a fast Gemini server written with security in mind. I
4 b9231167 2021-02-08 op initially wrote it to serve static files, but it has grown into a
5 747b35d0 2021-02-08 op featureful server.
6 3e4749f7 2020-10-02 op
7 3e4749f7 2020-10-02 op
8 b9220ca4 2021-01-11 op ## Features
9 3e4749f7 2020-10-02 op
10 601bc1cc 2021-01-30 op (random order)
11 601bc1cc 2021-01-30 op
12 08ce6f52 2021-04-29 op - sandboxed by default on OpenBSD, Linux and FreeBSD
13 747b35d0 2021-02-08 op - reconfiguration: reload the running configuration without
14 747b35d0 2021-02-08 op interruption
15 290b5baa 2021-02-23 op - automatic redirect/error pages (see `block return`)
16 4d2ec6d7 2021-01-13 op - IRI support (RFC3987)
17 601bc1cc 2021-01-30 op - automatic certificate generation for config-less mode
18 c3eb759a 2021-12-29 op - reverse proxying
19 a6c80955 2021-06-11 op - CGI and FastCGI support
20 08ce6f52 2021-04-29 op - virtual hosts
21 08ce6f52 2021-04-29 op - location rules
22 b9231167 2021-02-08 op - event-based asynchronous I/O model
23 08ce6f52 2021-04-29 op - low memory footprint
24 b9220ca4 2021-01-11 op - small codebase, easily hackable
25 3e4749f7 2020-10-02 op
26 fab952e1 2020-10-03 op
27 286c4f40 2021-01-27 op ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
28 286c4f40 2021-01-27 op
29 286c4f40 2021-01-27 op Even thought the current Gemini specification doesn't mention anything
30 601bc1cc 2021-01-30 op in this regard, I do think these are important things and so I tried
31 601bc1cc 2021-01-30 op to implement them in the most user-friendly way I could think of.
32 286c4f40 2021-01-27 op
33 601bc1cc 2021-01-30 op For starters, gmid has full support for IRI (RFC3987 —
34 22a742e4 2021-01-29 op Internationalized Resource Identifiers). IRIs are a superset of URIs,
35 286c4f40 2021-01-27 op so there aren't incompatibilities with URI-only clients.
36 286c4f40 2021-01-27 op
37 601bc1cc 2021-01-30 op There is full support also for punycode. In theory, the user doesn't
38 286c4f40 2021-01-27 op even need to know that punycode is a thing. The hostname in the
39 601bc1cc 2021-01-30 op configuration file can (and must be) in the decoded form (e.g. `naïve`
40 601bc1cc 2021-01-30 op and not `xn--nave-6pa`), gmid will do the rest.
41 286c4f40 2021-01-27 op
42 601bc1cc 2021-01-30 op The only missing piece is UNICODE normalisation of the IRI path: gmid
43 601bc1cc 2021-01-30 op doesn't do that (yet).
44 286c4f40 2021-01-27 op
45 286c4f40 2021-01-27 op
46 1487e11e 2021-02-06 op ## Configuration
47 1487e11e 2021-02-06 op
48 1487e11e 2021-02-06 op gmid has a rich configuration file, heavily inspired by OpenBSD'
49 08ce6f52 2021-04-29 op httpd, with every detail carefully documented in the manpage. Here's
50 08ce6f52 2021-04-29 op a minimal example of a config file:
51 1487e11e 2021-02-06 op
52 1487e11e 2021-02-06 op ```conf
53 08ce6f52 2021-04-29 op server "example.com" {
54 08ce6f52 2021-04-29 op cert "/path/to/cert.pem"
55 08ce6f52 2021-04-29 op key "/path/to/key.pem"
56 08ce6f52 2021-04-29 op root "/var/gemini/example.com"
57 08ce6f52 2021-04-29 op }
58 08ce6f52 2021-04-29 op ```
59 08ce6f52 2021-04-29 op
60 3759d3eb 2021-07-06 op and a slightly more complex one
61 08ce6f52 2021-04-29 op
62 08ce6f52 2021-04-29 op ```conf
63 1487e11e 2021-02-06 op ipv6 on # enable ipv6
64 1487e11e 2021-02-06 op
65 3759d3eb 2021-07-06 op # define a macro
66 3759d3eb 2021-07-06 op cert_root = "/path/to/keys"
67 3759d3eb 2021-07-06 op
68 1487e11e 2021-02-06 op server "example.com" {
69 08ce6f52 2021-04-29 op alias "foobar.com"
70 1487e11e 2021-02-06 op
71 3759d3eb 2021-07-06 op cert $cert_root "/example.com.crt"
72 3759d3eb 2021-07-06 op key $cert_root "/example.com.pem"
73 08ce6f52 2021-04-29 op root "/var/gemini/example.com"
74 1487e11e 2021-02-06 op
75 08ce6f52 2021-04-29 op # lang for text/gemini files
76 3759d3eb 2021-07-06 op lang "en"
77 08ce6f52 2021-04-29 op
78 08ce6f52 2021-04-29 op # execute CGI scripts in /cgi/
79 8070ffa7 2021-04-29 op cgi "/cgi/*"
80 08ce6f52 2021-04-29 op
81 08ce6f52 2021-04-29 op # only for locations that matches /files/*
82 08ce6f52 2021-04-29 op location "/files/*" {
83 08ce6f52 2021-04-29 op # generate directory listings
84 08ce6f52 2021-04-29 op auto index on
85 08ce6f52 2021-04-29 op }
86 08ce6f52 2021-04-29 op
87 08ce6f52 2021-04-29 op location "/repo/*" {
88 08ce6f52 2021-04-29 op # change the index file name
89 08ce6f52 2021-04-29 op index "README.gmi"
90 3759d3eb 2021-07-06 op lang "it"
91 08ce6f52 2021-04-29 op }
92 1487e11e 2021-02-06 op }
93 1487e11e 2021-02-06 op ```
94 1487e11e 2021-02-06 op
95 1487e11e 2021-02-06 op
96 b9220ca4 2021-01-11 op ## Building
97 3e4749f7 2020-10-02 op
98 b9231167 2021-02-08 op gmid depends on a POSIX libc, libevent2, OpenSSL/LibreSSL and libtls
99 74f0778b 2021-06-16 op (provided either by LibreSSL or libretls). At build time, yacc (or
100 74f0778b 2021-06-16 op GNU bison) is also needed.
101 3e4749f7 2020-10-02 op
102 771d8f28 2021-01-17 op The build is as simple as
103 3e4749f7 2020-10-02 op
104 601bc1cc 2021-01-30 op ./configure
105 b9220ca4 2021-01-11 op make
106 3e4749f7 2020-10-02 op
107 2ddc9271 2021-03-29 op or `make static` to build a statically-linked executable.
108 2ddc9271 2021-03-29 op
109 8f0da580 2021-01-21 op If the configure scripts fails to pick up something, please open an
110 f980545b 2021-01-21 op issue or notify me via email.
111 8f0da580 2021-01-21 op
112 771d8f28 2021-01-17 op To install execute:
113 881a9dd9 2021-01-16 op
114 771d8f28 2021-01-17 op make install
115 771d8f28 2021-01-17 op
116 bb4be662 2021-04-25 op Please keep in mind that the master branch, from time to time, may be
117 bb4be662 2021-04-25 op accidentally broken on some platforms. gmid is developed primarily on
118 bb4be662 2021-04-25 op OpenBSD/amd64 and commits on the master branch don't get always tested
119 bb4be662 2021-04-25 op in other OSes. Before tagging a release however, a comprehensive
120 c79b63f5 2021-04-27 op testing on various platform is done to ensure that everything is
121 c79b63f5 2021-04-27 op working as intended.
122 bb4be662 2021-04-25 op
123 bb4be662 2021-04-25 op
124 601bc1cc 2021-01-30 op ### Docker
125 771d8f28 2021-01-17 op
126 dbbfd0fb 2021-07-11 op If you have trouble installing LibreSSL or libretls, in `contrib`
127 dbbfd0fb 2021-07-11 op there's a sample Dockerfile. See [the contrib page][contrib-page] for
128 dbbfd0fb 2021-07-11 op more information.
129 601bc1cc 2021-01-30 op
130 dbbfd0fb 2021-07-11 op [contrib-page]: https://gmid.omarpolo.com/contrib.html#dockerfile
131 17b09e3c 2021-01-18 op
132 dd8cc7d3 2021-01-22 op ### Local libretls
133 17b09e3c 2021-01-18 op
134 8f0da580 2021-01-21 op This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
135 8f0da580 2021-01-21 op your distribution of choice or use docker instead.
136 8f0da580 2021-01-21 op
137 601bc1cc 2021-01-30 op However, it's possible to statically-link `gmid` to locally-installed
138 601bc1cc 2021-01-30 op libretls quite easily. (It's how I test gmid on Fedora, for instance)
139 8f0da580 2021-01-21 op
140 04397b32 2021-01-21 op Let's say you have compiled and installed libretls in `$LIBRETLS`,
141 8f0da580 2021-01-21 op then you can build `gmid` with
142 8f0da580 2021-01-21 op
143 04397b32 2021-01-21 op ./configure CFLAGS="-I$LIBRETLS/include" \
144 1606927e 2021-02-11 op LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread -levent"
145 8f0da580 2021-01-21 op make
146 8f0da580 2021-01-21 op
147 dd8cc7d3 2021-01-22 op ### Testing
148 dd8cc7d3 2021-01-22 op
149 31a4993a 2021-01-23 op Execute
150 dd8cc7d3 2021-01-22 op
151 dd8cc7d3 2021-01-22 op make regress
152 dd8cc7d3 2021-01-22 op
153 601bc1cc 2021-01-30 op to start the suite. Keep in mind that the regression tests will
154 601bc1cc 2021-01-30 op create files inside the `regress` directory and bind the 10965 port.
155 dd8cc7d3 2021-01-22 op
156 dd8cc7d3 2021-01-22 op
157 881a9dd9 2021-01-16 op ## Architecture/Security considerations
158 881a9dd9 2021-01-16 op
159 290b5baa 2021-02-23 op gmid is composed by four processes: the parent process, the logger,
160 290b5baa 2021-02-23 op the listener and the executor. The parent process is the only one
161 290b5baa 2021-02-23 op that doesn't drop privileges, but all it does is to wait for a SIGHUP
162 290b5baa 2021-02-23 op to reload the configuration and spawn a new generation of children
163 e58a447a 2021-07-29 op process. The logger process gathers the logs and prints 'em to
164 290b5baa 2021-02-23 op stderr or syslog (for the time being.) The listener process is the
165 290b5baa 2021-02-23 op only one that needs internet access and is sandboxed by default. The
166 be52e954 2021-07-09 op executor process exists only to fork and execute CGI scripts, and
167 be52e954 2021-07-09 op optionally to connect to FastCGI applications.
168 881a9dd9 2021-01-16 op
169 dcfdb969 2021-10-24 op On OpenBSD the processes are all `pledge(2)`d and `unveil(2)`ed.
170 881a9dd9 2021-01-16 op
171 94be0bf0 2021-03-20 op On FreeBSD, the listener and logger process are sandboxed with `capsicum(4)`.
172 d939d0f0 2021-01-17 op
173 601bc1cc 2021-01-30 op On Linux, a `seccomp(2)` filter is installed in the listener to allow
174 601bc1cc 2021-01-30 op only certain syscalls, see [sandbox.c](sandbox.c) for more information
175 67c49bc5 2021-09-19 op about the BPF program. If available, landlock is used to limit the
176 67c49bc5 2021-09-19 op portion of the file system gmid can access (requires linux 5.13+.)
177 ea58dab1 2021-01-17 op
178 6957a8c2 2021-06-04 op In any case, it's advisable to run gmid inside some sort of
179 0b00962d 2021-01-25 op container/jail/chroot.