stdiscosrv.1 15 KB

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