You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

632 lines
19 KiB

5 years ago
5 years ago
  1. .\" Copyright (c) 2019-2020 Rodolphe Bréard <rodolphe@breard.tf>
  2. .\"
  3. .\" Copying and distribution of this file, with or without modification,
  4. .\" are permitted in any medium without royalty provided the copyright
  5. .\" notice and this notice are preserved. This file is offered as-is,
  6. .\" without any warranty.
  7. .Dd March 12, 2020
  8. .Dt ACMED.TOML 5
  9. .Os
  10. .Sh NAME
  11. .Nm acmed.toml
  12. .Nd ACMEd configuration file
  13. .Sh DESCRIPTION
  14. .Nm
  15. is the configuration file for
  16. .Xr acmed 8 .
  17. It is written in the
  18. .Em TOML
  19. format. The allowed elements are described below.
  20. .Bl -tag
  21. .It Ic include
  22. Array containing the path to configuration file to include. The path can be either relative or absolute. If relative, it is relative to the configuration file which included it.
  23. .Pp
  24. In case or overlapping global option definition, the one of the last included file will be used. For example, if a file
  25. .Em A
  26. includes files
  27. .Em B
  28. and
  29. .Em C
  30. and all three defines the same global option, the final value will be the one defined in file
  31. .Em C .
  32. .It Ic global
  33. Table containing the global configuration options.
  34. .Bl -tag
  35. .It Cm accounts_directory Ar string
  36. Specify the directory where the accounts private and public keys are stored.
  37. .It Cm certificates_directory Ar string
  38. Specify the directory where the certificates and their associated private keys are stored.
  39. .It Cm cert_file_mode Ar integer
  40. Specify the permissions to use for newly-created certificates files. See
  41. .Xr chmod 2
  42. for more details.
  43. .It Cm cert_file_user Ar user_id Ft string
  44. Specify the user who will own newly-created certificates files. See
  45. .Xr chown 2
  46. for more details.
  47. .It Cm cert_file_group Ar group_id Ft string
  48. Specify the group who will own newly-created certificates files. See
  49. .Xr chown 2
  50. for more details.
  51. .It Ic env Ar table
  52. Table of environment variables that will be accessible from hooks.
  53. .It Cm pk_file_mode Ar integer
  54. Specify the permissions to use for newly-created private-key files. See
  55. .Xr chmod 2
  56. for more details.
  57. .It Cm pk_file_user Ar user_id Ft string
  58. Specify the user who will own newly-created private-key files. See
  59. .Xr chown 2
  60. for more details.
  61. .It Cm pk_file_group Ar group_id Ft string
  62. Specify the group who will own newly-created private-key files. See
  63. .Xr chown 2
  64. for more details.
  65. .El
  66. .It Ic rate-limit
  67. Array of table where each element defines a HTTPS rate limit.
  68. .Bl -tag
  69. .It Cm name Ar string
  70. The name the rate limit is registered under. Must be unique.
  71. .It Cm number Ar integer
  72. Number of requests authorized withing the time period.
  73. .It Cm period Ar string
  74. Period of time during which a maximal number of requests is authorized. The format is described in the
  75. .Sx TIME PERIODS
  76. section.
  77. .El
  78. .It Ic endpoint
  79. Array of table where each element defines a Certificate Authority
  80. .Pq CA
  81. which may be used to request certificates.
  82. .Bl -tag
  83. .It Cm name Ar string
  84. The name the endpoint is registered under. Must be unique.
  85. .It Cm rate_limits Ar array
  86. Array containing the names of the HTTPS rate limits to apply.
  87. .It Cm tos_agreed Ar boolean
  88. Set whether or not the user agrees to the Terms Of Service
  89. .Pq TOS .
  90. .It Cm url Ar string
  91. The endpoint's directory URL.
  92. .El
  93. .It Ic hook
  94. Array of table where each element defines a command that will be launched at a defined point. See section
  95. .Sx WRITING A HOOK
  96. for more details.
  97. .Bl -tag
  98. .It Cm allow_failure Ar boolean
  99. Defines if an error return value for this hook is allowed or not. If not allowed, a failure in this hook will fail the whole certificate request process. Default is false.
  100. .It Cm name Ar string
  101. The name the hook is registered under. Must be unique.
  102. .It Cm hook_type Ar array
  103. Array of strings. Possible types are:
  104. .Bl -dash -compact
  105. .It
  106. challenge-http-01
  107. .It
  108. challenge-http-01-clean
  109. .It
  110. challenge-dns-01
  111. .It
  112. challenge-dns-01-clean
  113. .It
  114. challenge-tls-alpn-01
  115. .It
  116. challenge-tls-alpn-01-clean
  117. .It
  118. file-pre-create
  119. .It
  120. file-pre-edit
  121. .It
  122. file-post-create
  123. .It
  124. file-post-edit
  125. .It
  126. post-operation
  127. .El
  128. .It Ic cmd Ar string
  129. The name of the command that will be launched.
  130. .It Ic args Ar array
  131. Array of strings representing the command's arguments.
  132. .It Ic stdin Ar string
  133. Path to the file that will be written into the command's standard intput. Mutually exclusive with
  134. .Em stdin_str .
  135. .It Ic stdin_str Ar string
  136. String that will be written into the command's standard input. Mutually exclusive with
  137. .Em stdin .
  138. .It Ic stdout Ar string
  139. Path to the file where the command's standard output if written.
  140. .It Ic stderr Ar string
  141. Path to the file where the command's standard error output if written.
  142. .El
  143. .It Ic group
  144. Array of table allowing to group several hooks as one. A group is considered as new hook.
  145. .Bl -tag
  146. .It Cm name Ar string
  147. The name the group is registered under. This name is considered as a hook name. Must be unique.
  148. .It Cm hooks Ar array
  149. Array containing the names of the hooks that are grouped. The hooks are guaranteed to be called sequentially in the declaration order.
  150. .El
  151. .It Ic account
  152. Array of table representing an account on one or several CA.
  153. .Bl -tag
  154. .It Ic name Ar string
  155. The name the account is registered under. Must be unique.
  156. .It Ic email Ar string
  157. The email address used to contact the account's holder.
  158. .El
  159. .It Ic certificate
  160. Array of table representing a certificate that will be requested to a CA.
  161. .Bl -tag
  162. .It Ic account Ar string
  163. Name of the account to use.
  164. .It Ic endpoint Ar string
  165. Name of the endpoint to use.
  166. .It Ic env Ar table
  167. Table of environment variables that will be accessible from hooks.
  168. .It Ic domains Ar array
  169. Array of tables listing the domains that should be included in the certificate along with the challenge to use for each one.
  170. .Bl -tag
  171. .It Ic challenge Ar string
  172. The name of the challenge to use to prove the domain's ownership. Possible values are:
  173. .Bl -dash -compact
  174. .It
  175. http-01
  176. .It
  177. dns-01
  178. .It
  179. tls-alpn-01
  180. .El
  181. .It Ic dns Ar string
  182. The domain name.
  183. .It Ic env Ar table
  184. Table of environment variables that will be accessible from hooks.
  185. .El
  186. .It Ic algorithm Ar string
  187. Name of the asymetric cryptography algorithm used to generate the certificate's key pair. Possible values are :
  188. .Bl -dash -compact
  189. .It
  190. rsa2048
  191. .Aq default
  192. .It
  193. rsa4096
  194. .It
  195. ecdsa_p256
  196. .It
  197. ecdsa_p384
  198. .El
  199. .It Ic kp_reuse Ar boolean
  200. Set whether or not the private key should be reused when renewing the certificate. Default is false.
  201. .It Ic directory Ar string
  202. Path to the directory where certificates and their associated private keys are stored.
  203. .It Ic hooks Ar array
  204. Names of hooks that will be called when requesting a new certificate. The hooks are guaranteed to be called sequentially in the declaration order.
  205. .El
  206. .Sh WRITING A HOOK
  207. When requesting a certificate to a CA using ACME, there is three steps that are hard to automatize. The first one is solving challenges in order to prove the ownership of every domains to be included: it requires to interact with the configuration of other services, hence depends on how the infrastructure works. The second one is restarting all the services that uses a given certificate, for the same reason. The last one is archiving: although several default methods can be implemented, sometimes admins wants or are required to do it in a different way.
  208. .Pp
  209. In order to allow a full automation of the three above steps without imposing arbitrary restrictions or methods,
  210. .Xr acmed 8
  211. uses hooks. Fundamentally, a hook is a command line template that will be called at a specific time of the process. Such approach allows admins to use any executable script or program located on the machine to customize the process.
  212. .Pp
  213. For a given certificate, hooks are guaranteed to be called sequentially in the declaration order. It is therefore possible to have a hook that depends on another one. Nevertheless, several certificates may be renewed at the same time. Hence, hooks shall not use globing or any other action that may disrupt hooks called by a different certificate.
  214. .Pp
  215. A hook have a type that will influence both the moment it is called and the available template variables. It is possible to declare several types. In such a case, the hook will be invoked whenever one of its type request it. When called, the hook only have access to template variable for the current type. If a hook uses a template variable that does not exists for the current type it is invoked for, the variable is empty.
  216. .Pp
  217. When writing a hook, the values of
  218. .Em args ,
  219. .Em stdin ,
  220. .Em stdin_str ,
  221. .Em stdout
  222. and
  223. .Em stderr
  224. are considered as template strings whereas
  225. .Em cmd
  226. is not. The template syntax is
  227. .Em Handlebars .
  228. See the
  229. .Sx STANDARDS
  230. section for a link to the
  231. .Em Handlebars
  232. specifications.
  233. .Pp
  234. The available types and the associated template variable are described below.
  235. .Bl -tag
  236. .It Ic challenge-http-01
  237. Invoked when the ownership of a domain must be proved using the
  238. .Em http-01
  239. challenge. The available template variables are:
  240. .Bl -tag -compact
  241. .It Cm challenge Ar string
  242. The name of the challenge type
  243. .Aq http-01 .
  244. Mostly used in hooks with multiple types.
  245. .It Cm domain Ar string
  246. The domain name whom ownership is currently being validated.
  247. .It Cm env Ar array
  248. Array containing all the environment variables.
  249. .It Cm file_name Ar string
  250. Name of the file containing the proof. This is not a full path and does not include the
  251. .Ql .well-known/acme-challenge/
  252. prefix.
  253. .It Cm is_clean_hook Ar bool
  254. False
  255. .It Cm proof Ar string
  256. The content of the proof that must be written to
  257. .Em file_name .
  258. .El
  259. .It Ic challenge-http-01-clean
  260. Invoked once a domain ownership has been proven using the
  261. .Em http-01
  262. challenge. This hook is intended to remove the proof since it is no longer required. The template variables are strictly identical to those given in the corresponding
  263. .Em challenge-http-01
  264. hook, excepted
  265. .Em is_clean_hook
  266. which is set to
  267. .Em true .
  268. .It Ic challenge-dns-01
  269. Invoked when the ownership of a domain must be proved using the
  270. .Em dns-01
  271. challenge. The available template variables are:
  272. .Bl -tag -compact
  273. .It Cm challenge Ar string
  274. The name of the challenge type
  275. .Aq dns-01 .
  276. Mostly used in hooks with multiple types.
  277. .It Cm domain Ar string
  278. The domain name whom ownership is currently being validated.
  279. .It Cm env Ar array
  280. Array containing all the environment variables.
  281. .It Cm is_clean_hook Ar bool
  282. False
  283. .It Cm proof Ar string
  284. The content of the proof that must be written to a
  285. .Ql TXT
  286. entry of the DNS zone for the
  287. .Ql _acme-challenge
  288. subdomain.
  289. .El
  290. .It Ic challenge-dns-01-clean
  291. Invoked once a domain ownership has been proven using the
  292. .Em dns-01
  293. challenge. This hook is intended to remove the proof since it is no longer required. The template variables are strictly identical to those given in the corresponding
  294. .Em challenge-dns-01
  295. hook, excepted
  296. .Em is_clean_hook
  297. which is set to
  298. .Em true .
  299. .It Ic challenge-tls-alpn-01
  300. Invoked when the ownership of a domain must be proved using the
  301. .Em tls-alpn-01
  302. challenge. The available template variables are:
  303. .Bl -tag -compact
  304. .It Cm challenge Ar string
  305. The name of the challenge type
  306. .Aq tls-alpn-01 .
  307. Mostly used in hooks with multiple types.
  308. .It Cm domain Ar string
  309. The domain name whom ownership is currently being validated.
  310. .It Cm env Ar array
  311. Array containing all the environment variables.
  312. .It Cm is_clean_hook Ar bool
  313. False
  314. .It Cm proof Ar string
  315. Plain-text representation of the
  316. .Em acmeIdentifier
  317. extension that should be used in the self-signed certificate presented when a TLS connection is initiated with the
  318. .Qd acme-tls/1
  319. ALPN extension value.
  320. .Xr acmed 8
  321. will not generate the certificate itself since it can be done using
  322. .Xr tacd 8 .
  323. .El
  324. .It Ic challenge-tls-alpn-01-clean
  325. Invoked once a domain ownership has been proven using the
  326. .Em tls-alpn-01
  327. challenge. This hook is intended to remove the proof since it is no longer required. The template variables are strictly identical to those given in the corresponding
  328. .Em challenge-tls-alpn-01
  329. hook, excepted
  330. .Em is_clean_hook
  331. which is set to
  332. .Em true .
  333. .It Ic file-pre-create
  334. Invoked
  335. .Em before
  336. a non-existent file
  337. .Em created .
  338. The available template variables are:
  339. .Bl -tag -compact
  340. .It Cm env Ar array
  341. Array containing all the environment variables.
  342. .It Cm file_directory Ar string
  343. Name of the directory where the impacted file is located.
  344. .It Cm file_name Ar string
  345. Name of the impacted file.
  346. .It Cm file_path Ar string
  347. Full path to the impacted file.
  348. .El
  349. .It Ic file-pre-edit
  350. Invoked
  351. .Em before
  352. an existent file
  353. .Em modified .
  354. The available template variables are the same as those available for the
  355. .Em file-pre-create
  356. type.
  357. .It Ic file-post-create
  358. Invoked
  359. .Em after
  360. a non-existent file
  361. .Em created .
  362. The available template variables are the same as those available for the
  363. .Em file-pre-create
  364. type.
  365. .It Ic file-post-edit
  366. Invoked
  367. .Em after
  368. an existent file
  369. .Em modified .
  370. The available template variables are the same as those available for the
  371. .Em file-pre-create
  372. type.
  373. .It Ic post-operation
  374. Invoked at the end of the certificate request process. The available template variables are:
  375. .Bl -tag -compact
  376. .It Cm algorithm Ar string
  377. Name of the algorithm used in the certificate.
  378. .It Cm domains Ar string
  379. Array containing the domain names included in the requested certificate.
  380. .It Cm env Ar array
  381. Array containing all the environment variables.
  382. .It Cm is_success Ar boolean
  383. True if the certificate request is successful.
  384. .It Cm status Ar string
  385. Human-readable status. If the certificate request failed, it contains the error description.
  386. .El
  387. .El
  388. .Sh DEFAULT HOOKS
  389. Because many people have the same needs, ACMEd comes with a set of hooks that should serve most situations. Hook names being unique, the following names and any other name starting by those is reserved and should not be used.
  390. .Bl -tag
  391. .It Pa git
  392. This hook uses
  393. .Xr git 1
  394. to archive private keys, public keys and certificates. It is possible to customize the commit username and email by using respectively the
  395. .Ev GIT_USERNAME
  396. and
  397. .Ev GIT_EMAIL
  398. environment variables.
  399. .It Pa http-01-echo
  400. This hook is designed to solve the http-01 challenge. For this purpose, it will write the proof into
  401. .Pa {{env.HTTP_ROOT}}/{{domain}}/.well-known/acme-challenge/{{file_name}} .
  402. .Pp
  403. The web server must be configured so the file
  404. .Pa http://{{domain}}/.well-known/acme-challenge/{{file_name}}
  405. can be accessed from the CA.
  406. .Pp
  407. If
  408. .Ev HTTP_ROOT
  409. is not specified, it will be set to
  410. .Pa /var/www .
  411. .It Pa tls-alpn-01-tacd-tcp
  412. This hook is designed to solve the tls-alpn-01 challenge using
  413. .Xr tacd 8 .
  414. It requires
  415. .Xr pkill 1
  416. to support the
  417. .Em Ar -F
  418. option.
  419. .Pp
  420. .Xr tacd 8
  421. will listen on the host defined by the
  422. .Ev TACD_HOST
  423. environment variable (default is the domain to be validated) and on the port defined by the
  424. .Ev TACD_PORT
  425. environment variable (default is 5001).
  426. .Pp
  427. .Xr tacd 8
  428. will store its pid into
  429. .Pa {{TACD_PID_ROOT}}/tacd_{{domain}}.pid .
  430. If
  431. .Ev TACD_PID_ROOT
  432. is not specified, it will be set to
  433. .Pa /run .
  434. .It Pa tls-alpn-01-tacd-unix
  435. This hook is designed to solve the tls-alpn-01 challenge using
  436. .Xr tacd 8 .
  437. It requires
  438. .Xr pkill 1
  439. to support the
  440. .Em Ar -F
  441. option.
  442. .Pp
  443. .Xr tacd 8
  444. will listen on the unix socket
  445. .Pa {{env.TACD_SOCK_ROOT}}/tacd_{{domain}}.sock .
  446. If
  447. .Ev TACD_SOCK_ROOT
  448. is not specified, it will be set to
  449. .Pa /run .
  450. .Pp
  451. .Xr tacd 8
  452. will store its pid into
  453. .Pa {{TACD_PID_ROOT}}/tacd_{{domain}}.pid .
  454. If
  455. .Ev TACD_PID_ROOT
  456. is not specified, it will be set to
  457. .Pa /run .
  458. .El
  459. .Sh TIME PERIODS
  460. ACMEd uses its own time period format, which is vaguely inspired by the ISO 8601 one. Periods are formatted as
  461. .Ar PM[PM...]
  462. where
  463. .Ar M
  464. is case sensitive character representing a length and
  465. .Ar P
  466. is an integer representing a multiplayer for the following length. The authorized length are:
  467. .Bl -dash -compact
  468. .It
  469. .Ar s :
  470. second
  471. .It
  472. .Ar m :
  473. minute
  474. .It
  475. .Ar h :
  476. hour
  477. .It
  478. .Ar d :
  479. day
  480. .It
  481. .Ar w :
  482. week
  483. .El
  484. The
  485. .Ar PM
  486. couples can be specified multiple times and in any order.
  487. .Pp
  488. For example,
  489. .Dq 1d42s and
  490. .Dq 40s20h4h2s
  491. both represents a period of one day and forty-two seconds.
  492. .Sh FILES
  493. .Bl -tag
  494. .It Pa /etc/acmed/acmed.toml
  495. Default
  496. .Xr acmed 8
  497. configuration file.
  498. .It Pa /etc/acmed/accounts
  499. Default accounts private and public keys directory.
  500. .It Pa /etc/acmed/certs
  501. Default certificates and associated private keys directory.
  502. .Sh EXAMPLES
  503. The following example defines a typical endpoint, account and certificate for a domain and several subdomains.
  504. .Bd -literal -offset indent
  505. [[endpoint]]
  506. name = "example name"
  507. url = "https://acme.example.org/directory"
  508. tos_agreed = true
  509. [[account]]
  510. name = "my test account"
  511. email = "certs@exemple.net"
  512. [[certificate]]
  513. endpoint = "example name"
  514. account = "my test account"
  515. domains = [
  516. { dns = "exemple.net", challenge = "http-01"},
  517. { dns = "1.exemple.net", challenge = "dns-01"},
  518. { dns = "2.exemple.net", challenge = "tls-alpn-01", env.TACD_PORT="5010"},
  519. { dns = "3.exemple.net", challenge = "tls-alpn-01", env.TACD_PORT="5011"},
  520. ]
  521. hooks = ["git", "http-01-echo", "tls-alpn-01-tacd-tcp", "some-dns-01-hook"]
  522. env.HTTP_ROOT = "/srv/http"
  523. .Ed
  524. .Pp
  525. It is possible to use
  526. .Xr echo 1
  527. to solve the
  528. .Em http-01
  529. challenge and
  530. .Xr rm 1
  531. to clean it.
  532. .Xr mkdir 1
  533. and
  534. .Xr chmod 1
  535. are used to prevent issues related to file access.
  536. .Bd -literal -offset indent
  537. [[hook]]
  538. name = "http-01-echo-mkdir"
  539. type = ["challenge-http-01"]
  540. cmd = "mkdir"
  541. args = [
  542. "-m", "0755",
  543. "-p", "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge"
  544. ]
  545. [[hook]]
  546. name = "http-01-echo-echo"
  547. type = ["challenge-http-01"]
  548. cmd = "echo"
  549. args = ["{{proof}}"]
  550. stdout = "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  551. [[hook]]
  552. name = "http-01-echo-chmod"
  553. type = ["challenge-http-01-clean"]
  554. cmd = "chmod"
  555. args = [
  556. "a+r",
  557. "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  558. ]
  559. [[hook]]
  560. name = "http-01-echo-clean"
  561. type = ["challenge-http-01-clean"]
  562. cmd = "rm"
  563. args = [
  564. "-f",
  565. "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  566. ]
  567. .Ed
  568. .Pp
  569. The hooks from the previous example can be grouped in order to reduce the number of hooks to define in the certificate.
  570. .Bd -literal -offset indent
  571. [[group]]
  572. name = "http-01-echo-var-www"
  573. hooks = [
  574. "http-01-echo-mkdir",
  575. "http-01-echo-echo",
  576. "http-01-echo-chmod",
  577. "http-01-echo-clean"
  578. ]
  579. [[certificate]]
  580. # Some fields omitted
  581. hooks = ["http-01-echo"]
  582. env.HTTP_ROOT = "/srv/http"
  583. .Ed
  584. .Pp
  585. It is also possible to use
  586. .Xr sendmail 8
  587. in a hook in order to notif someone when the certificate request process is done.
  588. .Bd -literal -offset indent
  589. [[hook]]
  590. name = "email-report"
  591. type = ["post-operation"]
  592. cmd = "sendmail"
  593. args = [
  594. "-f", "noreply.certs@example.net",
  595. "contact@example.net"
  596. ]
  597. stdin_str = """Subject: Certificate renewal {{#if is_success}}succeeded{{else}}failed{{/if}} for {{domains.[0]}}
  598. The following certificate has {{#unless is_success}}*not* {{/unless}}been renewed.
  599. domains: {{#each domains}}{{#if @index}}, {{/if}}{{this}}{{/each}}
  600. algorithm: {{algorithm}}
  601. status: {{status}}"""
  602. .Ed
  603. .Sh SEE ALSO
  604. .Xr acmed 8 ,
  605. .Xr tacd 8
  606. .Sh STANDARDS
  607. .Bl
  608. .It
  609. .Rs
  610. .%A Tom Preston-Werner
  611. .%D July 2018
  612. .%T TOML v0.5.0
  613. .%U https://github.com/toml-lang/toml
  614. .Re
  615. .It
  616. .Rs
  617. .%A Yehuda Katz
  618. .%T Handlebars
  619. .%U https://handlebarsjs.com/
  620. .Re
  621. .El
  622. .Sh AUTHORS
  623. .An Rodolphe Bréard
  624. .Aq rodolphe@breard.tf