Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Chef cookbook to request SSL certificates at Let's Encrypt

License

NotificationsYou must be signed in to change notification settings

schubergphilis/chef-acme

Repository files navigation

Build StatusCookbook Version

Automatically get/renew free and trusted certificates from Let's Encrypt (letsencrypt.org).ACME is theAutomated Certificate Management Environment protocol used byLet's Encrypt.

Starting with v4.0.0 of the acme cookbook the acme_ssl_certificate provider has been removed! The TLS-SNI-01 validation method used by this provider been disabled by Let's Encrypt due to security concerns. Please switch to the acme_certificate provider in this cookbook to request and renew your certificate using the supported HTTP-01 validation method.

Attributes

AttributeDescriptionDefault
contactContact information, default empty. Set tomailto:your@email.com[]
dirACME server endpoint, Set tohttps://acme-staging-v02.api.letsencrypt.org/directory if you want to use the Let's Encrypt staging environment and corresponding certificates.https://acme-v02.api.letsencrypt.org/directory
renewDays before the certificate expires at which the certificate will be renewed30
source_ipsIP addresses used by Let's Encrypt to verify the TLS certificates, it will change over time. This attribute is for firewall purposes. Allow these IPs for HTTP (tcp/80).['66.133.109.36']
private_keyPrivate key content of registered account. Private keys identify the ACME client with the endpoint and are not transferable between staging and production endpoints.nil
private_key_fileFilename where private key will be saved. If this file exists, the contents take precedence over the value set inprivate_key./etc/acme/account_private_key.pem
key_sizeDefault private key size used when resource property is not. Must be one out of: 2048, 3072, 4096.2048

Recipes

default

Installs the required acme-client rubygem.

Usage

Use theacme_certificate resource to request a certificate with the http-01 challenge. The webserver for the domain for which you are requesting a certificate must be running on the local server. This resource only supports the http validation method. To use the tls-sni-01 challenge, please see the resource below. Provide the path to yourwwwroot for the specified domain.

acme_certificate'test.example.com'docrt'/etc/ssl/test.example.com.crt'key'/etc/ssl/test.example.com.key'wwwroot'/var/www'end

If your webserver needs an existing certificate already when installing a new server, you will have a bootstrap problem: The web server cannot start without a certificate, but the certificate cannot be requested without the running web server. To overcome this, a temporary self-signed certificate can be generated with theacme_selfsigned resource, allowing the web server to start.

acme_selfsigned'test.example.com'docrt'/etc/ssl/test.example.com.crt'chain'/etc/ssl/test.example.com-chain.crt'key'/etc/ssl/test.example.com.key'end

A working example can be found in the includedacme_client test cookbook.

Providers

certificate

PropertyTypeDefaultDescription
cnstringnameThe common name for the certificate
alt_namesarray[]The common name for the certificate
crtstringnilFile path to place the certificate
keystringnilFile path to place the private key
key_sizeinteger2048Private key size. Must be one out of: 2048, 3072, 4096
ownerstring,integerrootOwner of the created files
groupstring,integerrootGroup of the created files
wwwrootstring/var/wwwPath to the wwwroot of the domain
ignore_failurebooleanfalseWhether to continue chef run if issuance fails
retriesinteger0Number of times to catch exceptions and retry
retry_delayinteger2Number of seconds to wait between retries
endpointstringnilThe Let's Encrypt endpoint to use
contactarray[]The contact to use

selfsigned

PropertyTypeDefaultDescription
cnstringnameThe common name for the certificate
crtstringnilFile path to place the certificate
keystringnilFile path to place the private key
key_sizeinteger2048Private key size. Must be one out of: 2048, 3072, 4096
chainstringnilFile path to place the certificate chain
ownerstring,integerrootOwner of the created files
groupstring,integerrootGroup of the created files

Example

To generate a certificate for an apache2 website you can use code like this:

# Include the recipe to install the gemsinclude_recipe'acme'# Set up contact information. Note the mailto: notationnode.override['acme']['contact']=['mailto:me@example.com']# Real certificates please...node.override['acme']['endpoint']='https://acme-v01.api.letsencrypt.org'site="example.com"sans=["www.#{site}"]# Generate a self-signed if we don't have a cert to prevent bootstrap problemsacme_selfsigned"#{site}"docrt"/etc/httpd/ssl/#{site}.crt"key"/etc/httpd/ssl/#{site}.key"chain"/etc/httpd/ssl/#{site}.pem"owner"apache"group"apache"notifies:restart,"service[apache2]",:immediateend# Set up your web server here...# Get and auto-renew the certificate from Let's Encryptacme_certificate"#{site}"docrt"/etc/httpd/ssl/#{site}.crt"key"/etc/httpd/ssl/#{site}.key"wwwroot"/var/www/#{site}/htdocs/"notifies:restart,"service[apache2]"alt_namessansend

DNS verification

Letsencrypt supports DNS validation. Depending on the setup there may be different ways to deploy an acme challenge to your infrastructure. If you want to use DSN validation, you have to provide two block arguments to theacme_certificate resource.

Implement 2 methods in a library in your cookbook, each returning aProc object. The following example uses a HTTP API to provide challenges to the DNS infrastructure.

# my_cookbook/libraries/acme_dns.rbclassChefclassRecipedefinstall_dns_challenge(apitoken)Proc.newdo |authorization,new_resource|# use DNS authorizationauthz=authorization.dnsfqdn=authorization.identifier['value']r=Net::HTTP.post(URI("https://my_awesome_dns_api/#{fqdn}"),authz.record_content,{'Authorization'=>"Token#{apitoken}"})ifr.code !='200'fail"DNS API does not want to install Challenge for#{fqdn}"else# do some validation that the challenge has propagated to the infrastructureend# it is important that the authz and fqdn is passed back, so it can be passed to the remove_dns_challenge method[authz,fqdn]endenddefremove_dns_challenge(apitoken)Proc.newdo |authz,fqdn|uri=URI("https://my_awesome_dns_api/#{fqdn}")Net::HTTP.start(uri.hostname,uri.port,use_ssl:uri.scheme=='https')do |http|http.delete(uri,{'Authorization'=>"Token#{apitoken}"})endendendendend

Use it in your recipe the following way:

apitoken=chef_vault_item(vault,item)['dns_api_token']acme_certificatenode['fqdn']dokey'/path/to/key'crt'/path/to/crt'install_authz_blockinstall_dns_challenge(apitoken)remove_authz_blockremove_dns_challenge(apitoken)end

Testing

The kitchen includes apebble server to run the integration tests with, so testing can run locally without interaction with the online APIs.

Contributing

  1. Fork the repository on Github
  2. Create a named feature branch (likeadd_component_x)
  3. Write your change
  4. Write tests for your change (if applicable)
  5. Run the tests, ensuring they all pass
  6. Submit a Pull Request using Github

License and Authors

Authors: Thijs Houtenbosthoutenbos@schubergphilis.com

Credits

Let’s Encrypt is a trademark of the Internet Security Research Group. All rights reserved.


[8]ページ先頭

©2009-2025 Movatter.jp