Git Product home page Git Product logo

openvpn's Introduction

openvpn Cookbook

Cookbook Version Build Status OpenCollective OpenCollective License

Installs OpenVPN and sets up a fairly basic configuration. Since OpenVPN is very complex, we provide a baseline only (see Customizing Server Configuration below).

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

  • Debian 8+
  • Ubuntu 16.04+
  • RHEL 6.x and 7.x w/ (EPEL is enabled as required)
  • CentOS 6.x, 7.x, 8.x
  • Fedora
  • OpenSUSE 42+ (partial support/WIP)
  • Arch Linux
  • FreeBSD 11+ (partial support/WIP)

Note: we currently only test the latest minor release for the last 2 major releases of each OS/distribution using Test Kitchen.

Cookbooks

  • yum-epel

Not Supported

This cookbook is designed to set up a basic installation of OpenVPN that will work for many common use cases. The following configurations are not supported by default with this cookbook:

  • setting up routers and other network devices
  • ethernet-bridging (tap interfaces)
  • dual-factor authentication
  • many other advanced OpenVPN configurations

For further modification of the cookbook see Usage below.

For more information about OpenVPN, see the official site.

Attributes

These attributes are set by the cookbook by default.

  • node['openvpn']['client_cn'] - The client's Common Name used with the openvpn::client recipe (essentially a standalone recipe) for the client certificate and key.
  • node['openvpn']['type'] - Valid values are 'client' (currently a work in progress), 'server' or 'server-bridge'. Default is 'server' and it will create a routed IP tunnel, and use the 'tun' device. 'server-bridge' will create an ethernet bridge and requires a tap0 device bridged with the ethernet interface, and is beyond the scope of this cookbook.
  • node['openvpn']['subnet'] - Used for server mode to configure a VPN subnet to draw client addresses. Default is 10.8.0.0, which is what the sample OpenVPN config package uses.
  • node['openvpn']['netmask'] - Netmask for the subnet, default is 255.255.0.0.
  • node['openvpn']['gateway'] - FQDN for the VPN gateway server. Default is node['fqdn'].
  • node['openvpn']['push_routes'] - Array of routes to to push to clients (as push statements) in the server.conf, e.g. '192.168.0.0 255.255.255.0'. Default is empty.
  • node['openvpn']['push_options'] - Array of options to push to clients in the server.conf, e.g. [["dhcp-option DNS", ["8.8.8.8"]]]. Default is empty.
  • node['openvpn']['configure_default_server'] - Boolean. Set this to false if you want to create all of your "conf" files with the LWRP.
  • node['openvpn']['git_package'] - Boolean. Whether to use the openvpn-git package (Arch Linux only, default false).
  • node['openvpn']['client_prefix'] - String. Name of the config that is created for clients. When imported into most vpn clients, this is the name that will be displayed for the connection. Default is 'vpn-prod'.
  • node['openvpn']['cookbook_user_conf'] - String. The cookbook used by the openvpn::users recipe for the client.conf.erb template. You can override this to your own, such as your wrapper cookbook. Default is 'openvpn'.
  • node['openvpn']['key_dir'] - Location to store keys, certificates and related files. Default /etc/openvpn/keys.
  • node['openvpn']['signing_ca_cert'] - CA certificate for signing, default /etc/openvpn/keys/ca.crt
  • node['openvpn']['signing_ca_key'] - CA key for signing, default /etc/openvpn/keys/ca.key
  • node['openvpn']['server_verification'] - Server certificate verification directive, can be anything mentioned in official doc. By default nil.
  • node['openvpn']['config']['local'] - IP to listen on, defaults to node['ipaddress']
  • node['openvpn']['config']['proto'] - Valid values are 'udp' or 'tcp', defaults to 'udp'.
  • node['openvpn']['config']['port'] - Port to listen on, defaults to '1194'.
  • node['openvpn']['config']['log'] - Server log file. Default /var/log/openvpn.log
  • node['openvpn']['config']['script-security'] - Script Security setting to use in server config. Default is 1. The "up" script will not be included in the configuration if this is 0 or 1. Set it to 2 to use the "up" script.

The following attributes are used to populate the easy-rsa vars file. Defaults are the same as the vars file that ships with OpenVPN.

  • node['openvpn']['key']['ca_expire'] - In how many days should the root CA key expire - CA_EXPIRE.
  • node['openvpn']['key']['expire'] - In how many days should certificates expire - KEY_EXPIRE.
  • node['openvpn']['key"]['size'] - Default key size, set to 2048 if paranoid but will slow down TLS negotiation performance - KEY_SIZE.

The following are for the default values for fields place in the certificate from the vars file. Do not leave these blank.

  • node['openvpn']['key']['country'] - KEY_COUNTRY
  • node['openvpn']['key']['province'] - KEY_PROVINCE
  • node['openvpn']['key']['city'] - KEY_CITY
  • node['openvpn']['key']['org'] - KEY_ORG
  • node['openvpn']['key']['email'] - KEY_EMAIL

The following lets you specify the message digest used for generating certificates by OpenVPN

  • node['openvpn']['key']['message_digest'] - Default is sha256 for a high-level of security.

The CRL will be generated, and refreshed automatically, allowing you to revoke certificates

  • node['openvpn']['key']['crl_expire'] - In how many days should the CRL expire? Will be refreshed after half of this time

Recipes

openvpn::default

Installs the OpenVPN package only.

openvpn::install

Installs the OpenVPN package only.

openvpn::server

Installs and configures OpenVPN as a server.

openvpn::client

Installs and configures OpenVPN as a client.

openvpn::service

Manages the OpenVPN system service (there is no need to use this recipe directly in your run_list).

openvpn::users

Utilizes a data bag called users to generate OpenVPN keys for each user.

openvpn::easy_rsa

Installs the easy-rsa package (a CLI utility to build and manage a PKI CA).

Usage

Create a role for the OpenVPN server. See above for attributes that can be entered here.

name "openvpn"
description "The server that runs OpenVPN"
run_list("recipe[openvpn::server]")
override_attributes(
  "openvpn" => {
    "gateway" => "vpn.example.com",
    "subnet" => "10.8.0.0",
    "netmask" => "255.255.0.0",
    "key" => {
      "country" => "US",
      "province" => "CA",
      "city" => "SanFrancisco",
      "org" => "Fort-Funston",
      "email" => "[email protected]"
    }
  }
)

Note: If you are using a Red Hat EL distribution, the EPEL repository is automatically enabled by Chef's recipe[yum::epel] to install the openvpn package.

To push routes to clients, add node['openvpn']['push_routes] as an array attribute, e.g. if the internal network is 192.168.100.0/24:

override_attributes(
  "openvpn" => {
    "push_routes" => [
      "192.168.100.0 255.255.255.0"
    ]
  }
)

To push other options to clients, use the node['openvpn']['push_options'] attribute and set an array of hashes or strings. For example:

override_attributes(
  "openvpn" => {
    "push_options" => {
      "dhcp-option" => [
        "DOMAIN domain.local",
        "DOMAIN-SEARCH domain.local"
      ],
      "string-option" => "string value"
    }
  }
)

This will render a config file that looks like:

push "dhcp-option DOMAIN domain.local"
push "dhcp-option DOMAIN-SEARCH domain.local"
push "string-option string value"

To automatically create new certificates and configurations for users, create data bags for each user. The only content required is the id, but this can be used in conjunction with other cookbooks by Chef Software such as users or samba. See SSL Certificates below for more about generating client certificate sets.

{
  "id": "jtimberman"
}

This cookbook also provides an 'up' script that runs when OpenVPN is started. This script is for setting up firewall rules and kernel networking parameters as needed for your environment. Modify to suit your needs, upload the cookbook and re-run chef on the openvpn server. For example, you'll probably want to enable IP forwarding (sample Linux setting is commented out). The attribute node['openvpn']["script_security"] must be set to 2 or higher to use this otherwise openvpn server startup will fail.

Resources

openvpn_user

Implements a resource for creation of users and bundles.

openvpn_config

Given a hash of config options it writes out individual openvpn config files.

If you don't want to use the default "server.conf" from the default recipe, set node['openvpn']["configure_default_server"] to false, then use this resource to configure things as you like.

Example

.pem files should be provided before (e.g.: cookbook_file)

openvpn_conf 'myvpn' do
  config({
    'client' => '',
    'dev' => 'tun',
    'proto' => 'tcp',
    'remote' => '1.2.3.4 443',
    'cipher' => 'AES-128-CBC',
    'tls-cipher' => 'DHE-RSA-AES256-SHA',
    'auth' => 'SHA1',
    'nobind' => '',
    'resolv-retry' => 'infinite',
    'persist-key' => '',
    'persist-tun' => '',
    'ca' => "/etc/openvpn/myvpn/ca.pem",
    'cert' => "/etc/openvpn/myvpn/cert.pem",
    'key' => "/etc/openvpn/myvpn/key.pem",
    'comp-lzo' => '',
    'verb' => false,
    'auth-user-pass' => "/etc/openvpn/myvpn/login.conf",
  })
end

# for systemd based systems
service 'openvpn@myvpn' do
  action [:start, :enable]
end

Customizing Server Configuration

To further customize the server configuration, there are two templates that can be modified in this cookbook.

  • templates/default/server.conf.erb
  • templates/default/server.up.sh.erb

The first is the OpenVPN server configuration file. Modify to suit your needs for more advanced features of OpenVPN. The second is an up script run when OpenVPN starts. This is where you can add firewall rules, enable IP forwarding and other OS network settings required for OpenVPN. Attributes in the cookbook are provided as defaults, you can add more via the openvpn role if you need them.

SSL Certificates

Some of the easy-rsa tools are copied to /etc/openvpn/easy-rsa to provide the minimum to generate the certificates using the default and users recipes. We provide a Rakefile to make it easier to generate client certificate sets if you're not using the data bags above. To generate new client certificates you will need rake installed (either as a gem or a package), then run:

cd /etc/openvpn/easy-rsa
source ./vars
rake client name="CLIENT_NAME" gateway="vpn.example.com"

Replace CLIENT_NAME and vpn.example.com with your desired values. The rake task will generate a tar.gz file with the configuration and certificates for the client.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website

openvpn's People

Contributors

axl89 avatar bdha avatar chewi avatar damacus avatar daviddjh avatar eherot avatar eropple avatar flaccid avatar itwasntandy avatar jeffbyrnes avatar johnroesler avatar josephholsten avatar jperville avatar jtimberman avatar kitchen-porter avatar markgibbons avatar nathenharvey avatar paulpalamarchuk avatar phutchins avatar powerschill avatar ramereth avatar renovate[bot] avatar sethvargo avatar stefanor avatar svdgraaf avatar tas50 avatar vskubriev avatar wolf31o2 avatar xorima avatar xorimabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openvpn's Issues

Foodcritic warnings

FC069: Ensure standardized license defined in metadata: ./metadata.rb:1
FC072: Metadata should not contain "attribute" keyword: ./metadata.rb:1
FC078: Ensure cookbook shared under an OSI-approved open source license: ./metadata.rb:1

Supermarket cookbook

Hi!
The cookbook on the supermarket is very old. Is it planned to release an intermediate version before v3?

Thx

undefined method `proto' for Custom resource openvpn_conf from cookbook openvpn

Cookbook version

[Version of the cookbook where you are encountering the issue]
3.0.0

Chef-client version

[Version of chef-client in your environment]
13.9.1

Platform Details

[Operating system distribution and release version. Cloud provider if running in the cloud]
Ubuntu 16 LTS

Scenario:

[What you are trying to achieve and you can't?]
use the opnvpn_conf resource

Steps to Reproduce:

[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?]

  1. define resource like:
    openvpn_conf 'server' do
    port node['openvpn']['config']['port']
    proto node['openvpn']['config']['proto']
    type node['openvpn']['config']['dev']
    local node['openvpn']['config']['local']
    routes node['openvpn']['routes']
    script_security node['openvpn']['script_security']
    key_dir node['openvpn']['key_dir']
    key_size node['openvpn']['key']['size']
    subnet node['openvpn']['subnet']
    netmask node['openvpn']['netmask']
    user node['openvpn']['user']
    group node['openvpn']['group']
    log node['openvpn']['log']
    not_if { node['openvpn']['configure_default_server'] }
    action :create
    notifies :restart, 'service[openvpn]'
    end

  2. chef converge

Expected Result:

[What are you expecting to happen as the consequence of above reproduction steps?]
succesful converge and conf file creation

Actual Result:

[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]
getting error messages like this for every resource property:
[2018-05-11T23:54:23+00:00] ERROR: undefined method `proto' for Custom resource openvpn_conf from cookbook openvpn

with 2.1.0 is working

create a 'service' recipe

Create a service recipe that contains the openvpn service, so that recipe can be included by both the server recipes, and the client recipe, to make the service managed, and not repeated (to avoid cloned resource warnings).

Openvpn service is not running after reboot

On CentOS 7 the openvpn service is not running after reboot.

"systemctl status [email protected]"

[email protected] - OpenVPN Robust And Highly Flexible Tunneling Application On server
   Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled)
   Active: failed (Result: exit-code) since di 2015-05-05 19:43:08 CEST; 14s ago
  Process: 940 ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/%i.pid --cd /etc/openvpn/ --config %i.conf (code=exited, status=1/FAILURE)

mei 05 19:43:08 combi001.example.com systemd[1]: [email protected]: control process exited, code=exited status=1
mei 05 19:43:08 combi001.example.com systemd[1]: Failed to start OpenVPN Robust And Highly Flexible Tunneling Application On server.
mei 05 19:43:08 combi001.example.com systemd[1]: Unit [email protected] entered failed state.

When I log in with SSH and execute this command manually "systemctl restart [email protected]" it runs fine (however it still says something about a failure).

[email protected] - OpenVPN Robust And Highly Flexible Tunneling Application On server
   Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled)
   Active: active (running) since di 2015-05-05 19:44:42 CEST; 1s ago
  Process: 2060 ExecStart=/usr/sbin/openvpn --daemon --writepid /var/run/openvpn/%i.pid --cd /etc/openvpn/ --config %i.conf (code=exited, status=0/SUCCESS)
 Main PID: 2070 (openvpn)
   CGroup: /system.slice/system-openvpn.slice/[email protected]
           └─2070 /usr/sbin/openvpn --daemon --writepid /var/run/openvpn/server.pid --cd /etc/openvpn/ --config server.conf

mei 05 19:44:42 combi001.example.com systemd[1]: Starting OpenVPN Robust And Highly Flexible Tunneling Application On server...
mei 05 19:44:42 combi001.example.com systemd[1]: Failed to read PID from file /var/run/openvpn/server.pid: Invalid argument
mei 05 19:44:42 combi001.example.com systemd[1]: Started OpenVPN Robust And Highly Flexible Tunneling Application On server.

Multi-machine testing in test-kitchen for server+client

Vagrantfile currently uses vbox private networking to connect the client to server to complete an end to end setup. This needs to be integrated into .kitchen.yml or a separate kitchen yaml so each supported platform can be tested in integration. Sprouted from issue #73.

Use openssl cookbook resource to generate certificates

Rather than a maze of twisty execute/bash resources, we should use the openssl LWRP to generate the required certs/keys. If this requires an update to the openssl cookbook, we should add any functionality necessary.

client_subnet_route may be more than one route

When using client-config-dir directory you can specify more than one client subnet.

client-config-dir ccd
route 10.9.1.0 255.255.255.0
route 10.8.0.0 255.255.255.0

I've modify the cookbook like this to make this possible.

diff --git a/providers/conf.rb b/providers/conf.rb
index be2d9be..d10a0b2 100644
--- a/providers/conf.rb
+++ b/providers/conf.rb
@@ -40,13 +40,14 @@ action :create do
     dhcp_domain: new_resource.dhcp_domain,
     duplicate_cn: new_resource.duplicate_cn,
     interface_num: new_resource.interface_num,
-    client_subnet_route: new_resource.client_subnet_route,
+    client_subnet_routes: new_resource.client_subnet_routes,
     max_clients: new_resource.max_clients,
     status_log: new_resource.status_log,
     plugins: new_resource.plugins

diff --git a/resources/conf.rb b/resources/conf.rb
index bc3deea..fb050ad 100644
--- a/resources/conf.rb
+++ b/resources/conf.rb
@@ -65,8 +65,8 @@ attribute :duplicate_cn,
           default: false
 attribute :interface_num,
           kind_of: Integer
-attribute :client_subnet_route,
-          kind_of: String
+attribute :client_subnet_routes,
+          kind_of: Array
 attribute :max_clients,
           kind_of: Integer
 attribute :status_log,
diff --git a/templates/default/server.conf.erb b/templates/default/server.conf.erb
index 1cfb993..f26bc38 100644
--- a/templates/default/server.conf.erb
+++ b/templates/default/server.conf.erb
@@ -36,9 +36,11 @@ push "dhcp-option DOMAIN <%= @dhcp_domain %>"
 <% if @duplicate_cn -%>
 duplicate-cn
 <% end -%>
-<% if @client_subnet_route -%>
+<% if @client_subnet_routes -%>
 client-config-dir ccd
-route <%= @client_subnet_route %>
+<% @client_subnet_routes.each do |client_subnet_route| -%>
+route <%= client_subnet_route %>
+<% end -%>
 <% end -%>

Persist server PKI including restore to new server nodes

There needs to be idempotency of server PKI (CA cert, key etc.) of a server i.e. if the server dies, run up a new node with the exact same configuration including the PKI elements.

It should also be possible to create a new server node that has a different configuration with other directives but uses the same stored CA, cert and key.

Secrets storage to fetch from is a likely requirement here and this could support multiple sources by means of providers e.g. s3, vault.

Unable to run include_recipe 'openvpn::server'

[2016-05-30T00:52:24+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2016-05-30T00:52:24+00:00] ERROR: could not find recipe server for cookbook openvpn
==> default: [2016-05-30T00:52:24+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

I can work around it by specifying the type as server and running include_recipe 'openvpn' instead

New tag

Hi! Would you mind tagging this, as there are 166 commits since v2.1.0.

Thanks in advance,
Leandro

Update README

to reflect change of attributes, e.g.:

node["openvpn"]["proto"] -> node["openvpn"]['config']["proto"]

Template FileNotFound error using LWRP conf provider

When using LWRP conf provider in my recipe I get this error message because server.conf.erb doesn't exist in my cookbook (which depends on openvpn)

Chef::Exceptions::FileNotFound
------------------------------
template[/etc/openvpn/server.conf]

I resolved it with this change:

diff --git a/providers/conf.rb b/providers/conf.rb
index be2d9be..de783c3 100644
--- a/providers/conf.rb
+++ b/providers/conf.rb
@@ -47,6 +47,7 @@ action :create do
   }

   template "/etc/openvpn/#{new_resource.name}.conf" do
+    cookbook 'openvpn' if !node['openvpn']['override_template']
     source 'server.conf.erb'
     owner 'root'
     group 'root'

rake should (probably?) be installed

The README points out that you can use the rake tasks defined in /etc/openvpn/easy-rsa/Rakefile, but rake is not available by default on an ubuntu 12.04 LTS system (and probably others).

It would be nice to be able to use the openvpn::default recipe, and be able to create users using this raketask without having to bring another recipe to install rake, or install it manually.

Configuration LWRP refactor

The LWRP for managing the client vs server config could be improved by refactoring a few things.

  1. Rename the source template to openpvn.conf.erb since it's not server specific.
  2. Create a service resource that can be restarted/reloaded when the template is updated (optionally, default to true); see also #43 for approaching this in the cookbook's recipes.
  3. Separate resource attribute that is the name attribute, rather than using new_resource#name directly.
  4. ChefSpec coverage, including matchers, to test behavior.
  5. Other things as I dig into the code/templates 😸

Firewall and gateway options needed by default?

  1. I needed to add iptables -t nat -A POSTROUTING -o br0 -j MASQUERADE to /etc/openvpn/server.up.d/postrouting.sh. Without this no packets were forwarded from the tunnel to the internet. I've noticed also that digitalocean tutorials create similar rules using ufw (https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-debian-8)

  2. When starting the client from command line sudo openvpn --config user.ovpn it was necessary to add push "redirect-gateway def1 bypass-dhcp" to server.conf, otherwise it won't completely create the necessary routes on the client. With network-manager it creates the routes anyway.

OpenVPN won't start on CentOS 7

If I switch to CentOS 7 (by changing to "config.vm.box = 'centos-7.2'" in the Vagrantfile) the server machine builds fine but the client machine fails with the error below. It is failing to start the OpenVPN service as it is trying to start [email protected] which in turn causes /etc/systemd/system/multi-user.target.wants/[email protected] file to look for a 'server.conf' OpenVPN config file but none exists as instead the recipe created a 'client.conf' file on the client machine.

I changed the references to "[email protected]" in service.rb file to "[email protected]" and was able to vagrant up the client machine successfully but that in turn breaks the server machine as service.rb is shared across both machines and in the server we create a 'server.conf' file for OpenVPN.

So, definitely a minor thing but I thought it was very cool of you to provide a working Vagrantfile and as it includes a lot of code to work on RHEL platforms I figured I'd try it on CentOS. Also this is basically the last step so fix this and we have RHEL working which would be nice. I'm not entirely certain how best to fix this but am happy to help out if I can.

Thanks all for the awesome recipe,

Paul

==> client: Recipe: openvpn::install
==> client:   * yum_package[openvpn] action install
==> client: [2016-01-07T17:25:43+00:00] INFO: yum_package[openvpn] installing openvpn-2.3.9-1.el7 from epel repository
==> client: [2016-01-07T17:25:46+00:00] INFO: yum_package[openvpn] installed openvpn at 2.3.9-1.el7
==> client: 
==> client:     - install version 2.3.9-1.el7 of package openvpn
==> client: Recipe: openvpn::service
==> client:   * link[/etc/systemd/system/multi-user.target.wants/[email protected]] action create[2016-01-07T17:25:46+00:00] INFO: link[/etc/systemd/system/multi-user.target.wants/[email protected]] created
==> client: 
==> client:     - create symlink at /etc/systemd/system/multi-user.target.wants/[email protected] to /usr/lib/systemd/system/[email protected]
==> client:   * service[openvpn] action enable
==> client:  (up to date)
==> client:   * service[openvpn] action start
==> client: 
==> client:     
==> client:     ================================================================================
==> client:     Error executing action `start` on resource 'service[openvpn]'
==> client:     ================================================================================
==> client:     
==> client:     Mixlib::ShellOut::ShellCommandFailed
==> client:     ------------------------------------
==> client:     Expected process to exit with [0], but received '1'
==> client:     ---- Begin output of /bin/systemctl start [email protected] ----
==> client:     STDOUT: 
==> client:     STDERR: Job for [email protected] failed because the control process exited with error code. See "systemctl status [email protected]" and "journalctl -xe" for details.
==> client:     ---- End output of /bin/systemctl start [email protected] ----
==> client:     Ran /bin/systemctl start [email protected] returned 1
==> client:     
==> client:     Resource Declaration:
==> client:     ---------------------
==> client:     # In /var/chef/cache/cookbooks/openvpn/recipes/service.rb
==> client:     
==> client:      39: service 'openvpn' do
==> client:      40:   service_name service_name
==> client:      41:   action [:enable, :start]
==> client:      42: end
==> client:     
==> client:     Compiled Resource:
==> client:     ------------------
==> client:     # Declared in /var/chef/cache/cookbooks/openvpn/recipes/service.rb:39:in `from_file'
==> client:     
==> client:     service("openvpn") do
==> client:       action [:enable, :start]
==> client:       supports {:restart=>nil, :reload=>nil, :status=>nil}
==> client:       retries 0
==> client:       retry_delay 2
==> client:       default_guard_interpreter :default
==> client:       service_name "[email protected]"
==> client:       enabled true
==> client:       pattern "openvpn"
==> client:       declared_type :service
==> client:       cookbook_name "openvpn"
==> client:       recipe_name "service"
==> client:     end
==> client:     
==> client: [2016-01-07T17:25:46+00:00] INFO: Running queued delayed notifications before re-raising exception
==> client: 
==> client: Running handlers:
==> client: [2016-01-07T17:25:46+00:00] ERROR: Running exception handlers
==> client: Running handlers complete
==> client: [2016-01-07T17:25:46+00:00] ERROR: Exception handlers complete
==> client: Chef Client failed. 7 resources updated in 23 seconds
==> client: [2016-01-07T17:25:46+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> client: [2016-01-07T17:25:46+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
==> client: [2016-01-07T17:25:46+00:00] ERROR: service[openvpn] (openvpn::service line 39) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
==> client: ---- Begin output of /bin/systemctl start [email protected] ----
==> client: STDOUT: 
==> client: STDERR: Job for [email protected] failed because the control process exited with error code. See "systemctl status [email protected]" and "journalctl -xe" for details.
==> client: ---- End output of /bin/systemctl start [email protected] ----
==> client: Ran /bin/systemctl start [email protected] returned 1
==> client: [2016-01-07T17:25:47+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Interest in handling user removal & suspension?

Looking through the code/doc, I don't see a solution for:

  • removing credentials for users with "remove" action
  • suspending credentials for users with "lock" action

Let me know if I just missed it or if folks are handling in a different manner. If not, is there any interest in supporting either of these use cases? If so, I can do my work in this cookbook and submit as PR. Otherwise, will just handle via wrapper.

Cheers,

Todd

Trouble setting push route

I've been trying to make a recipe that pushes a route just using the default configuration. However, the route doesn't show up. Do I need to the LWRP to create a server.conf that has a push route?
example default atttribute in recipe

normal['openvpn']['push_routes'] = ['10.0.0.0 255.255.0.0']

differences between 2.1.0 and 2.1.1 are breaking changes!

There are major changes in 2.1.1 that are not backwards compatible with 2.x. The structure of the recipes in the cookbook, and also the routes attribute changes to push_routes. This is a breaking change.
Therefore the cookbook should be 3.x and follow semver.

possible to allow to override the template file for `user client conf`

Hi,

I have a need for adding one more config for our user client conf, called tls-auth 'ta.key' 1.

But it is not feasible to rewind Chef Resources, since the "user create code" lives inside a Search loop which yields different user id.

Is it possible if we can add cookbook attributes to the template file like this.

%w(conf ovpn).each do |ext|
      template "#{node['openvpn']['key_dir']}/#{node['openvpn']['client_prefix']}-#{u['id']}.#{ext}" do
        source 'client.conf.erb'
        cookbook node['openvpn']['client_template_cookbook']
        variables(client_cn: u['id'])
      end
    end

Client recipe (and conf provider) don't set username in conf template

I just wanted to use the openvpn::client recipe, however it's pretty broken atm (in 2.1.1 / master).

Here's the output from the chef-client run:

...
       Recipe: openvpn::service
         * service[openvpn] action restart

           ================================================================================
           Error executing action `restart` on resource 'service[openvpn]'
           ================================================================================

           Mixlib::ShellOut::ShellCommandFailed
           ------------------------------------
           Expected process to exit with [0], but received '1'
           ---- Begin output of /etc/init.d/openvpn start ----
           STDOUT: * Starting virtual private network daemon(s)...
            *   Autostarting VPN 'client'
           STDERR: 
           ---- End output of /etc/init.d/openvpn start ----
       Ran /etc/init.d/openvpn start returned 1


           ---------------------
           # In /tmp/kitchen/cache/cookbooks/openvpn/recipes/service.rb

            39: service 'openvpn' do
            40:   service_name service_name
            41:   action [:enable, :start]
            42: end

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/openvpn/recipes/service.rb:39:in `from_file'

           service("openvpn") do
             action [:enable, :start]
             updated true
             supports {:restart=>nil, :reload=>nil, :status=>nil}
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             service_name "openvpn"
             enabled true
             running true
             pattern "openvpn"
             declared_type :service
             cookbook_name "openvpn"
             recipe_name "service"
           end

...       
       Running handlers:
       [2016-01-28T06:13:44+08:00] ERROR: Running exception handlers
       Running handlers complete
       [2016-01-28T06:13:44+08:00] ERROR: Exception handlers complete
       Chef Client failed. 41 resources updated in 01 minutes 59 seconds
       [2016-01-28T06:13:44+08:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2016-01-28T06:13:44+08:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2016-01-28T06:13:44+08:00] ERROR: service[openvpn] (openvpn::service line 39) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
       ---- Begin output of /etc/init.d/openvpn start ----
       STDOUT: * Starting virtual private network daemon(s)...
        *   Autostarting VPN 'client'
       STDERR: 
       ---- End output of /etc/init.d/openvpn start ----
       Ran /etc/init.d/openvpn start returned 1
       [2016-01-28T06:13:45+08:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
>>>>>> Converge failed on instance <default-ubuntu-1404>.
>>>>>> Please see .kitchen/logs/default-ubuntu-1404.log for more details
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: SSH exited (1) for command: [sh -c '

sudo -E /opt/chef/bin/chef-client --local-mode --config /tmp/kitchen/client.rb --log_level auto --force-formatter --no-color --json-attributes /tmp/kitchen/dna.json --chef-zero-port 8889
']
>>>>>> ----------------------

here's the relevant output from /var/log/syslog:

Jan 27 22:13:43 vagrant ovpn-client[3249]: Options error: --ca fails with 'ca.crt': No such file or directory
Jan 27 22:13:43 vagrant ovpn-client[3249]: Options error: --cert fails with '.crt': No such file or directory
Jan 27 22:13:43 vagrant ovpn-client[3249]: Options error: --key fails with '.key': No such file or directory
Jan 27 22:13:43 vagrant ovpn-client[3249]: Options error: Please correct these errors.
Jan 27 22:13:43 vagrant ovpn-client[3249]: Use --help for more information.

And here's how the template ends up:

vagrant@default-ubuntu-1404:~$ vi /etc/openvpn/client.conf 

# OpenVPN client configuration file
# Generated by Chef - local changes will be overwritten!

# Please refer to the OpenVPN documentation for details on
# configuration settings.

client
dev tun
proto udp
remote vpn. 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert .crt
key .key
comp-lzo
verb 3 

The username is set and used by the openvpn::users recipe, but not from the openvpn::client.

new release

There's been a lot of changes since the last release in 2013. Any idea when this new 3.0.0 version will make the cut and be tagged/added to supermarket?

recipies mentioned in readme missing in package.

Cookbook version

2.1.0, 2.0.4

Chef-client version

12

Platform Details

ubuntu 16.04

Scenario:

some recipies were missing in package mentioned in readme (openvpn::server)

Steps to Reproduce:

run recipie openvpn::server

Expected Result:

to initiate openvpn::server

Actual Result:

Chef::Exceptions::RecipeNotFound

could not find recipe server for cookbook openvpn

Recommended method of revoking users?

Thanks for providing the cookbook to create a VPN server. I don't see anything in the documentation about how to revoke users. I also don't see the revoke-full command on the server to do it according to the "OpenVPN way".

What is the recommended way of removing users access to the VPN?

Ideally I'd like to remove the user, manually run chef on the server and have it boot that user from the connection.

Thanks!

Install dependency libengine-pkcs11-openssl

I've noticed after struggling to install openvpn with this cookbook on a debian jessie that /etc/openvpn/keys/openssl.cnf refers to /usr/lib/engines/engine_pkcs11.so but this file doesn't exist. So probably libengine-pkcs11-openssl package needs to be installed too

Args option

Cookbook version

[Version of the cookbook where you are encountering the issue]

Chef-client version

[Version of chef-client in your environment]

Platform Details

[Operating system distribution and release version. Cloud provider if running in the cloud]

Scenario:

I would like to add to openvpn args " --status-version 2" to use with collectd plugin (https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_openvpn).

By default, status version is 1

       --status-version [n]
              Choose the status file format version number.  Currently n can be 1, 2, or 3 and defaults to 1.

I don't see how to do that in this cookbook. Any idea ?

Steps to Reproduce:

[If you are filing an issue what are the things we need to do in order to repro your problem? How are you using this cookbook or any resources it includes?]

Expected Result:

[What are you expecting to happen as the consequence of above reproduction steps?]

Actual Result:

[What actually happens after the reproduction steps? Include the error output or a link to a gist if possible.]

IP Forwarding setup

Hi guys,

I noticed there's an enable_ip_forwarding recipe which is not yet documented in the README.md which seems to help me achieve the same (?) thing as using the server.up script does?

In particular I see this recipe sets the net.ipv4.conf.all.forwarding and net.ipv6.conf.all.forwarding using the sysctl_param resource. The up script, if used, sets /sbin/sysctl -w net.ipv4.ip_forward=1, so I am somewhat unsure as to which method is the preferred one to use here.. ?

If someone could help explain this, I'd be happy to tidy it up in a PR that helps document this.

Thanks!

Support for OpenVZ servers

/var/log/openvpn.log

  1 Sat Apr  2 21:59:54 2016 OpenVPN 2.3.2 i686-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Dec  1 2014
  2 Sat Apr  2 21:59:54 2016 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
  3 Sat Apr  2 21:59:54 2016 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory (errno=2)
  4 Sat Apr  2 21:59:54 2016 Exiting due to fatal error

Possible solutions:
http://wiki.vpslink.com/TUN/TAP_device_with_OpenVPN_or_Hamachi
http://wiki.openvz.org/VPN_via_the_TUN/TAP_device

Persist certs/keys after initial build

Executing the openvpn::default on a new server will generate a slew of openssl files (i.e. server.crt, server.key, ca.crt, dh2048.pem, etc...). After the initial build of a VPN server and distribution of some of those files to clients, how do we ensure those files persist beyond node failure, or are used on say multiple openvpn servers (load balanced for availability)?

I must be missing something here.

Release with the current changes

Any chance there's going to be a release with the new key/val based config options sometime soon? That would allow for a lot more robust changes and would be really useful as long as everyone is aware that's it's going to break their existing configs.

setting [:openvpn][:push_options][:"dhcp-option"] - not working

Hey Folks,

it looks like specifying the push_options attribute doesnt trigger anything

override[:openvpn][:push_options][:"dhcp-option"] = "DNS 10.0.0.2"

when i look into templates/default/server.conf.erb - i dont see any handling inside
neither

<% @config.sort.each do |key, value| %>
<% next if value.nil? -%>
<%= key %> <%=
  case value
  when String
    value
  when TrueClass
    1
  when FalseClass
    0
  else
    value
  end
%>
<% end %>

<% unless @push_routes.empty? %>
# additional routes to push to clients
  <% @push_routes.each do |route| %>
push "route <%= route %>"
  <% end %>
<% end %>

same is under providers/conf.rb

i see that variables are passed through node['openvpn']['config'] & node['openvpn']['push_routes']
but nowhere i find node['openvpn']['push_options']

action :create do
  template "/etc/openvpn/#{new_resource.name}.conf" do
    cookbook 'openvpn'
    source "#{new_resource.name}.conf.erb"
    owner 'root'
    group 'root'
    mode 0644
    variables(
      config: new_resource.config || node['openvpn']['config'],
      push_routes: node['openvpn']['push_routes']
    )
  end
end

maybe i'm blind - any hints ?

"users bags"

I'm very new to Chef (started yesterday) and I'm wondering what the parameters to the knife tool to create the user data bags, I've tried the following combinations:

  • users (data bag), openvpn (data bag item)
  • openvpn (data bag), users (item)
  • users (data bag), zack (item)

Is there something I'm missing?

berks cookbook does not download the latest version of openvpn

Hi,
My berksfile is:
`
source "https://supermarket.chef.io"

metadata

cookbook 'openvpn', '~> 2.1.0'
`

However, during berks install I don't have the latest template file: server.conf.erb.
I logged into my test kitchen, it is a different file

`

OpenVPN server config file

Generated by Chef - local changes will be overwritten

port <%= @PORT %>
proto <%= @proto %>
<% if @type == "server-bridge" -%>
dev tap<%= @interface_num %>
<% else -%>
dev tun<%= @interface_num %>
The problem with this old file is that if the 'plugins' is empty as default, it would bring the error - Nomethod each for Nil:NilClass
<% @plugins.each do |p| -%>
plugin <%= p %>
`
<% end -%>

Setting ["openvpn"]["routes"] in role override_attributes doesn't set routes

{
  "name": "openvpn-server",
  "default_attributes": {
  },
  "json_class": "Chef::Role",
  "run_list": [
    "recipe[openvpn::default]",
    "recipe[openvpn::users]"
  ],
  "description": "OpenVPN Server",
  "chef_type": "role",
  "override_attributes": {
      "openvpn" : {
          "config" : {
              "local" : "0.0.0.0",
          },
          "gateway" : "gw.example.com",
          "subnet" : "192.168.0.0",
          "netmask" : "255.255.0.0",
          "routes" : [
              "push 'route 1.2.3.0 255.255.255.224'"
          ],
          "script_security" : "2",
      }
  }
}

No push routes show up in server.conf.

Use lazy evaluation for key generation

You already use unless...

# Use unless instead of not_if otherwise OpenSSL::PKey::DH runs every time.
unless ::File.exist?("#{key_dir}/dh#{key_size}.pem")

But when I wrap the cookbook and have my own key process, this still runs at converge time on the first run unnecessarily. If you use the recommended key size (4096) this is extremely painful.

My workaround was to send a key size smaller than I'm actually using (side-effects unknown), but lazy evaluation should deal with this nicely.

https://docs.chef.io/resource_common.html#lazy-evaluation

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.