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.

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