Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

openbsd_en.md 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. # Installing on OpenBSD
  2. This guide describes the installation and configuration of pleroma (and the required software to run it) on a single OpenBSD 6.6 server.
  3. For any additional information regarding commands and configuration files mentioned here, check the man pages [online](https://man.openbsd.org/) or directly on your server with the man command.
  4. #### Required software
  5. The following packages need to be installed:
  6. * elixir
  7. * gmake
  8. * git
  9. * postgresql-server
  10. * postgresql-contrib
  11. * cmake
  12. * ffmpeg
  13. * ImageMagick
  14. To install them, run the following command (with doas or as root):
  15. ```
  16. pkg_add elixir gmake git postgresql-server postgresql-contrib cmake ffmpeg ImageMagick
  17. ```
  18. Pleroma requires a reverse proxy, OpenBSD has relayd in base (and is used in this guide) and packages/ports are available for nginx (www/nginx) and apache (www/apache-httpd). Independently of the reverse proxy, [acme-client(1)](https://man.openbsd.org/acme-client) can be used to get a certificate from Let's Encrypt.
  19. #### Optional software
  20. Per [`docs/installation/optional/media_graphics_packages.md`](../installation/optional/media_graphics_packages.md):
  21. * ImageMagick
  22. * ffmpeg
  23. * exiftool
  24. To install the above:
  25. ```
  26. pkg_add ImageMagick ffmpeg p5-Image-ExifTool
  27. ```
  28. #### Creating the pleroma user
  29. Pleroma will be run by a dedicated user, \_pleroma. Before creating it, insert the following lines in login.conf:
  30. ```
  31. pleroma:\
  32. :datasize-max=1536M:\
  33. :datasize-cur=1536M:\
  34. :openfiles-max=4096
  35. ```
  36. This creates a "pleroma" login class and sets higher values than default for datasize and openfiles (see [login.conf(5)](https://man.openbsd.org/login.conf)), this is required to avoid having pleroma crash some time after starting.
  37. Create the \_pleroma user, assign it the pleroma login class and create its home directory (/home/\_pleroma/): `useradd -m -L pleroma _pleroma`
  38. #### Clone pleroma's directory
  39. Enter a shell as the \_pleroma user. As root, run `su _pleroma -;cd`. Then clone the repository with `git clone -b stable https://git.pleroma.social/pleroma/pleroma.git`. Pleroma is now installed in /home/\_pleroma/pleroma/, it will be configured and started at the end of this guide.
  40. #### PostgreSQL
  41. Start a shell as the \_postgresql user (as root run `su _postgresql -` then run the `initdb` command to initialize postgresql:
  42. You will need to specify pgdata directory to the default (/var/postgresql/data) with the `-D <path>` and set the user to postgres with the `-U <username>` flag. This can be done as follows:
  43. ```
  44. initdb -D /var/postgresql/data -U postgres
  45. ```
  46. If you are not using the default directory, you will have to update the `datadir` variable in the /etc/rc.d/postgresql script.
  47. When this is done, enable postgresql so that it starts on boot and start it. As root, run:
  48. ```
  49. rcctl enable postgresql
  50. rcctl start postgresql
  51. ```
  52. To check that it started properly and didn't fail right after starting, you can run `ps aux | grep postgres`, there should be multiple lines of output.
  53. #### httpd
  54. httpd will have three fuctions:
  55. * redirect requests trying to reach the instance over http to the https URL
  56. * serve a robots.txt file
  57. * get Let's Encrypt certificates, with acme-client
  58. Insert the following config in httpd.conf:
  59. ```
  60. # $OpenBSD: httpd.conf,v 1.17 2017/04/16 08:50:49 ajacoutot Exp $
  61. ext_inet="<IPv4 address>"
  62. ext_inet6="<IPv6 address>"
  63. server "default" {
  64. listen on $ext_inet port 80 # Comment to disable listening on IPv4
  65. listen on $ext_inet6 port 80 # Comment to disable listening on IPv6
  66. listen on 127.0.0.1 port 80 # Do NOT comment this line
  67. log syslog
  68. directory no index
  69. location "/.well-known/acme-challenge/*" {
  70. root "/acme"
  71. request strip 2
  72. }
  73. location "/robots.txt" { root "/htdocs/local/" }
  74. location "/*" { block return 302 "https://$HTTP_HOST$REQUEST_URI" }
  75. }
  76. types {
  77. }
  78. ```
  79. Do not forget to change *<IPv4/6 address\>* to your server's address(es). If httpd should only listen on one protocol family, comment one of the two first *listen* options.
  80. Create the /var/www/htdocs/local/ folder and write the content of your robots.txt in /var/www/htdocs/local/robots.txt.
  81. Check the configuration with `httpd -n`, if it is OK enable and start httpd (as root):
  82. ```
  83. rcctl enable httpd
  84. rcctl start httpd
  85. ```
  86. #### acme-client
  87. acme-client is used to get SSL/TLS certificates from Let's Encrypt.
  88. Insert the following configuration in /etc/acme-client.conf:
  89. ```
  90. #
  91. # $OpenBSD: acme-client.conf,v 1.4 2017/03/22 11:14:14 benno Exp $
  92. #
  93. authority letsencrypt-<domain name> {
  94. #agreement url "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf"
  95. api url "https://acme-v02.api.letsencrypt.org/directory"
  96. account key "/etc/acme/letsencrypt-privkey-<domain name>.pem"
  97. }
  98. domain <domain name> {
  99. domain key "/etc/ssl/private/<domain name>.key"
  100. domain certificate "/etc/ssl/<domain name>.crt"
  101. domain full chain certificate "/etc/ssl/<domain name>.fullchain.pem"
  102. sign with letsencrypt-<domain name>
  103. challengedir "/var/www/acme/"
  104. }
  105. ```
  106. Replace *<domain name\>* by the domain name you'll use for your instance. As root, run `acme-client -n` to check the config, then `acme-client -ADv <domain name>` to create account and domain keys, and request a certificate for the first time.
  107. Make acme-client run everyday by adding it in /etc/daily.local. As root, run the following command: `echo "acme-client <domain name>" >> /etc/daily.local`.
  108. Relayd will look for certificates and keys based on the address it listens on (see next part), the easiest way to make them available to relayd is to create a link, as root run:
  109. ```
  110. ln -s /etc/ssl/<domain name>.fullchain.pem /etc/ssl/<IP address>.crt
  111. ln -s /etc/ssl/private/<domain name>.key /etc/ssl/private/<IP address>.key
  112. ```
  113. This will have to be done for each IPv4 and IPv6 address relayd listens on.
  114. #### relayd
  115. relayd will be used as the reverse proxy sitting in front of pleroma.
  116. Insert the following configuration in /etc/relayd.conf:
  117. ```
  118. # $OpenBSD: relayd.conf,v 1.4 2018/03/23 09:55:06 claudio Exp $
  119. ext_inet="<IPv4 address>"
  120. ext_inet6="<IPv6 address>"
  121. table <pleroma_server> { 127.0.0.1 }
  122. table <httpd_server> { 127.0.0.1 }
  123. http protocol plerup { # Protocol for upstream pleroma server
  124. #tcp { nodelay, sack, socket buffer 65536, backlog 128 } # Uncomment and adjust as you see fit
  125. tls ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305"
  126. tls ecdhe secp384r1
  127. # Forward some paths to the local server (as pleroma won't respond to them as you might want)
  128. pass request quick path "/robots.txt" forward to <httpd_server>
  129. # Append a bunch of headers
  130. match request header append "X-Forwarded-For" value "$REMOTE_ADDR" # This two header and the next one are not strictly required by pleroma but adding them won't hurt
  131. match request header append "X-Forwarded-By" value "$SERVER_ADDR:$SERVER_PORT"
  132. match response header append "X-XSS-Protection" value "1; mode=block"
  133. match response header append "X-Permitted-Cross-Domain-Policies" value "none"
  134. match response header append "X-Frame-Options" value "DENY"
  135. match response header append "X-Content-Type-Options" value "nosniff"
  136. match response header append "Referrer-Policy" value "same-origin"
  137. match response header append "X-Download-Options" value "noopen"
  138. match response header append "Content-Security-Policy" value "default-src 'none'; base-uri 'self'; form-action 'self'; img-src 'self' data: https:; media-src 'self' https:; style-src 'self' 'unsafe-inline'; font-src 'self'; script-src 'self'; connect-src 'self' wss://CHANGEME.tld; upgrade-insecure-requests;" # Modify "CHANGEME.tld" and set your instance's domain here
  139. match request header append "Connection" value "upgrade"
  140. #match response header append "Strict-Transport-Security" value "max-age=31536000; includeSubDomains" # Uncomment this only after you get HTTPS working.
  141. # If you do not want remote frontends to be able to access your Pleroma backend server, comment these lines
  142. match response header append "Access-Control-Allow-Origin" value "*"
  143. match response header append "Access-Control-Allow-Methods" value "POST, PUT, DELETE, GET, PATCH, OPTIONS"
  144. match response header append "Access-Control-Allow-Headers" value "Authorization, Content-Type, Idempotency-Key"
  145. match response header append "Access-Control-Expose-Headers" value "Link, X-RateLimit-Reset, X-RateLimit-Limit, X-RateLimit-Remaining, X-Request-Id"
  146. # Stop commenting lines here
  147. }
  148. relay wwwtls {
  149. listen on $ext_inet port https tls # Comment to disable listening on IPv4
  150. listen on $ext_inet6 port https tls # Comment to disable listening on IPv6
  151. protocol plerup
  152. forward to <pleroma_server> port 4000 check http "/" code 200
  153. forward to <httpd_server> port 80 check http "/robots.txt" code 200
  154. }
  155. ```
  156. Again, change *<IPv4/6 address\>* to your server's address(es) and comment one of the two *listen* options if needed. Also change *wss://CHANGEME.tld* to *wss://<your instance's domain name\>*.
  157. Check the configuration with `relayd -n`, if it is OK enable and start relayd (as root):
  158. ```
  159. rcctl enable relayd
  160. rcctl start relayd
  161. ```
  162. #### pf
  163. Enabling and configuring pf is highly recommended.
  164. In /etc/pf.conf, insert the following configuration:
  165. ```
  166. # Macros
  167. if="<network interface>"
  168. authorized_ssh_clients="any"
  169. # Skip traffic on loopback interface
  170. set skip on lo
  171. # Default behavior
  172. set block-policy drop
  173. block in log all
  174. pass out quick
  175. # Security features
  176. match in all scrub (no-df random-id)
  177. block in log from urpf-failed
  178. # Rules
  179. pass in quick on $if inet proto icmp to ($if) icmp-type { echoreq unreach paramprob trace } # ICMP
  180. pass in quick on $if inet6 proto icmp6 to ($if) icmp6-type { echoreq unreach paramprob timex toobig } # ICMPv6
  181. pass in quick on $if proto tcp to ($if) port { http https } # relayd/httpd
  182. pass in quick on $if proto tcp from $authorized_ssh_clients to ($if) port ssh
  183. ```
  184. Replace *<network interface\>* by your server's network interface name (which you can get with ifconfig). Consider replacing the content of the authorized\_ssh\_clients macro by, for exemple, your home IP address, to avoid SSH connection attempts from bots.
  185. Check pf's configuration by running `pfctl -nf /etc/pf.conf`, load it with `pfctl -f /etc/pf.conf` and enable pf at boot with `rcctl enable pf`.
  186. #### Configure and start pleroma
  187. Enter a shell as \_pleroma (as root `su _pleroma -`) and enter pleroma's installation directory (`cd ~/pleroma/`).
  188. Then follow the main installation guide:
  189. * run `mix deps.get`
  190. * run `MIX_ENV=prod mix pleroma.instance gen` and enter your instance's information when asked
  191. * copy config/generated\_config.exs to config/prod.secret.exs. The default values should be sufficient but you should edit it and check that everything seems OK.
  192. * exit your current shell back to a root one and run `psql -U postgres -f /home/_pleroma/pleroma/config/setup_db.psql` to setup the database.
  193. * return to a \_pleroma shell into pleroma's installation directory (`su _pleroma -;cd ~/pleroma`) and run `MIX_ENV=prod mix ecto.migrate`
  194. As \_pleroma in /home/\_pleroma/pleroma, you can now run `LC_ALL=en_US.UTF-8 MIX_ENV=prod mix phx.server` to start your instance.
  195. In another SSH session/tmux window, check that it is working properly by running `ftp -MVo - http://127.0.0.1:4000/api/v1/instance`, you should get json output. Double-check that *uri*'s value is your instance's domain name.
  196. ##### Starting pleroma at boot
  197. An rc script to automatically start pleroma at boot hasn't been written yet, it can be run in a tmux session (tmux is in base).
  198. #### Create administrative user
  199. If your instance is up and running, you can create your first user with administrative rights with the following command as the \_pleroma user.
  200. ```
  201. LC_ALL=en_US.UTF-8 MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
  202. ```
  203. #### Further reading
  204. {! backend/installation/further_reading.include !}
  205. ## Questions
  206. Questions about the installation or didn’t it work as it should be, ask in [#pleroma:libera.chat](https://matrix.to/#/#pleroma:libera.chat) via Matrix or **#pleroma** on **libera.chat** via IRC.