stdiscosrv.1 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "STDISCOSRV" "1" "Feb 29, 2024" "v1.27.3" "Syncthing"
  31. .SH NAME
  32. stdiscosrv \- Syncthing Discovery Server
  33. .SH SYNOPSIS
  34. .INDENT 0.0
  35. .INDENT 3.5
  36. .sp
  37. .nf
  38. .ft C
  39. stdiscosrv [\-cert=<file>] [\-db\-dir=<string>] [\-debug] [\-http] [\-key=<string>]
  40. [\-listen=<address>] [\-metrics\-listen=<address>]
  41. [\-replicate=<peers>] [\-replication\-listen=<address>]
  42. .ft P
  43. .fi
  44. .UNINDENT
  45. .UNINDENT
  46. .SH DESCRIPTION
  47. .sp
  48. Syncthing relies on a discovery server to find peers on the internet. Anyone
  49. can run a discovery server and point Syncthing installations to it. The
  50. Syncthing project also maintains a global cluster for public use.
  51. .SH OPTIONS
  52. .INDENT 0.0
  53. .TP
  54. .B \-cert=<file>
  55. Certificate file (default “./cert.pem”).
  56. .UNINDENT
  57. .INDENT 0.0
  58. .TP
  59. .B \-db\-dir=<string>
  60. Database directory, where data is stored (default “./discovery.db”).
  61. .UNINDENT
  62. .INDENT 0.0
  63. .TP
  64. .B \-debug
  65. Enable debug output.
  66. .UNINDENT
  67. .INDENT 0.0
  68. .TP
  69. .B \-http
  70. Listen on HTTP (behind an HTTPS proxy).
  71. .UNINDENT
  72. .INDENT 0.0
  73. .TP
  74. .B \-key=<file>
  75. Key file (default “./key.pem”).
  76. .UNINDENT
  77. .INDENT 0.0
  78. .TP
  79. .B \-listen=<address>
  80. Listen address (default “:8443”).
  81. .UNINDENT
  82. .INDENT 0.0
  83. .TP
  84. .B \-metrics\-listen=<address>
  85. Prometheus compatible metrics endpoint listen address (default disabled).
  86. .UNINDENT
  87. .INDENT 0.0
  88. .TP
  89. .B \-replicate=<peers>
  90. Replication peers, \fI\%id@address\fP <\fBid@address\fP>, comma separated
  91. .UNINDENT
  92. .INDENT 0.0
  93. .TP
  94. .B \-replication\-listen=<address>
  95. Listen address for incoming replication connections (default “:19200”).
  96. .UNINDENT
  97. .SH POINTING SYNCTHING AT YOUR DISCOVERY SERVER
  98. .sp
  99. By default, Syncthing uses a number of global discovery servers, signified by
  100. the entry \fBdefault\fP in the list of discovery servers. To make Syncthing use
  101. your own instance of stdiscosrv, open up Syncthing’s web GUI. Go to settings,
  102. Global Discovery Server and add stdiscosrv’s host address to the comma\-separated
  103. list, e.g. \fBhttps://disco.example.com:8443/\fP\&. Note that stdiscosrv uses port
  104. 8443 by default. For stdiscosrv to be available over the internet with a dynamic
  105. IP address, you will need a dynamic DNS service.
  106. .sp
  107. Deprecated since version v0.14.44: Prior versions need \fB/v2/\fP appended to the discovery
  108. server address, e.g. \fBhttps://disco.example.com:8443/v2/\fP\&.
  109. .sp
  110. If you wish to use \fIonly\fP your own discovery server, remove the \fBdefault\fP
  111. entry from the list.
  112. .SH SETTING UP
  113. .SS Description
  114. .sp
  115. This guide assumes that you have already set up Syncthing. If you
  116. haven’t yet, head over to \fI\%Getting Started\fP first.
  117. .SS Installing
  118. .sp
  119. Go to \fI\%releases\fP <\fBhttps://github.com/syncthing/discosrv/releases\fP> and
  120. download the file appropriate for your operating system. Unpacking it will
  121. yield a binary called \fBstdiscosrv\fP (or \fBstdiscosrv.exe\fP on Windows).
  122. Start this in whatever way you are most comfortable with; double clicking
  123. should work in any graphical environment. At first start, stdiscosrv will
  124. generate certificate files and database in the current directory unless
  125. given flags to the contrary.
  126. .sp
  127. The discovery server can also be obtained through apt, the Debian/Ubuntu package
  128. manager. Recent releases can be found at syncthing’s
  129. \fI\%apt repository\fP <\fBhttps://apt.syncthing.net/\fP>\&. The name of the package is
  130. syncthing\-discosrv.
  131. .SS Configuring
  132. .sp
  133. \fBNOTE:\fP
  134. .INDENT 0.0
  135. .INDENT 3.5
  136. If you are running an instance of Syncthing on the discovery server,
  137. you must either add that instance to other devices using a static
  138. address or bind the discovery server and Syncthing instances to
  139. different IP addresses.
  140. .UNINDENT
  141. .UNINDENT
  142. .SS Certificates
  143. .sp
  144. The discovery server provides service over HTTPS. To ensure secure connections
  145. from clients there are three options:
  146. .INDENT 0.0
  147. .IP \(bu 2
  148. Use a CA\-signed certificate pair for the domain name you will use for the
  149. discovery server. This is like any other HTTPS website; clients will
  150. authenticate the server based on its certificate and domain name.
  151. .IP \(bu 2
  152. Use any certificate pair and let clients authenticate the server based on
  153. its “device ID” (similar to Syncthing\-to\-Syncthing authentication). This
  154. option can be used with the certificate automatically generated by the
  155. discovery server.
  156. .IP \(bu 2
  157. Pass the \fB\-http\fP flag if the discovery server is behind an SSL\-secured
  158. reverse proxy. See below for configuration.
  159. .UNINDENT
  160. .sp
  161. For the first two options, the discovery server must be given the paths to
  162. the certificate and key at startup. This isn’t necessary with the \fBhttp\fP flag:
  163. .INDENT 0.0
  164. .INDENT 3.5
  165. .sp
  166. .nf
  167. .ft C
  168. $ stdiscosrv \-cert=/path/to/cert.pem \-key=/path/to/key.pem
  169. Server device ID is 7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  170. .ft P
  171. .fi
  172. .UNINDENT
  173. .UNINDENT
  174. .sp
  175. The discovery server prints its device ID at startup. In case you are using
  176. a non CA signed certificate, this device ID (fingerprint) must be given to
  177. the clients in the discovery server URL:
  178. .INDENT 0.0
  179. .INDENT 3.5
  180. .sp
  181. .nf
  182. .ft C
  183. https://disco.example.com:8443/?id=7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  184. .ft P
  185. .fi
  186. .UNINDENT
  187. .UNINDENT
  188. .sp
  189. Otherwise, the URL will be:
  190. .INDENT 0.0
  191. .INDENT 3.5
  192. .sp
  193. .nf
  194. .ft C
  195. https://disco.example.com:8443/
  196. .ft P
  197. .fi
  198. .UNINDENT
  199. .UNINDENT
  200. .SS Replication
  201. .sp
  202. The discovery server can be deployed in a redundant, load sharing fashion.
  203. In this mode announcements are replicated from the server that receives them
  204. to other peer servers and queries can be answered equally by all servers.
  205. .sp
  206. Replication connections are encrypted and authenticated using TLS. The
  207. certificate is selected by the \fB\-cert\fP and \fB\-key\fP options and is thus
  208. shared with the main discovery API. If the \fB\-http\fP mode is used the
  209. certificate is not used for client requests but only for replication
  210. connections.
  211. .sp
  212. Authentication of replication connections is done using \fI\%Syncthing\-style
  213. device IDs\fP <\fBhttps://docs.syncthing.net/dev/device-ids.html#id1\fP> only \- CA
  214. verification is not available. The device IDs in question are those printed
  215. by the discovery server on startup.
  216. .sp
  217. Replication connections are unidirectional \- announcements are replication
  218. from the \fBsender\fP to a \fBlistener\fP\&. In order to have a bidirectional
  219. replication relationship between two servers both need to be configured as
  220. sender and listener.
  221. .sp
  222. As an example, lets assume two discovery servers:
  223. .INDENT 0.0
  224. .IP \(bu 2
  225. Server one is on 192.0.2.20 and has certificate ID I6K…H76
  226. .IP \(bu 2
  227. Server two is on 192.0.2.55 and has certificate ID MRI…7OK
  228. .UNINDENT
  229. .sp
  230. In order for both to replicate to the other and thus form a redundant pair,
  231. use the following commands.
  232. .sp
  233. On server one:
  234. .INDENT 0.0
  235. .INDENT 3.5
  236. .sp
  237. .nf
  238. .ft C
  239. $ stdiscosrv \-replicate=MRI...7OK@192.0.2.55:19200 <other options>
  240. .ft P
  241. .fi
  242. .UNINDENT
  243. .UNINDENT
  244. .sp
  245. On server two:
  246. .INDENT 0.0
  247. .INDENT 3.5
  248. .sp
  249. .nf
  250. .ft C
  251. $ stdiscosrv \-replicate=I6K...H76@192.0.2.20:19200 <other options>
  252. .ft P
  253. .fi
  254. .UNINDENT
  255. .UNINDENT
  256. .sp
  257. The \fB\-replicate\fP directive sets which remote device IDs are expected and
  258. allowed for both outgoing (sending) and incoming (listening) connections,
  259. and which addresses to use when connecting out to those peers. Both IP and
  260. port must be specified in peer addresses.
  261. .sp
  262. It is possible to only allow incoming connections from a peer without
  263. establishing an outgoing replication connection. To do so, give only the
  264. device ID without “@ip:port” address:
  265. .INDENT 0.0
  266. .INDENT 3.5
  267. .sp
  268. .nf
  269. .ft C
  270. $ stdiscosrv \-replicate=I6K...H76 <other options>
  271. .ft P
  272. .fi
  273. .UNINDENT
  274. .UNINDENT
  275. .sp
  276. Discosrv will listen on the replication port only when \fB\-replicate\fP is
  277. given. The default replication listen address is “:19200”.
  278. .sp
  279. To achieve load balancing over two mutually replicating discovery server
  280. instances, add multiple A / AAAA DNS records for a given name and point
  281. Syncthing towards this name. The same certificate must be used on both
  282. discovery servers.
  283. .SS Reverse Proxy Setup
  284. .sp
  285. New in version 1.8.0: A new “X\-Client\-Port” HTTP header was added.
  286. .sp
  287. The discovery server can be run behind an SSL\-secured reverse proxy. This
  288. allows:
  289. .INDENT 0.0
  290. .IP \(bu 2
  291. Use of a subdomain name without requiring a port number added to the URL
  292. .IP \(bu 2
  293. Sharing an SSL certificate with multiple services on the same server
  294. .UNINDENT
  295. .sp
  296. Note that after this configuration, if the proxy uses a valid HTTPS
  297. certificate, \fBclients should omit the\fP \fB?id=...\fP \fBparameter from the
  298. discovery server URL on their configuration\fP\&. Client\-side validation will be
  299. done by checking the visible proxy server’s HTTPS certificate. If, however, the
  300. proxy uses a self\-signed or somehow invalid certificate, clients must still set
  301. the \fB?id=...\fP parameter with the computed hash of the proxy’s
  302. certificate. Using such setup is discouraged and is not covered in this page.
  303. Always favour using valid and widely recognised certificates.
  304. .SS Requirements
  305. .INDENT 0.0
  306. .IP \(bu 2
  307. Run the discovery server using the \-http flag: \fBstdiscosrv \-http\fP\&.
  308. .IP \(bu 2
  309. SSL certificate/key configured for the reverse proxy.
  310. .IP \(bu 2
  311. The “X\-Forwarded\-For” HTTP header must be passed through with the client’s
  312. real IP address.
  313. .IP \(bu 2
  314. The “X\-Client\-Port” HTTP header should be passed through, containing the client’s real connection port.
  315. .IP \(bu 2
  316. The “X\-SSL\-Cert” HTTP header must be passed through with the PEM\-encoded
  317. client SSL certificate. This will be present in POST requests and may be empty
  318. in GET requests from clients. If you see syncthing\-discosrv outputting
  319. \fBno certificates\fP when receiving POST requests, that’s because the proxy
  320. is not passing this header through.
  321. .IP \(bu 2
  322. The proxy must request the client SSL certificate but not require it to be
  323. signed by a trusted CA.
  324. .UNINDENT
  325. .SS Nginx
  326. .sp
  327. These lines in the configuration take care of the last four requirements
  328. listed above:
  329. .INDENT 0.0
  330. .INDENT 3.5
  331. .sp
  332. .nf
  333. .ft C
  334. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  335. proxy_set_header X\-Client\-Port $remote_port;
  336. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  337. ssl_verify_client optional_no_ca;
  338. .ft P
  339. .fi
  340. .UNINDENT
  341. .UNINDENT
  342. .sp
  343. The following is a complete example Nginx configuration file. With this setup,
  344. clients can use \fI\%https://discovery.example.com\fP as the discovery server URL in
  345. the Syncthing settings.
  346. .INDENT 0.0
  347. .INDENT 3.5
  348. .sp
  349. .nf
  350. .ft C
  351. # HTTP 1.1 support
  352. proxy_http_version 1.1;
  353. proxy_buffering off;
  354. proxy_set_header Host $http_host;
  355. proxy_set_header Upgrade $http_upgrade;
  356. proxy_set_header Connection $http_connection;
  357. proxy_set_header X\-Real\-IP $remote_addr;
  358. proxy_set_header X\-Client\-Port $remote_port;
  359. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  360. proxy_set_header X\-Forwarded\-Proto $http_x_forwarded_proto;
  361. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  362. upstream discovery.example.com {
  363. # Local IP address:port for discovery server
  364. server 192.0.2.1:8443;
  365. }
  366. server {
  367. server_name discovery.example.com;
  368. listen 80;
  369. access_log /var/log/nginx/access.log vhost;
  370. return 301 https://$host$request_uri;
  371. }
  372. server {
  373. server_name discovery.example.com;
  374. listen 443 ssl http2;
  375. access_log /var/log/nginx/access.log vhost;
  376. # Mozilla Intermediate configuration (https://wiki.mozilla.org/Security/Server_Side_TLS)
  377. ssl_protocols TLSv1.2 TLSv1.3;
  378. ssl_ciphers ECDHE\-ECDSA\-AES128\-GCM\-SHA256:ECDHE\-RSA\-AES128\-GCM\-SHA256:ECDHE\-ECDSA\-AES256\-GCM\-SHA384:ECDHE\-RSA\-AES256\-GCM\-SHA384:ECDHE\-ECDSA\-CHACHA20\-POLY1305:ECDHE\-RSA\-CHACHA20\-POLY1305:DHE\-RSA\-AES128\-GCM\-SHA256:DHE\-RSA\-AES256\-GCM\-SHA384;
  379. ssl_prefer_server_ciphers off;
  380. ssl_session_tickets off;
  381. ssl_session_timeout 5m;
  382. ssl_session_cache shared:SSL:50m;
  383. ssl_verify_client optional_no_ca;
  384. # OCSP stapling
  385. ssl_stapling on;
  386. ssl_stapling_verify on;
  387. # Certificates
  388. ssl_certificate /etc/nginx/certs/discovery.example.com.crt;
  389. ssl_certificate_key /etc/nginx/certs/discovery.example.com.key;
  390. # curl https://ssl\-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
  391. ssl_dhparam /path/to/dhparam;
  392. # HSTS (ngx_http_headers_module is required) (63072000 seconds)
  393. add_header Strict\-Transport\-Security \(dqmax\-age=63072000\(dq always;
  394. location / {
  395. proxy_pass http://discovery.example.com;
  396. }
  397. }
  398. .ft P
  399. .fi
  400. .UNINDENT
  401. .UNINDENT
  402. .sp
  403. An example of automating the SSL certificates and reverse\-proxying the Discovery
  404. Server and Syncthing using Nginx, \fI\%Let’s Encrypt\fP <\fBhttps://letsencrypt.org/\fP> and Docker can be found \fI\%here\fP <\fBhttps://forum.syncthing.net/t/docker-syncthing-and-syncthing-discovery-behind-nginx-reverse-proxy-with-lets-encrypt/6880\fP>\&.
  405. .SS Apache
  406. .sp
  407. The following lines must be added to the configuration:
  408. .INDENT 0.0
  409. .INDENT 3.5
  410. .sp
  411. .nf
  412. .ft C
  413. SSLProxyEngine On
  414. SSLVerifyClient optional_no_ca
  415. RequestHeader set X\-SSL\-Cert \(dq%{SSL_CLIENT_CERT}s\(dq
  416. .ft P
  417. .fi
  418. .UNINDENT
  419. .UNINDENT
  420. .sp
  421. The following was observed to not be required at least under
  422. Apache httpd 2.4.38, as the proxy module adds the needed header by default.
  423. If you need to explicitly add the following directive, make sure to issue
  424. \fBa2enmod remoteip\fP first. Then, add the following to your Apache httpd
  425. configuration:
  426. .INDENT 0.0
  427. .INDENT 3.5
  428. .sp
  429. .nf
  430. .ft C
  431. RemoteIPHeader X\-Forwarded\-For
  432. .ft P
  433. .fi
  434. .UNINDENT
  435. .UNINDENT
  436. .SS Caddy
  437. .sp
  438. The following lines must be added to the Caddyfile:
  439. .INDENT 0.0
  440. .INDENT 3.5
  441. .sp
  442. .nf
  443. .ft C
  444. discovery.example.com {
  445. reverse_proxy 192.0.2.1:8443 {
  446. header_up X\-Forwarded\-For {http.request.remote.host}
  447. header_up X\-Client\-Port {http.request.remote.port}
  448. header_up X\-Tls\-Client\-Cert\-Der\-Base64 {http.request.tls.client.certificate_der_base64}
  449. }
  450. tls {
  451. client_auth {
  452. mode request
  453. }
  454. }
  455. }
  456. .ft P
  457. .fi
  458. .UNINDENT
  459. .UNINDENT
  460. .INDENT 0.0
  461. .INDENT 3.5
  462. .sp
  463. .nf
  464. .ft C
  465. .ft P
  466. .fi
  467. .UNINDENT
  468. .UNINDENT
  469. .sp
  470. For more details, see also the recommendations in the
  471. \fI\%Reverse Proxy Setup\fP <\fBhttps://docs.syncthing.net/users/reverseproxy.html\fP>
  472. page. Note that that page is directed at setting up a proxy for the
  473. Syncthing web UI. You should do the proper path and port adjustments to proxying
  474. the discovery server and your particular setup.
  475. .SH SEE ALSO
  476. .sp
  477. \fBsyncthing\-networking(7)\fP, \fBsyncthing\-faq(7)\fP
  478. .SH AUTHOR
  479. The Syncthing Authors
  480. .SH COPYRIGHT
  481. 2014-2019, The Syncthing Authors
  482. .\" Generated by docutils manpage writer.
  483. .