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.

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