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.

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