1
0

snac.8 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. .Dd $Mdocdate$
  2. .Dt SNAC 8
  3. .Os
  4. .Sh NAME
  5. .Nm snac
  6. .Nd snac administration
  7. .Sh DESCRIPTION
  8. The
  9. .Nm
  10. daemon processes messages from other servers in the Fediverse
  11. using the ActivityPub protocol.
  12. .Pp
  13. This is the admin manual. For user operation, see
  14. .Xr snac 1 .
  15. For file and data formats, see
  16. .Xr snac 5 .
  17. .Ss Special cares about your snac you must know beforehand
  18. .Nm
  19. makes heavy use of hard links and link reference counts for its work, so
  20. don't even think of using it on a filesystem that doesn't support this
  21. feature. Most UNIX-like operating systems (Linux, the BSDs, the old DEC
  22. Ultrix machine in your grandfather basement, probably MacOS) support hard
  23. links on their native filesystems. Don't do fancy things like moving the
  24. subdirectories to different filesystems. Also, if you move your
  25. .Nm
  26. installation to another server, do it with a tool that respect hard
  27. link counts. Remember:
  28. .Nm
  29. is a very UNIXy program that loves hard links.
  30. .Ss Building and Installation
  31. A C compiler must be installed in the system, as well as the development
  32. headers and libraries for OpenSSL (or compatible) and curl. To build
  33. .Nm ,
  34. run
  35. .Bd -literal -offset indent
  36. make
  37. .Ed
  38. .Pp
  39. And, after that, run as root
  40. .Bd -literal -offset indent
  41. make install
  42. .Ed
  43. .Ss Data storage Initialization
  44. Once
  45. .Nm
  46. is properly installed on the system, designate a directory where
  47. the server and user data are to be stored. This directory
  48. must not exist yet.
  49. .Nm
  50. must always be run as a regular user; you can create one for
  51. it or use your own. To initialize the data storage, execute
  52. .Bd -literal -offset indent
  53. snac init $HOME/snac-data
  54. .Ed
  55. .Pp
  56. A small set of questions will be asked regarding the installation,
  57. specially the host name it will run under, the local network address
  58. and port
  59. .Nm
  60. will listen to, the optional path prefix and possibly other things.
  61. .Pp
  62. You can launch the
  63. .Nm
  64. process by running
  65. .Bd -literal -offset indent
  66. snac httpd $HOME/snac-data
  67. .Ed
  68. .Pp
  69. Use a web browser to connect to the specified address and port. You
  70. should see a greeting page.
  71. .Pp
  72. Log messages are sent to the standard error stream. By default, only
  73. relevant information is written there. You can increase the debugging
  74. level by editing the 'dbglevel' field in the
  75. .Pa server.json
  76. file or by setting a numeric value between 0 and 3 to the DEBUG
  77. environment variable, see below.
  78. .Pp
  79. If you operate a Linux systemd-enabled system, OpenBSD or FreeBSD, there are
  80. startup scripts and configuration data in the
  81. .Pa examples
  82. directory.
  83. For other operating systems, please read the appropriate documentation
  84. on how to install a daemon as a non-root service.
  85. .Ss Upgrading to a new version
  86. Sometimes, the data storage disk layout changes between versions. If there
  87. is such a change,
  88. .Nm
  89. will refuse to run and require an upgrade. Do this by running
  90. .Bd -literal -offset indent
  91. snac upgrade $HOME/snac-data
  92. .Ed
  93. .Pp
  94. Take special care to execute this upgrade operation without any
  95. .Nm
  96. processes serving on the same folder. You can break everything. I know
  97. this because Tyler knows this.
  98. .Pp
  99. .Ss Server Setup
  100. .Pp
  101. An http server with TLS and proxying support must already be
  102. installed and configured.
  103. .Nm
  104. runs as a daemon and listens on a TCP/IP socket, preferrably
  105. on a local interface. It can serve the full domain or only
  106. a directory. The http server must be configured to route to the
  107. .Nm
  108. socket all related traffic and also the webfinger standard
  109. address. The Host header must be propagated.
  110. See the examples below.
  111. .Ss Adding Users
  112. .Pp
  113. Users must be created from the command line.
  114. You can do it by running
  115. .Bd -literal -offset indent
  116. snac adduser $HOME/snac-data
  117. .Ed
  118. .Pp
  119. All needed data will be prompted for. There is no artificial limit
  120. on the number of users that can be created.
  121. .Ss Customization
  122. The
  123. .Pa server.json
  124. configuration file allows some behaviour tuning:
  125. .Bl -tag -width tenletters
  126. .It Ic host
  127. The host name.
  128. .It Ic prefix
  129. The URL path prefix.
  130. .It Ic address
  131. The listen network address.
  132. .It Ic port
  133. The listen network port.
  134. .It Ic dbglevel
  135. The debug level. An integer value, being 0 the less verbose (the default).
  136. .It Ic layout
  137. The disk storage layout version. Never touch this.
  138. .It Ic queue_retry_max
  139. Messages sent out are stored in a queue. If the posting of a messages fails,
  140. it's re-enqueued for later. This integer configures the maximum count of
  141. times the sending will be retried.
  142. .It Ic queue_retry_minutes
  143. The number of minutes to wait before the failed posting of a message is
  144. retried. This is not linear, but multipled by the number of retries
  145. already done.
  146. .It Ic max_timeline_entries
  147. This is the maximum timeline entries shown in the web interface.
  148. .It Ic timeline_purge_days
  149. Entries in the timeline older that this number of days are purged.
  150. If you don't want any timeline purging and enjoy your data drives
  151. fill up with old crap and finally burst in flames, you can disable
  152. purging by setting this to 0.
  153. .It Ic local_purge_days
  154. Same as before, but for the user-generated entries in the local timeline.
  155. .It Ic cssurls
  156. This is a list of URLs to CSS files that will be inserted, in this order,
  157. in the HTML before the user CSS. Use these files to configure the global
  158. site layout.
  159. .It Ic disable_cache
  160. If set to true, timeline caching is not done. This is only useful for
  161. debugging purposes; don't enable it unless you know what do you want, as
  162. it makes everything slower.
  163. .It Ic disable_openbsd_security
  164. If running under OpenBSD,
  165. .Nm
  166. makes use of the enhanced security functions
  167. .Xr unveil 2
  168. and
  169. .Xr pledge 2 .
  170. Setting this to true disables their usage. These functions limit severely
  171. what an intruder can do in case of a security vulnerability, so only enable
  172. this option if something is very broken.
  173. .It Ic num_threads
  174. By setting this value, you can specify the exact number of threads
  175. .Nm
  176. will use when processing connections. Values lesser than 4 will be ignored.
  177. .It Ic disable_email_notifications
  178. By setting this to true, no email notification will be sent for any user.
  179. .It Ic disable_inbox_collection
  180. By setting this to true, no inbox collection is done. Inbox collection helps
  181. being discovered from remote instances, but also increases network traffic.
  182. .It Ic http_headers
  183. If you need to add more HTTP response headers for whatever reason, you can
  184. fill this object with the required header/value pairs. For example, for enhanced
  185. XSS security, you can set the "Content-Security-Policy" header to "script-src ;"
  186. to be totally sure that no JavaScript is executed.
  187. .It Ic show_instance_timeline
  188. If this is set to true, the instance base URL will show a timeline with the latest
  189. user posts instead of the default greeting static page. If other information
  190. fields are set (see below), they are also shown.
  191. .It Ic admin_email
  192. The email address of the instance administrator (optional).
  193. .It Ic admin_account
  194. The user name of the instance administrator (optional).
  195. .It Ic short_description
  196. A textual short description about the instance (optional).
  197. .It Ic fastcgi
  198. If set to true,
  199. .Nm
  200. will use the FastCGI interface to communicate with the upper level
  201. http server, that must be configured accordingly.
  202. .It Ic disable_history
  203. If set to true, history monthly snapshots are not served nor their links shown.
  204. .It Ic shared_inboxes
  205. This boolean value selects if shared inboxes are announced or not. Enabling
  206. shared inboxes helps (somewhat) in optimizing incoming traffic for instances
  207. with a large number of users.
  208. .It Ic min_account_age
  209. If this numeric value (in seconds) is set, any activity coming from an account
  210. that was created more recently than that will be rejected. This may be used
  211. to mitigate spam from automatically created accounts.
  212. .It Ic protocol
  213. This string value contains the protocol (schema) to be used in URLs. If not
  214. set, it defaults to "https". If you run
  215. .Nm
  216. as part of a hidden network like Tor or I2P that doesn't have a TLS /
  217. Certificate infrastructure, you need to set it to "http". Don't change it
  218. unless you know what you are doing.
  219. .El
  220. .Pp
  221. You must restart the server to make effective these changes.
  222. .Pp
  223. If a file named
  224. .Pa greeting.html
  225. is present in the server base directory, it will be returned whenever
  226. the base URL of the server is requested. Fill it with whatever
  227. information about the instance you want to supply to people
  228. visiting the server, like sign up requirements, site policies
  229. and such. The special %userlist% mark in the file will cause
  230. the list of users in this instance to be inserted.
  231. .Pp
  232. Users can change a bit of information about themselves from the
  233. web interface. See
  234. .Xr snac 1
  235. for details. Further, every user can have a private CSS file in their
  236. .Pa static/style.css
  237. that will be served instead of the server-wide one.
  238. It's not modifiable from the web interface to avoid users
  239. shooting themselves in the foot by destroying everything.
  240. .Ss Custom Emojis
  241. From version 2.51, support for customized Emojis in posts is available
  242. (previously, they were hardcoded). Emojis are read from the
  243. .Pa emojis.json
  244. file in the instance base directory, as a JSON object of key / value
  245. pairs (if this file does not exist, it will be created with
  246. the predefined set). Each key in the object contains the text to be found (e.g.,
  247. the :-) for a smiling face), and its associated value, the text string that
  248. will replace it (in this example case, the HTML entity for the Unicode codepoint
  249. for the smiley or the Emoji itself as text).
  250. .Pp
  251. Emoji values can also be URLs to image files; in this case, they will not be
  252. substituted in the post content, but added to the 'tag' array as an ActivityPub
  253. standard 'Emoji' object (it's recommendable that the Emoji key be enclosed in
  254. colons for maximum compatilibity with other ActivityPub implementations, like
  255. e.g. :happydoggo:). These images can be served from an external source or from the
  256. .Pa static
  257. directory of the instance admin.
  258. .Pp
  259. If you want to disable any Emoji substitution, change the file to contain
  260. just an empty JSON object ({}).
  261. .Ss SPAM Mitigation
  262. There have been some SPAM attacks on the Fediverse and, as too many
  263. instances and server implementations out there still allow automatic
  264. account creation, it will only get worse.
  265. .Nm
  266. includes some (not very strong) tools for trying to survive the SPAM
  267. flood that will eventually happen.
  268. .Pp
  269. The
  270. .Ic min_account_age
  271. field in the main configuration file allows setting a minimum age (in
  272. seconds) to consider too recently created accounts suspicious of being
  273. a potential source of SPAM. This is a naïve assumption, because spammers
  274. can create accounts, let them dormant for a while and then start to use
  275. them. Also, some ActivityPub implementations don't even bother to return
  276. a creation date for their accounts, so this is not very useful.
  277. .Pp
  278. From version 2.50, post content can be filtered out by regular expressions.
  279. These weapons of mass destruction can be written into the
  280. .Ic filter_reject.txt
  281. file in the server base directory, one per line; if this file exists,
  282. all posts' content will be matched (after being stripped of HTML tags)
  283. against these regexes, one by one, and any match will make the post to
  284. be rejected. If you don't know about regular expressions, don't use this
  285. option (or learn about them in some tutorial, there are gazillions of
  286. them out there), as you and your users may start missing posts. Also,
  287. given that every regular expression implementation supports a different
  288. set of features, consider reading the documentation about the one
  289. implemented in your system.
  290. .Ss ActivityPub Support
  291. These are the following activities and objects that
  292. .Nm
  293. supports:
  294. .Bl -tag -width tenletters
  295. .It Vt Follow
  296. Complete support, on input and output.
  297. .It Vt Undo
  298. For
  299. .Vt Follow
  300. objects, on input and output.
  301. .It Vt Create
  302. For
  303. .Vt Note ,
  304. .Vt Question
  305. and
  306. .Vt Page
  307. objects, on input and output.
  308. .It Vt Accept
  309. For
  310. .Vt Follow
  311. objects, on input and output.
  312. .It Vt Like
  313. For
  314. .Vt Note
  315. objects, on input and output.
  316. .It Vt Announce
  317. For
  318. .Vt Note
  319. objects, on input and output.
  320. .It Vt Update
  321. For
  322. .Vt Person ,
  323. .Vt Note
  324. and
  325. .Vt Question
  326. objects, on input and output.
  327. .It Vt Delete
  328. Supported for
  329. .Vt Note
  330. and
  331. .Vt Tomsbtone
  332. objects on input, and for
  333. .Vt Note
  334. objects on output.
  335. .El
  336. .Pp
  337. The rest of activities and objects are dropped on input.
  338. .Pp
  339. There is partial support for
  340. .Vt OrderedCollection
  341. objects in the
  342. .Pa /outbox
  343. (with the last 20 entries of the local timeline shown). No pagination
  344. is supported. Intentionally, the
  345. .Pa /followers
  346. and
  347. .Pa /following
  348. paths return empty lists.
  349. .Ss Migrating from Mastodon
  350. User migration from different Fediverse instances is a pain in the ass
  351. that has been implemented everywhere as a kludgy afterthought. There is
  352. not much that can be done, other than importing the list of people you
  353. follow to your new
  354. .Nm
  355. account.
  356. .Pp
  357. To do this, download the user's list of accounts being followed (in CSV
  358. format) from the Mastodon web interface and execute this:
  359. .Bd -literal -offset indent
  360. awk -F, 'NR > 1 { print $1 }' /path/to/following_accounts.csv | \\
  361. xargs -n 1 snac follow $SNAC_BASEDIR $SNAC_USER
  362. .Ed
  363. .Ss Instance blocking
  364. Full instances can be blocked. This operation must be done from
  365. the command-line tool. See
  366. .Xr snac 1 .
  367. .Ss Other Considerations
  368. .Nm
  369. stores all the messages it receives as JSON files, which are usually
  370. bloated and filled with redundant information. Using a filesystem with
  371. file compression enabled (like btrfs or zfs) will probably be a good
  372. choice to store the
  373. .Nm
  374. data storage into.
  375. .Sh ENVIRONMENT
  376. .Bl -tag -width Ds
  377. .It Ev DEBUG
  378. Overrides the debugging level from the server 'dbglevel' configuration
  379. variable. Set it to an integer value. The higher, the deeper in meaningless
  380. verbiage you'll find yourself into.
  381. .El
  382. .Sh EXAMPLES
  383. You want to install the
  384. .Nm
  385. Fediverse daemon in the host example.com, that is correctly configured
  386. with a valid TLS certificate and running the nginx httpd server.
  387. The service will be installed under the
  388. .Pa fedi
  389. location. Two users, walter and jessie, will be hosted in the system.
  390. Their Fediverse presence addresses will be
  391. .Lk https://example.com/fedi/walter
  392. and
  393. .Lk https://example.com/fedi/jesse ,
  394. respectively. They will be known
  395. in the Fediverse as @walter@example.com and @jesse@example.com. The
  396. .Nm
  397. daemon will run as the user snacusr in the system and listen to the
  398. localhost:8001 network socket. All data will be stored in the
  399. .Pa /home/snacusr/fedidata
  400. directory.
  401. .Pp
  402. Log into the system as snacusr and execute:
  403. .Bd -literal -offset indent
  404. snac init /home/snacusr/fedidata
  405. .Ed
  406. .Pp
  407. Answer "example.com" to the host name question, "/fedi" to the path
  408. prefix question, "localhost" to the address and "8001" to the port.
  409. .Pp
  410. Create the users
  411. .Bd -literal -offset indent
  412. snac adduser /home/snacusr/fedidata walter
  413. snac adduser /home/snacusr/fedidata jesse
  414. .Ed
  415. .Pp
  416. Answer the questions with reasonable values.
  417. .Pp
  418. Execute the server:
  419. .Bd -literal -offset indent
  420. snac httpd /home/snacusr/fedidata
  421. .Ed
  422. .Pp
  423. Edit the nginx configuration and add the following snippet to the
  424. example.com server section:
  425. .Bd -literal -offset indent
  426. # nginx configuration example
  427. # main web access point
  428. location /fedi {
  429. proxy_pass http://localhost:8001;
  430. proxy_set_header Host $http_host;
  431. }
  432. # webfinger
  433. location /.well-known/webfinger {
  434. proxy_pass http://localhost:8001;
  435. proxy_set_header Host $http_host;
  436. }
  437. # Mastodon API (entry points)
  438. location /api/v1/ {
  439. proxy_pass http://localhost:8001;
  440. proxy_set_header Host $http_host;
  441. }
  442. location /api/v2/ {
  443. proxy_pass http://localhost:8001;
  444. proxy_set_header Host $http_host;
  445. }
  446. # Mastodon API (OAuth support)
  447. location /oauth {
  448. proxy_pass http://localhost:8001;
  449. proxy_set_header Host $http_host;
  450. }
  451. # optional
  452. location /.well-known/nodeinfo {
  453. proxy_pass http://localhost:8001;
  454. proxy_set_header Host $http_host;
  455. }
  456. # optional (needed by some Mastodon API clients)
  457. location /.well-known/host-meta {
  458. proxy_pass http://localhost:8001;
  459. proxy_set_header Host $http_host;
  460. }
  461. .Ed
  462. .Pp
  463. Restart the nginx daemon and connect to
  464. .Lk https://example.com/fedi/walter .
  465. The empty, default screen will be shown. Enter the admin section with the
  466. credentials defined for this user. Search people, start following
  467. them, engage in arid discussions and generally enjoy the frustrating
  468. experience of Social Media.
  469. .Pp
  470. This is an example of a similar configuration for the Apache2 web server:
  471. .Bd -literal -offset indent
  472. # apache2 configuration example
  473. ProxyPreserveHost On
  474. # Main web access point
  475. <Location /fedi>
  476. ProxyPass http://127.0.0.1:8001/social
  477. </Location>
  478. # WebFinger
  479. <Location /.well-known/webfinger>
  480. ProxyPass http://127.0.0.1:8001/.well-known/webfinger
  481. </Location>
  482. # Mastodon API (entry points)
  483. <Location /api/v1/>
  484. ProxyPass http://127.0.0.1:8001/api/v1/
  485. </Location>
  486. <Location /api/v2/>
  487. ProxyPass http://127.0.0.1:8001/api/v2/
  488. </Location>
  489. # Mastodon API (OAuth support)
  490. <Location /oauth>
  491. ProxyPass http://127.0.0.1:8001/oauth
  492. </Location>
  493. # NodeInfo (optional)
  494. <Location /.well-known/nodeinfo>
  495. ProxyPass http://127.0.0.1:8001/.well-known/nodeinfo
  496. </Location>
  497. # host-meta (optional, needed for some Mastodon API clients)
  498. <Location /.well-known/host-meta>
  499. ProxyPass http://127.0.0.1:8001/.well-known/host-meta
  500. </Location>
  501. .Ed
  502. .Pp
  503. Since version 2.43,
  504. .Nm
  505. supports communicating from / to the front end http server using the FastCGI
  506. protocol. There is no special advantage in using this, only that some servers
  507. allow for simpler configuration. For example, in the case of nginx, you can
  508. replace the two 'proxy_pass' and 'proxy_set_header' lines in the example
  509. above with just
  510. .Bd -literal -offset indent
  511. fastcgi_pass localhost:8001;
  512. .Ed
  513. .Pp
  514. The only thing to change on
  515. .Nm
  516. size is to the set 'fastcgi' value to true in
  517. .Pa server.json .
  518. .Pp
  519. Further, using the FastCGI interface allows a much simpler configuration
  520. under OpenBSD's native httpd, given that it's natively implemented there
  521. and you no longer need to configure the complicated relayd server. This is
  522. an example:
  523. .Bd -literal -offset indent
  524. # OpenBSD httpd configuration example
  525. # other server configuration
  526. [...]
  527. location "/fedi/*" {
  528. fastcgi socket tcp "127.0.0.1" 8001
  529. }
  530. location "/.well-known/webfinger" {
  531. fastcgi socket tcp "127.0.0.1" 8001
  532. }
  533. location "/oauth/*" {
  534. fastcgi socket tcp "127.0.0.1" 8001
  535. }
  536. location "/api/v1/*" {
  537. fastcgi socket tcp "127.0.0.1" 8001
  538. }
  539. location "/api/v2/*" {
  540. fastcgi socket tcp "127.0.0.1" 8001
  541. }
  542. location "/.well-known/nodeinfo" {
  543. fastcgi socket tcp "127.0.0.1" 8001
  544. }
  545. location "/.well-known/host-meta" {
  546. fastcgi socket tcp "127.0.0.1" 8001
  547. }
  548. .Ed
  549. .Sh SEE ALSO
  550. .Xr snac 1 ,
  551. .Xr snac 5
  552. .Sh AUTHORS
  553. .An grunfink Lk https://comam.es/snac/grunfink @grunfink@comam.es
  554. .Sh LICENSE
  555. See the LICENSE file for details.
  556. .Sh CAVEATS
  557. JSON files are fragile when modified by hand. Take care.