Git Product home page Git Product logo

puppet-letsencrypt_nginx's Introduction

Build Status

letsencrypt_nginx

Table of Contents

  1. Overview
  2. Module Description - What the module does and why it is useful
  3. Setup - The basics of getting started with letsencrypt_nginx
  4. Usage - Configuration options and additional functionality
  5. Reference - An under-the-hood peek at what the module is doing and how
  6. Limitations - OS compatibility, etc.
  7. Development - Guide for contributing to the module

Overview

The goal of Let's Encrypt is to automate ssl certificates.

This module is a helper to manage letsencrypt for puppet managed nginx servers.

Works with puppet/letsencrypt and puppet/nginx

Module Description

The goal of this module is to enable ssl on puppet managed nginx servers as simple as possible. The module reuses the domains configured in the server server_name

For the authorization, the webroot challenge is used and a custom location is automatically added to the ngninx server so that the challenge path is using the letsencrypt webroot. This allows to solve the challenge even if the server is just a proxy to another server.

Setup

What letsencrypt_nginx does

  • configure locations for the letsencrypt challenge path for defined servers and default server
  • Define default server for nginx that catches all requests that do not match a server_name
  • Uses letsencrypt::certonly to get certificate (requires puppet-letsencrypt)
  • Tell letsencrypt::certonly to manage cron for renewals

What letsencrypt_nginx does not

  • Manage nginx server ssl configuration. Configure the server ssl and certificate as seen in the examples below.

Setup Requirements

Requests to Port 80 (and 433) of the IPv4 address of the domains to encrypt need to reach your server.

This module uses the puppet/letsencrypt module, see it's documentation for the letsencrypt options

Usage

See the following example for encrypting a nginx server. This will successfully configure nginx, the server and the ssl certificat in one run, if added to a blank Server.

Important: You should declare letsencrypt_nginx resources after the nginx resources. The fetching of the configured domains is parse order dependent.

Let's encrypt nginx server

nginx::resource::server { 'letsencrypt-test1.example.com':
  server_name      => [
    'letsencrypt-test1.example.com',
    'letsencrypt-test2.example.com',
  ],
  proxy            => 'http://10.1.2.3',
  ssl              => true,
  ssl_redirect => true,
  ssl_key          => '/etc/letsencrypt/live/letsencrypt-test1.example.com/privkey.pem',
  ssl_cert         => '/etc/letsencrypt/live/letsencrypt-test1.example.com/fullchain.pem',
}
class { ::letsencrypt:
  email => '[email protected]',
}
class { 'letsencrypt_nginx':
  firstrun_webroot => '/var/www/html',
  servers           => {
    'letsencrypt-test1.example.com' => {},
  },
}

To add ssl configuration to an existing installation, you need first to configure the locations for your default server and your existing server.

class { 'letsencrypt_nginx':
  locations => {
    'default' => {}
    'letsencrypt-test1.example.com' => {}
  }
}

If this is applied successfully, you can then add the ssl configuration to your nginx server as above and declare your letsencrypt_nginx::server

Hiera example

classes:
  - nginx
  - letsencrypt
  - letsencrypt_nginx

nginx::servers:
  'letsencrypt-test1.example.com':
      server_name:
                            - 'letsencrypt-test1.example.com'
                            - 'letsencrypt-test2.example.com'
      proxy:                'http://10.1.2.3'
      ssl:                  true
      ssl_redirect:     true
      ssl_key:              '/etc/letsencrypt/live/letsencrypt-test1.example.com/privkey.pem'
      ssl_cert:             '/etc/letsencrypt/live/letsencrypt-test1.example.com/fullchain.pem'

letsencrypt::email: '[email protected]'
# use staging server for testing
letsencrypt::config:
  server: 'https://acme-staging.api.letsencrypt.org/directory'

letsencrypt_nginx::firstrun_webroot: '/var/www/html'
letsencrypt_nginx::servers:
  'letsencrypt-test1.example.com': {}

Reference

Class: letsencrypt_nginx

Let's Encrypt base configuration and hiera interface.

Parameters

  • default_server_name: name of nginx server that catches all requests that do not match any other server_name

  • webroot: This directory is configured as webroot for the webroot authentication locations added to the server to allow renewals

  • firstrun_webroot: Use different webroot on first run. Set this to the default webroot of the webserver if the service starts automatically when installed. E.g. For Nginx on Ubuntu: /var/www/html

  • firstrun_standalone: Use standalone mode on first run. Set this to true if the webserver does not start automatically when installed. letsencrypt will use standalone mode to get the certificate before the webserver is started the first time.

  • locations, servers: These Parameters can be used to create instances of these defined types through hiera

Define: letsencrypt_nginx::server

Automatically get ssl certificate for nginx server

Parameters

  • domains: Array of domains to get ssl certificate for. If not defined, it uses the server_name array defined in the server. Use these domains instead of reading server_name array of server.

  • exclude_domains: Array of servernames that should not be added as alt names for the ssl cert. E.g. Elements of server_name that are defined in the server, but are not public resolvable or not valid fqdns.

  • webroot_paths: Passed to letsencrypt::certonly, not recommended to change An array of webroot paths for the domains in domains. Required if using plugin => 'webroot'. If domains and webroot_paths are not the same length, webroot_paths will cycle to make up the difference.

  • additional_args: Passed to letsencrypt::certonly An array of additional command line arguments to pass to the letsencrypt-auto command.

  • manage_cron: Passed to letsencrypt::certonly, default: true Boolean indicating whether or not to schedule cron job for renewal. Runs daily but only renews if near expiration, e.g. within 10 days.

Define: letsencrypt_nginx::location

Configure acme-challenge location webroot for a nginx server

Parameters

  • server: server to configure location for, defaults to $name

Development

Run bundle exec rake to execute the spec tests. There are already some basic tests for each class and define, but not all options are covered.

Release Notes

See CHANGELOG.md

Contributors

License

Apache 2.0

TODO & Ideas

  • Automatically configure SSL certificate and key on the server
  • Add Domains to existing Certificates
  • Support for RedHat, CentOS etc.

puppet-letsencrypt_nginx's People

Contributors

apeeters avatar csdougliss avatar ericlaflamme avatar pgassmann avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppet-letsencrypt_nginx's Issues

Release new version

Please create a release for the latest change which fixes the missing path errors.

SSL only vhost places acme-challenge inside non-existing HTTP server block

Not sure if this is an issue with puppet-letsencrypt_nginx or the nginx module.

Trying to setup a SSL only vhost by setting ssl = true and listen_port = 443 generates an invalid vhost configuration file.

Sample puppet snippet:

class { 'nginx':
}

# Catch all vhost
nginx::resource::vhost { '_':
	www_root => '/usr/share/nginx/html'
}

nginx::resource::vhost { 'test.example.org':
	proxy => 'http://localhost:8081',
	ssl => true,
	#listen_port => 443,
	ssl_key => '/etc/letsencrypt/live/test.example.org/privkey.pem',
	ssl_cert => '/etc/letsencrypt/live/test.example.org/fullchain.pem'
}

class { ::letsencrypt:
	email => '[email protected]',
}

class { 'letsencrypt_nginx':
	firstrun_webroot => '/var/lib/letsencrypt/webroot',
	vhosts => {
		'test.example.org' => {}
	}
}

Adding listen_port => 443 and running puppet apply, results in the following change. Which nginx can't use.

--- /etc/nginx/sites-available/test.example.org.conf	2017-01-08 17:48:31.578264617 +0100
+++ /tmp/puppet-file20170108-9702-dvle14	2017-01-08 17:58:08.858259344 +0100
@@ -1,23 +1,3 @@
-# MANAGED BY PUPPET
-server {
-  listen *:80;
-  server_name           test.example.org;
-
-  index  index.html index.htm index.php;
-
-  access_log            /var/log/nginx/test.example.org.access.log combined;
-  error_log             /var/log/nginx/test.example.org.error.log;
-
-  location / {
-
-    proxy_pass            http://localhost:8081/;
-    proxy_read_timeout    90;
-    proxy_connect_timeout 90;
-    proxy_redirect        off;
-    proxy_set_header      Host $host;
-    proxy_set_header      X-Real-IP $remote_addr;
-    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
-  }

   location /.well-known/acme-challenge {
     auth_basic           "off";
@@ -25,7 +5,6 @@
     root      /var/lib/letsencrypt/webroot;
     index     index.html index.htm index.php;
   }
-}
 # MANAGED BY PUPPET
 server {
   listen       *:443 ssl;

Please tag releases

Hi,

Currently two releases are available on Puppet Forge. Please tag these on Github for reference.

Thanks!

Class[Nginx] is already declared

As letsencrypt_nginx is already declaring nginx, how do I define my own nginx parameters?

See below:

class { ::letsencrypt:
    email          => 'xyz'
  }

  class { 'letsencrypt_nginx':
    firstrun_webroot => '/usr/share/nginx/html',
    servers           => {
      'xyz' => {},
    },
  }

# Nginx
    class { 'nginx':
        worker_processes => 2,
        manage_repo     => true,
        package_source  => 'nginx-stable',
        server_tokens   => "off",
        http_access_log => "/var/log/nginx/access.log combined buffer=16k", /* buffer log writes to speed up IO */
        client_max_body_size => "32M"
    }
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Nginx] is already declared; cannot redeclare (file: /etc/puppetlabs/code/environments/production/manifests/xx.pp, line: 73) (file: /etc/puppetlabs/code/environments/production/manifests/xx, line: 73, column: 5) on node xx

migrate jfryman-nginx to puppet-nginx

puppet-nginx has taken over maintenance of jfryman-nginx going forward.

Currently installing your module results in this error:

Error: Could not install module 'pgassmann-letsencrypt_nginx' (v1.1.3)
Dependency 'jfryman-nginx' (v999.999.999) would overwrite /etc/puppet/modules/nginx
Currently, 'puppet-nginx' (v0.5.0) is installed to that directory
Use puppet module install --ignore-dependencies to install only this module

Certicate reported as expired after having been renewed

Not sure if this is something that can or should be resolved in this module.

I ran into this issue today:

  • certificate was renewed 30 days ago.
  • certificate was reported as expired today.

This was caused by nginx not having reloaded its configuration or having been restarted after the certificate had been renewed. Should this module do something about this?

'letsencrypt_nginx_firstrun' exec should specify a path

With the default Puppet config, the exec will fail to run because mkdir and echo are not qualified:

Failed to apply catalog: Validation of Exec[set letsencrypt_nginx_firstrun fact] failed: 'mkdir -p /etc/facter/facts.d/ && echo "letsencrypt_nginx_firstrun=SUCCESS" > /etc/facter/facts.d/letsencrypt_nginx.txt' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppetlabs/code/environments/production/modules/letsencrypt_nginx/manifests/init.pp:62

Adding a path => ['/bin'] to the exec I think should fix things on most systems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.