stdiscosrv.1 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .TH "STDISCOSRV" "1" "Nov 18, 2020" "v1" "Syncthing"
  4. .SH NAME
  5. stdiscosrv \- Syncthing Discovery Server
  6. .
  7. .nr rst2man-indent-level 0
  8. .
  9. .de1 rstReportMargin
  10. \\$1 \\n[an-margin]
  11. level \\n[rst2man-indent-level]
  12. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  13. -
  14. \\n[rst2man-indent0]
  15. \\n[rst2man-indent1]
  16. \\n[rst2man-indent2]
  17. ..
  18. .de1 INDENT
  19. .\" .rstReportMargin pre:
  20. . RS \\$1
  21. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  22. . nr rst2man-indent-level +1
  23. .\" .rstReportMargin post:
  24. ..
  25. .de UNINDENT
  26. . RE
  27. .\" indent \\n[an-margin]
  28. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  29. .nr rst2man-indent-level -1
  30. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  31. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  32. ..
  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 getting\-started 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. .SS Configuring
  127. .sp
  128. \fBNOTE:\fP
  129. .INDENT 0.0
  130. .INDENT 3.5
  131. If you are running an instance of Syncthing on the discovery server,
  132. you must either add that instance to other devices using a static
  133. address or bind the discovery server and Syncthing instances to
  134. different IP addresses.
  135. .UNINDENT
  136. .UNINDENT
  137. .SS Certificates
  138. .sp
  139. The discovery server provides service over HTTPS. To ensure secure connections
  140. from clients there are three options:
  141. .INDENT 0.0
  142. .IP \(bu 2
  143. Use a CA\-signed certificate pair for the domain name you will use for the
  144. discovery server. This is like any other HTTPS website; clients will
  145. authenticate the server based on its certificate and domain name.
  146. .IP \(bu 2
  147. Use any certificate pair and let clients authenticate the server based on
  148. its “device ID” (similar to Syncthing\-to\-Syncthing authentication). This
  149. option can be used with the certificate automatically generated by the
  150. discovery server.
  151. .IP \(bu 2
  152. Pass the \fB\-http\fP flag if the discovery server is behind an SSL\-secured
  153. reverse proxy. See below for configuration.
  154. .UNINDENT
  155. .sp
  156. For the first two options, the discovery server must be given the paths to
  157. the certificate and key at startup. This isn’t necessary with the \fBhttp\fP flag:
  158. .INDENT 0.0
  159. .INDENT 3.5
  160. .sp
  161. .nf
  162. .ft C
  163. $ stdiscosrv \-cert=/path/to/cert.pem \-key=/path/to/key.pem
  164. Server device ID is 7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  165. .ft P
  166. .fi
  167. .UNINDENT
  168. .UNINDENT
  169. .sp
  170. The discovery server prints its device ID at startup. In case you are using
  171. a non CA signed certificate, this device ID (fingerprint) must be given to
  172. the clients in the discovery server URL:
  173. .INDENT 0.0
  174. .INDENT 3.5
  175. .sp
  176. .nf
  177. .ft C
  178. https://disco.example.com:8443/?id=7DDRT7J\-UICR4PM\-PBIZYL3\-MZOJ7X7\-EX56JP6\-IK6HHMW\-S7EK32W\-G3EUPQA
  179. .ft P
  180. .fi
  181. .UNINDENT
  182. .UNINDENT
  183. .sp
  184. Otherwise, the URL will be:
  185. .INDENT 0.0
  186. .INDENT 3.5
  187. .sp
  188. .nf
  189. .ft C
  190. https://disco.example.com:8443/
  191. .ft P
  192. .fi
  193. .UNINDENT
  194. .UNINDENT
  195. .SS Replication
  196. .sp
  197. The discovery server can be deployed in a redundant, load sharing fashion.
  198. In this mode announcements are replicated from the server that receives them
  199. to other peer servers and queries can be answered equally by all servers.
  200. .sp
  201. Replication connections are encrypted and authenticated using TLS. The
  202. certificate is selected by the \fB\-cert\fP and \fB\-key\fP options and is thus
  203. shared with the main discovery API. If the \fB\-http\fP mode is used the
  204. certificate is not used for client requests but only for replication
  205. connections.
  206. .sp
  207. Authentication of replication connections is done using \fI\%Syncthing\-style
  208. device IDs\fP <\fBhttps://docs.syncthing.net/dev/device-ids.html#id1\fP> only \- CA
  209. verification is not available. The device IDs in question are those printed
  210. by the discovery server on startup.
  211. .sp
  212. Replication connections are unidirectional \- announcements are replication
  213. from the \fBsender\fP to a \fBlistener\fP\&. In order to have a bidirectional
  214. replication relationship between two servers both need to be configured as
  215. sender and listener.
  216. .sp
  217. As an example, lets assume two discovery servers:
  218. .INDENT 0.0
  219. .IP \(bu 2
  220. Server one is on 192.0.2.20 and has certificate ID I6K…H76
  221. .IP \(bu 2
  222. Server two is on 192.0.2.55 and has certificate ID MRI…7OK
  223. .UNINDENT
  224. .sp
  225. In order for both to replicate to the other and thus form a redundant pair,
  226. use the following commands.
  227. .sp
  228. On server one:
  229. .INDENT 0.0
  230. .INDENT 3.5
  231. .sp
  232. .nf
  233. .ft C
  234. $ stdiscosrv \[email protected]:19200 <other options>
  235. .ft P
  236. .fi
  237. .UNINDENT
  238. .UNINDENT
  239. .sp
  240. On server two:
  241. .INDENT 0.0
  242. .INDENT 3.5
  243. .sp
  244. .nf
  245. .ft C
  246. $ stdiscosrv \[email protected]:19200 <other options>
  247. .ft P
  248. .fi
  249. .UNINDENT
  250. .UNINDENT
  251. .sp
  252. The \fB\-replicate\fP directive sets which remote device IDs are expected and
  253. allowed for both outgoing (sending) and incoming (listening) connections,
  254. and which addresses to use when connecting out to those peers. Both IP and
  255. port must be specified in peer addresses.
  256. .sp
  257. It is possible to only allow incoming connections from a peer without
  258. establishing an outgoing replication connection. To do so, give only the
  259. device ID without “@ip:port” address:
  260. .INDENT 0.0
  261. .INDENT 3.5
  262. .sp
  263. .nf
  264. .ft C
  265. $ stdiscosrv \-replicate=I6K...H76 <other options>
  266. .ft P
  267. .fi
  268. .UNINDENT
  269. .UNINDENT
  270. .sp
  271. Discosrv will listen on the replication port only when \fB\-replicate\fP is
  272. given. The default replication listen address is “:19200”.
  273. .sp
  274. To achieve load balancing over two mutually replicating discovery server
  275. instances, add multiple A / AAAA DNS records for a given name and point
  276. Syncthing towards this name. The same certificate must be used on both
  277. discovery servers.
  278. .SS Reverse Proxy Setup
  279. .sp
  280. New in version 1.8.0: A new “X\-Client\-Port” HTTP header was added.
  281. .sp
  282. The discovery server can be run behind an SSL\-secured reverse proxy. This
  283. allows:
  284. .INDENT 0.0
  285. .IP \(bu 2
  286. Use of a subdomain name without requiring a port number added to the URL
  287. .IP \(bu 2
  288. Sharing an SSL certificate with multiple services on the same server
  289. .UNINDENT
  290. .sp
  291. Note that after this configuration, if the proxy uses a valid HTTPS
  292. certificate, \fBclients should omit the\fP \fB?id=...\fP \fBparameter from the
  293. discovery server URL on their configuration\fP\&. Client\-side validation will be
  294. done by checking the visible proxy server’s HTTPS certificate. If, however, the
  295. proxy uses a self\-signed or somehow invalid certificate, clients must still set
  296. the \fB?id=...\fP parameter with the computed hash of the proxy’s
  297. certificate. Using such setup is discouraged and is not covered in this page.
  298. Always favour using valid and widely recognised certificates.
  299. .SS Requirements
  300. .INDENT 0.0
  301. .IP \(bu 2
  302. Run the discovery server using the \-http flag: \fBstdiscosrv \-http\fP\&.
  303. .IP \(bu 2
  304. SSL certificate/key configured for the reverse proxy.
  305. .IP \(bu 2
  306. The “X\-Forwarded\-For” HTTP header must be passed through with the client’s
  307. real IP address.
  308. .IP \(bu 2
  309. The “X\-Client\-Port” HTTP header should be passed through, containing the client’s real connection port.
  310. .IP \(bu 2
  311. The “X\-SSL\-Cert” HTTP header must be passed through with the PEM\-encoded
  312. client SSL certificate. This will be present in POST requests and may be empty
  313. in GET requests from clients. If you see syncthing\-discosrv outputting
  314. \fBno certificates\fP when receiving POST requests, that’s because the proxy
  315. is not passing this header through.
  316. .IP \(bu 2
  317. The proxy must request the client SSL certificate but not require it to be
  318. signed by a trusted CA.
  319. .UNINDENT
  320. .SS Nginx
  321. .sp
  322. These lines in the configuration take care of the last four requirements
  323. listed above:
  324. .INDENT 0.0
  325. .INDENT 3.5
  326. .sp
  327. .nf
  328. .ft C
  329. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  330. proxy_set_header X\-Client\-Port $remote_port;
  331. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  332. ssl_verify_client optional_no_ca;
  333. .ft P
  334. .fi
  335. .UNINDENT
  336. .UNINDENT
  337. .sp
  338. The following is a complete example Nginx configuration file. With this setup,
  339. clients can use \fI\%https://discovery.example.com\fP as the discovery server URL in
  340. the Syncthing settings.
  341. .INDENT 0.0
  342. .INDENT 3.5
  343. .sp
  344. .nf
  345. .ft C
  346. # HTTP 1.1 support
  347. proxy_http_version 1.1;
  348. proxy_buffering off;
  349. proxy_set_header Host $http_host;
  350. proxy_set_header Upgrade $http_upgrade;
  351. proxy_set_header Connection $http_connection;
  352. proxy_set_header X\-Real\-IP $remote_addr;
  353. proxy_set_header X\-Client\-Port $remote_port;
  354. proxy_set_header X\-Forwarded\-For $proxy_add_x_forwarded_for;
  355. proxy_set_header X\-Forwarded\-Proto $http_x_forwarded_proto;
  356. proxy_set_header X\-SSL\-Cert $ssl_client_cert;
  357. upstream discovery.example.com {
  358. # Local IP address:port for discovery server
  359. server 192.0.2.1:8443;
  360. }
  361. server {
  362. server_name discovery.example.com;
  363. listen 80;
  364. access_log /var/log/nginx/access.log vhost;
  365. return 301 https://$host$request_uri;
  366. }
  367. server {
  368. server_name discovery.example.com;
  369. listen 443 ssl http2;
  370. access_log /var/log/nginx/access.log vhost;
  371. # Mozilla Intermediate configuration (https://wiki.mozilla.org/Security/Server_Side_TLS)
  372. ssl_protocols TLSv1.2 TLSv1.3;
  373. 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;
  374. ssl_prefer_server_ciphers off;
  375. ssl_session_tickets off;
  376. ssl_session_timeout 5m;
  377. ssl_session_cache shared:SSL:50m;
  378. ssl_verify_client optional_no_ca;
  379. # OCSP stapling
  380. ssl_stapling on;
  381. ssl_stapling_verify on;
  382. # Certificates
  383. ssl_certificate /etc/nginx/certs/discovery.example.com.crt;
  384. ssl_certificate_key /etc/nginx/certs/discovery.example.com.key;
  385. # curl https://ssl\-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
  386. ssl_dhparam /path/to/dhparam;
  387. # HSTS (ngx_http_headers_module is required) (63072000 seconds)
  388. add_header Strict\-Transport\-Security "max\-age=63072000" always;
  389. location / {
  390. proxy_pass http://discovery.example.com;
  391. }
  392. }
  393. .ft P
  394. .fi
  395. .UNINDENT
  396. .UNINDENT
  397. .sp
  398. An example of automating the SSL certificates and reverse\-proxying the Discovery
  399. 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>\&.
  400. .SS Apache
  401. .sp
  402. The following lines must be added to the configuration:
  403. .INDENT 0.0
  404. .INDENT 3.5
  405. .sp
  406. .nf
  407. .ft C
  408. SSLProxyEngine On
  409. SSLVerifyClient optional_no_ca
  410. RequestHeader set X\-SSL\-Cert "%{SSL_CLIENT_CERT}s"
  411. .ft P
  412. .fi
  413. .UNINDENT
  414. .UNINDENT
  415. .sp
  416. The following was observed to not be required at least under
  417. Apache httpd 2.4.38, as the proxy module adds the needed header by default.
  418. If you need to explicitly add the following directive, make sure to issue
  419. \fBa2enmod remoteip\fP first. Then, add the following to your Apache httpd
  420. configuration:
  421. .INDENT 0.0
  422. .INDENT 3.5
  423. .sp
  424. .nf
  425. .ft C
  426. RemoteIPHeader X\-Forwarded\-For
  427. .ft P
  428. .fi
  429. .UNINDENT
  430. .UNINDENT
  431. .sp
  432. For more details, see also the recommendations in the
  433. \fI\%Reverse Proxy Setup\fP <\fBhttps://docs.syncthing.net/users/reverseproxy.html\fP>
  434. page. Note that that page is directed at setting up a proxy for the
  435. Syncthing web UI. You should do the proper path and port adjustments to proxying
  436. the discovery server and your particular setup.
  437. .SH SEE ALSO
  438. .sp
  439. \fBsyncthing\-networking(7)\fP, \fBsyncthing\-faq(7)\fP
  440. .SH AUTHOR
  441. The Syncthing Authors
  442. .SH COPYRIGHT
  443. 2014-2019, The Syncthing Authors
  444. .\" Generated by docutils manpage writer.
  445. .