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.

576 lines
17 KiB

6 years ago
  1. .\" Copyright (c) 2019 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 May 8, 2019
  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 Cm pk_file_mode Ar integer
  52. Specify the permissions to use for newly-created private-key files. See
  53. .Xr chmod 2
  54. for more details.
  55. .It Cm pk_file_user Ar user_id Ft string
  56. Specify the user who will own newly-created private-key files. See
  57. .Xr chown 2
  58. for more details.
  59. .It Cm pk_file_group Ar group_id Ft string
  60. Specify the group who will own newly-created private-key files. See
  61. .Xr chown 2
  62. for more details.
  63. .El
  64. .It Ic endpoint
  65. Array of table where each element defines a Certificate Authority
  66. .Pq CA
  67. which may be used to request certificates.
  68. .Bl -tag
  69. .It Cm name Ar string
  70. The name the endpoint is registered under. Must be unique.
  71. .It Cm url Ar string
  72. The endpoint's directory URL.
  73. .It Cm tos_agreed Ar boolean
  74. Set whether or not the user agrees to the Terms Of Service
  75. .Pq TOS .
  76. .El
  77. .It Ic hook
  78. Array of table where each element defines a command that will be launched at a defined point. See section
  79. .Sx WRITING A HOOK
  80. for more details.
  81. .Bl -tag
  82. .It Cm name Ar string
  83. The name the hook is registered under. Must be unique.
  84. .It Cm hook_type Ar array
  85. Array of strings. Possible types are:
  86. .Bl -dash -compact
  87. .It
  88. challenge-http-01
  89. .It
  90. challenge-http-01-clean
  91. .It
  92. challenge-dns-01
  93. .It
  94. challenge-dns-01-clean
  95. .It
  96. challenge-tls-alpn-01
  97. .It
  98. challenge-tls-alpn-01-clean
  99. .It
  100. file-pre-create
  101. .It
  102. file-pre-edit
  103. .It
  104. file-post-create
  105. .It
  106. file-post-edit
  107. .It
  108. post-operation
  109. .El
  110. .It Ic cmd Ar string
  111. The name of the command that will be launched.
  112. .It Ic args Ar array
  113. Array of strings representing the command's arguments.
  114. .It Ic stdin Ar string
  115. String that will be written into the command's standard input.
  116. .It Ic stdout Ar string
  117. Path to the file where the command's standard output if written.
  118. .It Ic stderr Ar string
  119. Path to the file where the command's standard error output if written.
  120. .El
  121. .It Ic group
  122. Array of table allowing to group several hooks as one. A group is considered as new hook.
  123. .Bl -tag
  124. .It Cm name Ar string
  125. The name the group is registered under. This name is considered as a hook name. Must be unique.
  126. .It Cm hooks Ar array
  127. Array containing the names of the hooks that are grouped. The hooks are guaranteed to be called sequentially in the declaration order.
  128. .El
  129. .It Ic account
  130. Array of table representing an account on one or several CA.
  131. .Bl -tag
  132. .It Ic name Ar string
  133. The name the account is registered under. Must be unique.
  134. .It Ic email Ar string
  135. The email address used to contact the account's holder.
  136. .El
  137. .It Ic certificate
  138. Array of table representing a certificate that will be requested to a CA.
  139. .Bl -tag
  140. .It Ic account Ar string
  141. Name of the account to use.
  142. .It Ic endpoint Ar string
  143. Name of the endpoint to use.
  144. .It Ic env Ar table
  145. Table of environment variables that will be accessible from hooks.
  146. .It Ic domains Ar array
  147. Array of tables listing the domains that should be included in the certificate along with the challenge to use for each one.
  148. .Bl -tag
  149. .It Ic challenge Ar string
  150. The name of the challenge to use to prove the domain's ownership. Possible values are:
  151. .Bl -dash -compact
  152. .It
  153. http-01
  154. .It
  155. dns-01
  156. .It
  157. tls-alpn-01
  158. .El
  159. .It Ic dns Ar string
  160. The domain name.
  161. .It Ic env Ar table
  162. Table of environment variables that will be accessible from hooks.
  163. .El
  164. .It Ic algorithm Ar string
  165. Name of the asymetric cryptography algorithm used to generate the certificate's key pair. Possible values are :
  166. .Bl -dash -compact
  167. .It
  168. rsa2048
  169. .Aq default
  170. .It
  171. rsa4096
  172. .It
  173. ecdsa_p256
  174. .It
  175. ecdsa_p384
  176. .El
  177. .It Ic kp_reuse Ar boolean
  178. Set whether or not the private key should be reused when renewing the certificate. Default is false.
  179. .It Ic directory Ar string
  180. Path to the directory where certificates and their associated private keys are stored.
  181. .It Ic hooks Ar array
  182. Names of hooks that will be called when requesting a new certificate. The hooks are guaranteed to be called sequentially in the declaration order.
  183. .El
  184. .Sh WRITING A HOOK
  185. 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.
  186. .Pp
  187. In order to allow a full automation of the three above steps without imposing arbitrary restrictions or methods,
  188. .Xr acmed 8
  189. 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.
  190. .Pp
  191. 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.
  192. .Pp
  193. 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.
  194. .Pp
  195. When writing a hook, the values of
  196. .Em args ,
  197. .Em stdin ,
  198. .Em stdout
  199. and
  200. .Em stderr
  201. are considered as template strings whereas
  202. .Em cmd
  203. is not. The template syntax is
  204. .Em Handlebars .
  205. See the
  206. .Sx STANDARDS
  207. section for a link to the
  208. .Em Handlebars
  209. specifications.
  210. .Pp
  211. The available types and the associated template variable are described below.
  212. .Bl -tag
  213. .It Ic challenge-http-01
  214. Invoked when the ownership of a domain must be proved using the
  215. .Em http-01
  216. challenge. The available template variables are:
  217. .Bl -tag -compact
  218. .It Cm challenge Ar string
  219. The name of the challenge type
  220. .Aq http-01 .
  221. Mostly used in hooks with multiple types.
  222. .It Cm domain Ar string
  223. The domain name whom ownership is currently being validated.
  224. .It Cm env Ar array
  225. Array containing all the environment variables.
  226. .It Cm file_name Ar string
  227. Name of the file containing the proof. This is not a full path and does not include the
  228. .Ql .well-known/acme-challenge/
  229. prefix.
  230. .It Cm is_clean_hook Ar bool
  231. False
  232. .It Cm proof Ar string
  233. The content of the proof that must be written to
  234. .Em file_name .
  235. .El
  236. .It Ic challenge-http-01-clean
  237. Invoked once a domain ownership has been proven using the
  238. .Em http-01
  239. 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
  240. .Em challenge-http-01
  241. hook, excepted
  242. .Em is_clean_hook
  243. which is set to
  244. .Em true .
  245. .It Ic challenge-dns-01
  246. Invoked when the ownership of a domain must be proved using the
  247. .Em dns-01
  248. challenge. The available template variables are:
  249. .Bl -tag -compact
  250. .It Cm challenge Ar string
  251. The name of the challenge type
  252. .Aq dns-01 .
  253. Mostly used in hooks with multiple types.
  254. .It Cm domain Ar string
  255. The domain name whom ownership is currently being validated.
  256. .It Cm env Ar array
  257. Array containing all the environment variables.
  258. .It Cm is_clean_hook Ar bool
  259. False
  260. .It Cm proof Ar string
  261. The content of the proof that must be written to a
  262. .Ql TXT
  263. entry of the DNS zone for the
  264. .Ql _acme-challenge
  265. subdomain.
  266. .El
  267. .It Ic challenge-dns-01-clean
  268. Invoked once a domain ownership has been proven using the
  269. .Em dns-01
  270. 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
  271. .Em challenge-dns-01
  272. hook, excepted
  273. .Em is_clean_hook
  274. which is set to
  275. .Em true .
  276. .It Ic challenge-tls-alpn-01
  277. Invoked when the ownership of a domain must be proved using the
  278. .Em tls-alpn-01
  279. challenge. The available template variables are:
  280. .Bl -tag -compact
  281. .It Cm challenge Ar string
  282. The name of the challenge type
  283. .Aq tls-alpn-01 .
  284. Mostly used in hooks with multiple types.
  285. .It Cm domain Ar string
  286. The domain name whom ownership is currently being validated.
  287. .It Cm env Ar array
  288. Array containing all the environment variables.
  289. .It Cm is_clean_hook Ar bool
  290. False
  291. .It Cm proof Ar string
  292. Plain-text representation of the
  293. .Em acmeIdentifier
  294. extension that should be used in the self-signed certificate presented when a TLS connection is initiated with the
  295. .Qd acme-tls/1
  296. ALPN extension value.
  297. .Xr acmed 8
  298. will not generate the certificate itself since it can be done using
  299. .Xr tacd 8 .
  300. .El
  301. .It Ic challenge-tls-alpn-01-clean
  302. Invoked once a domain ownership has been proven using the
  303. .Em tls-alpn-01
  304. 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
  305. .Em challenge-tls-alpn-01
  306. hook, excepted
  307. .Em is_clean_hook
  308. which is set to
  309. .Em true .
  310. .It Ic file-pre-create
  311. Invoked
  312. .Em before
  313. a non-existent file
  314. .Em created .
  315. The available template variables are:
  316. .Bl -tag -compact
  317. .It Cm env Ar array
  318. Array containing all the environment variables.
  319. .It Cm file_directory Ar string
  320. Name of the directory where the impacted file is located.
  321. .It Cm file_name Ar string
  322. Name of the impacted file.
  323. .It Cm file_path Ar string
  324. Full path to the impacted file.
  325. .El
  326. .It Ic file-pre-edit
  327. Invoked
  328. .Em before
  329. an existent file
  330. .Em modified .
  331. The available template variables are the same as those available for the
  332. .Em file-pre-create
  333. type.
  334. .It Ic file-post-create
  335. Invoked
  336. .Em after
  337. a non-existent file
  338. .Em created .
  339. The available template variables are the same as those available for the
  340. .Em file-pre-create
  341. type.
  342. .It Ic file-post-edit
  343. Invoked
  344. .Em after
  345. an existent file
  346. .Em modified .
  347. The available template variables are the same as those available for the
  348. .Em file-pre-create
  349. type.
  350. .It Ic post-operation
  351. Invoked at the end of the certificate request process. The available template variables are:
  352. .Bl -tag -compact
  353. .It Cm algorithm Ar string
  354. Name of the algorithm used in the certificate.
  355. .It Cm domains Ar string
  356. Array containing the domain names included in the requested certificate.
  357. .It Cm env Ar array
  358. Array containing all the environment variables.
  359. .It Cm is_success Ar boolean
  360. True if the certificate request is successful.
  361. .It Cm status Ar string
  362. Human-readable status. If the certificate request failed, it contains the error description.
  363. .El
  364. .El
  365. .Sh DEFAULT HOOKS
  366. 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.
  367. .Bl -tag
  368. .It Pa git
  369. This hook uses
  370. .Xr git 1
  371. to archive private keys, public keys and certificates. It is possible to customize the commit username and email by using respectively the
  372. .Ev GIT_USERNAME
  373. and
  374. .Ev GIT_EMAIL
  375. environment variables.
  376. .It Pa http-01-echo
  377. This hook is designed to solve the http-01 challenge. For this purpose, it will write the proof into
  378. .Pa {{env.HTTP_ROOT}}/{{domain}}/.well-known/acme-challenge/{{file_name}} .
  379. .Pp
  380. The web server must be configured so the file
  381. .Pa http://{{domain}}/.well-known/acme-challenge/{{file_name}}
  382. can be accessed from the CA.
  383. .Pp
  384. If
  385. .Ev HTTP_ROOT
  386. is not specified, it will be set to
  387. .Pa /var/www .
  388. .It Pa tls-alpn-01-tacd-tcp
  389. This hook is designed to solve the tls-alpn-01 challenge using
  390. .Xr tacd 8 .
  391. It requires
  392. .Xr pkill 1
  393. to support the
  394. .Em Ar -F
  395. option.
  396. .Pp
  397. .Xr tacd 8
  398. will listen on the host defined by the
  399. .Ev TACD_HOST
  400. environment variable (default is the domain to be validated) and on the port defined by the
  401. .Ev TACD_PORT
  402. environment variable (default is 5001).
  403. .Pp
  404. .Xr tacd 8
  405. will store its pid into
  406. .Pa {{TACD_PID_ROOT}}/tacd_{{domain}}.pid .
  407. If
  408. .Ev TACD_PID_ROOT
  409. is not specified, it will be set to
  410. .Pa /run .
  411. .It Pa tls-alpn-01-tacd-unix
  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 unix socket
  422. .Pa {{env.TACD_SOCK_ROOT}}/tacd_{{domain}}.sock .
  423. If
  424. .Ev TACD_SOCK_ROOT
  425. is not specified, it will be set to
  426. .Pa /run .
  427. .Pp
  428. .Xr tacd 8
  429. will store its pid into
  430. .Pa {{TACD_PID_ROOT}}/tacd_{{domain}}.pid .
  431. If
  432. .Ev TACD_PID_ROOT
  433. is not specified, it will be set to
  434. .Pa /run .
  435. .El
  436. .Sh FILES
  437. .Bl -tag
  438. .It Pa /etc/acmed/acmed.toml
  439. Default
  440. .Xr acmed 8
  441. configuration file.
  442. .It Pa /etc/acmed/accounts
  443. Default accounts private and public keys directory.
  444. .It Pa /etc/acmed/certs
  445. Default certificates and associated private keys directory.
  446. .Sh EXAMPLES
  447. The following example defines a typical endpoint, account and certificate for a domain and several subdomains.
  448. .Bd -literal -offset indent
  449. [[endpoint]]
  450. name = "example name"
  451. url = "https://acme.example.org/directory"
  452. tos_agreed = true
  453. [[account]]
  454. name = "my test account"
  455. email = "certs@exemple.net"
  456. [[certificate]]
  457. endpoint = "example name"
  458. account = "my test account"
  459. domains = [
  460. { dns = "exemple.net", challenge = "http-01"},
  461. { dns = "1.exemple.net", challenge = "dns-01"},
  462. { dns = "2.exemple.net", challenge = "tls-alpn-01", env.TACD_PORT="5010"},
  463. { dns = "3.exemple.net", challenge = "tls-alpn-01", env.TACD_PORT="5011"},
  464. ]
  465. hooks = ["git", "http-01-echo", "tls-alpn-01-tacd-tcp", "some-dns-01-hook"]
  466. env.HTTP_ROOT = "/srv/http"
  467. .Ed
  468. .Pp
  469. It is possible to use
  470. .Xr echo 1
  471. to solve the
  472. .Em http-01
  473. challenge and
  474. .Xr rm 1
  475. to clean it.
  476. .Xr mkdir 1
  477. and
  478. .Xr chmod 1
  479. are used to prevent issues related to file access.
  480. .Bd -literal -offset indent
  481. [[hook]]
  482. name = "http-01-echo-mkdir"
  483. type = ["challenge-http-01"]
  484. cmd = "mkdir"
  485. args = [
  486. "-m", "0755",
  487. "-p", "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge"
  488. ]
  489. [[hook]]
  490. name = "http-01-echo-echo"
  491. type = ["challenge-http-01"]
  492. cmd = "echo"
  493. args = ["{{proof}}"]
  494. stdout = "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  495. [[hook]]
  496. name = "http-01-echo-chmod"
  497. type = ["challenge-http-01-clean"]
  498. cmd = "chmod"
  499. args = [
  500. "a+r",
  501. "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  502. ]
  503. [[hook]]
  504. name = "http-01-echo-clean"
  505. type = ["challenge-http-01-clean"]
  506. cmd = "rm"
  507. args = [
  508. "-f",
  509. "{{%if env.HTTP_ROOT}}{{env.HTTP_ROOT}}{{else}}/var/www{{/if}}/{{domain}}/.well-known/acme-challenge/{{file_name}}"
  510. ]
  511. .Ed
  512. .Pp
  513. The hooks from the previous example can be grouped in order to reduce the number of hooks to define in the certificate.
  514. .Bd -literal -offset indent
  515. [[group]]
  516. name = "http-01-echo-var-www"
  517. hooks = [
  518. "http-01-echo-mkdir",
  519. "http-01-echo-echo",
  520. "http-01-echo-chmod",
  521. "http-01-echo-clean"
  522. ]
  523. [[certificate]]
  524. # Some fields omitted
  525. hooks = ["http-01-echo"]
  526. env.HTTP_ROOT = "/srv/http"
  527. .Ed
  528. .Pp
  529. It is also possible to use
  530. .Xr sendmail 8
  531. in a hook in order to notif someone when the certificate request process is done.
  532. .Bd -literal -offset indent
  533. [[hook]]
  534. name = "email-report"
  535. type = ["post-operation"]
  536. cmd = "sendmail"
  537. args = [
  538. "-f", "noreply.certs@example.net",
  539. "contact@example.net"
  540. ]
  541. stdin = """Subject: Certificate renewal {{#if is_success}}succeeded{{else}}failed{{/if}} for {{domains.[0]}}
  542. The following certificate has {{#unless is_success}}*not* {{/unless}}been renewed.
  543. domains: {{#each domains}}{{#if @index}}, {{/if}}{{this}}{{/each}}
  544. algorithm: {{algorithm}}
  545. status: {{status}}"""
  546. .Ed
  547. .Sh SEE ALSO
  548. .Xr acmed 8 ,
  549. .Xr tacd 8
  550. .Sh STANDARDS
  551. .Bl
  552. .It
  553. .Rs
  554. .%A Tom Preston-Werner
  555. .%D July 2018
  556. .%T TOML v0.5.0
  557. .%U https://github.com/toml-lang/toml
  558. .Re
  559. .It
  560. .Rs
  561. .%A Yehuda Katz
  562. .%T Handlebars
  563. .%U https://handlebarsjs.com/
  564. .Re
  565. .El
  566. .Sh AUTHORS
  567. .An Rodolphe Bréard
  568. .Aq rodolphe@breard.tf