logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

onion_federation.md (5237B)


  1. # Easy Onion Federation (Tor)
  2. Tor can free people from the necessity of a domain, in addition to helping protect their privacy. As Pleroma's goal is to empower the people and let as many as possible host an instance with as little resources as possible, the ability to host an instance with a small, cheap computer like a RaspberryPi along with Tor, would be a great way to achieve that.
  3. In addition, federating with such instances will also help furthering that goal.
  4. This is a guide to show you how it can be easily done.
  5. This guide assumes you already got Pleroma working, and that it's running on the default port 4000.
  6. Currently only has an Nginx example.
  7. To install Tor on Debian / Ubuntu:
  8. ```
  9. apt -yq install tor
  10. ```
  11. If using an old server version (older than Debian Stretch or Ubuntu 18.04), install from backports or PPA.
  12. I recommend using a newer server version instead.
  13. To have the newest, V3 onion addresses (which I recommend) in Debian, install Tor from backports.
  14. If you do not have backports, uncomment the stretch-backports links at the end of `/etc/apt/sources.list`.
  15. Then install:
  16. ```
  17. apt update
  18. apt -t stretch-backports -yq install tor
  19. ```
  20. **WARNING:** Onion instances not using a Tor version supporting V3 addresses will not be able to federate with you.
  21. Create the hidden service for your Pleroma instance in `/etc/tor/torrc`:
  22. ```
  23. HiddenServiceDir /var/lib/tor/pleroma_hidden_service/
  24. HiddenServicePort 80 127.0.0.1:8099
  25. HiddenServiceVersion 3 # Remove if Tor version is below 0.3 ( tor --version )
  26. ```
  27. Restart Tor to generate an address:
  28. ```
  29. systemctl restart tor@default.service
  30. ```
  31. Get the address:
  32. ```
  33. cat /var/lib/tor/pleroma_hidden_service/hostname
  34. ```
  35. # Federation
  36. Next, edit your Pleroma config.
  37. If running in prod, cd to your Pleroma directory, edit `config/prod.secret.exs`
  38. and append this line:
  39. ```
  40. config :pleroma, :http, proxy_url: {:socks5, :localhost, 9050}
  41. ```
  42. In your Pleroma directory, assuming you're running prod,
  43. run the following:
  44. ```
  45. su pleroma
  46. MIX_ENV=prod mix deps.get
  47. MIX_ENV=prod mix ecto.migrate
  48. exit
  49. ```
  50. restart Pleroma (if using systemd):
  51. ```
  52. systemctl restart pleroma
  53. ```
  54. # Tor Instance Access
  55. Make your instance accessible using Tor.
  56. ## Tor-only Instance
  57. If creating a Tor-only instance, open `config/prod.secret.exs` and under "config :pleroma, Pleroma.Web.Endpoint," edit "https" and "port: 443" to the following:
  58. ```
  59. url: [host: "onionaddress", scheme: "http", port: 80],
  60. ```
  61. In addition to that, replace the existing nginx config's contents with the example below.
  62. ## Existing Instance (Clearnet Instance)
  63. If not a Tor-only instance,
  64. add the nginx config below to your existing config at `/etc/nginx/sites-enabled/pleroma.nginx`.
  65. ---
  66. For both cases, disable CSP in Pleroma's config (STS is disabled by default) so you can define those yourself separately from the clearnet (if your instance is also on the clearnet).
  67. Copy the following into the `config/prod.secret.exs` in your Pleroma folder (/home/pleroma/pleroma/):
  68. ```
  69. config :pleroma, :http_security,
  70. enabled: false
  71. ```
  72. Use this as the Nginx config:
  73. ```
  74. proxy_cache_path /tmp/pleroma-media-cache levels=1:2 keys_zone=pleroma_media_cache:10m max_size=10g inactive=720m use_temp_path=off;
  75. # The above already exists in a clearnet instance's config.
  76. # If not, add it.
  77. server {
  78. listen 127.0.0.1:8099;
  79. server_name youronionaddress;
  80. # Comment to enable logs
  81. access_log /dev/null;
  82. error_log /dev/null;
  83. gzip_vary on;
  84. gzip_proxied any;
  85. gzip_comp_level 6;
  86. gzip_buffers 16 8k;
  87. gzip_http_version 1.1;
  88. gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
  89. client_max_body_size 16m;
  90. location / {
  91. add_header X-XSS-Protection "1; mode=block";
  92. add_header X-Permitted-Cross-Domain-Policies none;
  93. add_header X-Frame-Options DENY;
  94. add_header X-Content-Type-Options nosniff;
  95. add_header Referrer-Policy same-origin;
  96. add_header X-Download-Options noopen;
  97. proxy_http_version 1.1;
  98. proxy_set_header Upgrade $http_upgrade;
  99. proxy_set_header Connection "upgrade";
  100. proxy_set_header Host $http_host;
  101. proxy_pass http://localhost:4000;
  102. client_max_body_size 16m;
  103. }
  104. location /proxy {
  105. proxy_cache pleroma_media_cache;
  106. proxy_cache_lock on;
  107. proxy_ignore_client_abort on;
  108. proxy_pass http://localhost:4000;
  109. }
  110. }
  111. ```
  112. reload Nginx:
  113. ```
  114. systemctl reload nginx
  115. ```
  116. You should now be able to both access your instance using Tor and federate with other Tor instances!
  117. ---
  118. ### Possible Issues
  119. * In Debian, make sure your hidden service folder `/var/lib/tor/pleroma_hidden_service/` and its contents, has debian-tor as both owner and group by using
  120. ```
  121. ls -la /var/lib/tor/
  122. ```
  123. If it's not, run:
  124. ```
  125. chown -R debian-tor:debian-tor /var/lib/tor/pleroma_hidden_service/
  126. ```
  127. * Make sure *only* the owner has *only* read and write permissions.
  128. If not, run:
  129. ```
  130. chmod -R 600 /var/lib/tor/pleroma_hidden_service/
  131. ```
  132. * If you have trouble logging in to the Mastodon Frontend when using Tor, use the Tor Browser Bundle.