Blob


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