Blob


1 # gmid
3 gmid is a Gemini server written with security in mind. I initially
4 wrote it to serve static files, but it has grown into a featureful
5 server that can be used from either the command line to serve local
6 directories
8 gmid docs # serve the directory docs over gemini
10 or as a traditional daemon
12 gmid -c /etc/gmid.conf
15 ## Features
17 (random order)
19 - reconfiguration: reload the running configuration without interruption
20 - sandboxed by default on OpenBSD, Linux and FreeBSD
21 - IRI support (RFC3987)
22 - punycode support
23 - dual stack (IPv4 and IPv6)
24 - automatic certificate generation for config-less mode
25 - CGI scripts
26 - (very) low memory footprint
27 - small codebase, easily hackable
28 - virtual hosts
29 - per-location rules
30 - optional directory listings
31 - configurable mime types
32 - chroot support
35 ## Drawbacks
37 - not suited for very busy hosts. If you receive an high number of
38 connection per-second you'd probably want to run multiple gmid
39 instances behind relayd/haproxy or a different server.
42 ## Internationalisation (IRIs, UNICODE, punycode, all that stuff)
44 Even thought the current Gemini specification doesn't mention anything
45 in this regard, I do think these are important things and so I tried
46 to implement them in the most user-friendly way I could think of.
48 For starters, gmid has full support for IRI (RFC3987 —
49 Internationalized Resource Identifiers). IRIs are a superset of URIs,
50 so there aren't incompatibilities with URI-only clients.
52 There is full support also for punycode. In theory, the user doesn't
53 even need to know that punycode is a thing. The hostname in the
54 configuration file can (and must be) in the decoded form (e.g. `naïve`
55 and not `xn--nave-6pa`), gmid will do the rest.
57 The only missing piece is UNICODE normalisation of the IRI path: gmid
58 doesn't do that (yet).
61 ## Building
63 gmid depends on a POSIX libc, OpenSSL/LibreSSL and libtls (provided
64 either by LibreSSL or libretls). At build time, flex and yacc (or GNU
65 bison) are also needed.
67 The build is as simple as
69 ./configure
70 make
72 If the configure scripts fails to pick up something, please open an
73 issue or notify me via email.
75 To install execute:
77 make install
79 ### Docker
81 If you have trouble installing LibreSSL or libretls, you can use
82 Docker to build a `gmid` image with:
84 docker build -t gmid .
86 and then run it with something along the lines of
88 docker run --rm -it -p 1965:1965 \
89 -v /path/to/gmid.conf:...:ro \
90 -v /path/to/docs:/var/gemini \
91 gmid -c .../gmid.conf
93 (ellipses used for brevity)
95 ### Local libretls
97 This is **NOT** recommended, please try to port LibreSSL/LibreTLS to
98 your distribution of choice or use docker instead.
100 However, it's possible to statically-link `gmid` to locally-installed
101 libretls quite easily. (It's how I test gmid on Fedora, for instance)
103 Let's say you have compiled and installed libretls in `$LIBRETLS`,
104 then you can build `gmid` with
106 ./configure CFLAGS="-I$LIBRETLS/include" \
107 LDFLAGS="$LIBRETLS/lib/libtls.a -lssl -lcrypto -lpthread"
108 make
110 ### Testing
112 Execute
114 make regress
116 to start the suite. Keep in mind that the regression tests will
117 create files inside the `regress` directory and bind the 10965 port.
120 ## Architecture/Security considerations
122 gmid is composed by two processes: a listener and an executor. The
123 listener process is the only one that needs internet access and is
124 sandboxed. When a CGI script needs to be executed, the executor
125 (outside of the sandbox) sets up a pipe and gives one end to the
126 listener, while the other is bound to the CGI script standard output.
127 This way, is still possible to execute CGI scripts without
128 restrictions even in the presence of a sandboxed network process.
130 On OpenBSD, the listener runs with the `stdio recvfd rpath inet`
131 pledges, while the executor has `stdio sendfd proc exec`; both have
132 unveiled only the served directories.
134 On FreeBSD, the executor process is sandboxed with `capsicum(4)`.
136 On Linux, a `seccomp(2)` filter is installed in the listener to allow
137 only certain syscalls, see [sandbox.c](sandbox.c) for more information
138 on the BPF program.
140 In any case, you are invited to run gmid inside some sort of
141 container/jail/chroot.