Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
openssl Cookbook CHANGELOG
==========================
This file is used to list changes made in each version of the openssl cookbook.
v4.0.0 (2014-02-19)
-------------------
- Reverting to Opscode module namespace
v3.0.2 (2014-12-30)
-------------------
- Accidently released 2.0.2 as 3.0.2
v2.0.2 (2014-12-30)
-------------------
- Call cert.to_pem before recipe DSL
v2.0.0 (2014-06-11)
-------------------
- #1 - **[COOK-847](https://tickets.chef.io/browse/COOK-847)** - Add LWRP for generating self signed certs
- #4 - **[COOK-4715](https://tickets.chef.io/browse/COOK-4715)** - add upgrade recipe and complete test harness
v1.1.0
------
### Improvement
- **[COOK-3222](https://tickets.chef.io/browse/COOK-3222)** - Allow setting length for `secure_password`
v1.0.2
------
- Add name attribute to metadata

115
cookbooks/openssl/README.md Normal file
View File

@@ -0,0 +1,115 @@
openssl Cookbook
================
This cookbook provides a library method to generate secure random passwords in recipes using the Ruby OpenSSL library.
It also provides an attribute-driven recipe for upgrading OpenSSL packages.
Requirements
------------
The `secure_password` works on any platform with OpenSSL Ruby bindings installed, which are a requirement for Chef anyway.
The upgrade recipe works on the following tested platforms:
* Ubuntu 12.04, 14.04
* Debian 7.4
* CentOS 6.5
It may work on other platforms or versions of the above platforms with or without modification.
[Chef Sugar](https://github.com/sethvargo/chef-sugar) was introduced as a dependency to provide helpers that make the default attribute settings (see Attributes) easier to reason about.
Attributes
----------
* `node['openssl']['packages']` - An array of packages of openssl. The default attributes attempt to be smart about which packages are the default, but this may need to be changed by users of the `openssl::upgrade` recipe.
* `node['openssl']['restart_services']` - An array of service resources that use the `node['openssl']['packages']`. This is empty by default as Chef has no reliably reasonable way to detect which applications or services are compiled against these packages. *Note* These each need to be "`service`" resources specified somewhere in the recipes in the node's run list.
Recipes
-------
### upgrade
The upgrade recipe iterates over the list of packages in the `node['openssl']['packages']` attribute and manages them with the `:upgrade` action. Each package will send `:restart` notification to service resources named by the `node['openssl']['restart_services']` attribute.
Usage
-----
Most often this will be used to generate a secure password for an attribute. In a recipe:
```ruby
::Chef::Recipe.send(:include, Chef::OpenSSL::Password)
node.set_unless[:my_password] = secure_password
```
To use the `openssl::upgrade` recipe, set the attributes as mentioned above. For example, we have a "stats_collector" service that uses openssl. It has a recipe that looks like this:
LWRP
====
This cookbook includes an LWRP for generating Self Signed Certificates
## openssl_x509
generate a pem formatted x509 cert + key
### Attributes
`common_name` A String representing the `CN` ssl field
`org` A String representing the `O` ssl field
`org_unit` A String representing the `OU` ssl field
`country` A String representing the `C` ssl field
`expire` A Fixnum reprenting the number of days from _now_ to expire the cert
`key_file` Optional A string to the key file to use. If no key is present it will generate and store one.
`key_pass` A String that is the key's passphrase
`key_length` A Fixnum reprenting your desired Bit Length _Default: 2048_
`owner` The owner of the files _Default: "root"_
`group` The group of the files _Default: "root"_
`mode` The mode to store the files in _Default: "0400"_
### Example usage
openssl_x509 "/tmp/mycert.pem" do
common_name "www.f00bar.com"
org "Foo Bar"
org_unit "Lab"
country "US"
end
License and Author
==================
Author:: Jesse Nelson (<spheromak@gmail.com>)
Author:: Joshua Timberman (<joshua@chef.io>)
=======
```ruby
node.default['openssl']['restart_services'] = ['stats_collector']
# other recipe code here...
service 'stats_collector' do
action [:enable, :start]
end
include_recipe 'openssl::upgrade'
```
This will ensure that openssl is upgraded to the latest version so the `stats_collector` service won't be exploited (hopefully!).
```text
Copyright:: 2009-2011, Chef Software, Inc
Copyright:: 2014, Chef Software, Inc <legal@chef.io>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

View File

@@ -0,0 +1,21 @@
#
# Cookbook Name:: openssl
# Attributes:: default
#
# Copyright 2014, Chef Software, Inc. <legal@chef.io>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
default['openssl']['packages'] = []
default['openssl']['restart_services'] = []

View File

@@ -0,0 +1,37 @@
#
# Cookbook Name:: openssl
# Library:: secure_password
# Author:: Joshua Timberman <joshua@chef.io>
#
# Copyright 2009, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'openssl'
module Opscode
module OpenSSL
module Password
def secure_password(length = 20)
pw = String.new
while pw.length < length
pw << ::OpenSSL::Random.random_bytes(1).gsub(/\W/, '')
end
pw
end
end
end
end

View File

@@ -0,0 +1,31 @@
{
"name": "openssl",
"version": "4.0.0",
"description": "Provides a library with a method for generating secure random passwords.",
"long_description": "openssl Cookbook\n================\n\nThis cookbook provides a library method to generate secure random passwords in recipes using the Ruby OpenSSL library.\n\nIt also provides an attribute-driven recipe for upgrading OpenSSL packages.\n\nRequirements\n------------\n\nThe `secure_password` works on any platform with OpenSSL Ruby bindings installed, which are a requirement for Chef anyway.\n\nThe upgrade recipe works on the following tested platforms:\n\n* Ubuntu 12.04, 14.04\n* Debian 7.4\n* CentOS 6.5\n\nIt may work on other platforms or versions of the above platforms with or without modification.\n\n[Chef Sugar](https://github.com/sethvargo/chef-sugar) was introduced as a dependency to provide helpers that make the default attribute settings (see Attributes) easier to reason about.\n\nAttributes\n----------\n\n* `node['openssl']['packages']` - An array of packages of openssl. The default attributes attempt to be smart about which packages are the default, but this may need to be changed by users of the `openssl::upgrade` recipe.\n* `node['openssl']['restart_services']` - An array of service resources that use the `node['openssl']['packages']`. This is empty by default as Chef has no reliably reasonable way to detect which applications or services are compiled against these packages. *Note* These each need to be \"`service`\" resources specified somewhere in the recipes in the node's run list.\n\nRecipes\n-------\n\n### upgrade\n\nThe upgrade recipe iterates over the list of packages in the `node['openssl']['packages']` attribute and manages them with the `:upgrade` action. Each package will send `:restart` notification to service resources named by the `node['openssl']['restart_services']` attribute.\n\nUsage\n-----\n\nMost often this will be used to generate a secure password for an attribute. In a recipe:\n\n```ruby\n::Chef::Recipe.send(:include, Chef::OpenSSL::Password)\nnode.set_unless[:my_password] = secure_password\n```\n\nTo use the `openssl::upgrade` recipe, set the attributes as mentioned above. For example, we have a \"stats_collector\" service that uses openssl. It has a recipe that looks like this:\n\nLWRP\n==== \n\nThis cookbook includes an LWRP for generating Self Signed Certificates\n\n## openssl_x509\ngenerate a pem formatted x509 cert + key \n\n### Attributes\n`common_name` A String representing the `CN` ssl field\n`org` A String representing the `O` ssl field\n`org_unit` A String representing the `OU` ssl field\n`country` A String representing the `C` ssl field\n`expire` A Fixnum reprenting the number of days from _now_ to expire the cert\n`key_file` Optional A string to the key file to use. If no key is present it will generate and store one. \n`key_pass` A String that is the key's passphrase\n`key_length` A Fixnum reprenting your desired Bit Length _Default: 2048_\n`owner` The owner of the files _Default: \"root\"_\n`group` The group of the files _Default: \"root\"_\n`mode` The mode to store the files in _Default: \"0400\"_\n\n### Example usage\n\n openssl_x509 \"/tmp/mycert.pem\" do\n common_name \"www.f00bar.com\"\n org \"Foo Bar\"\n org_unit \"Lab\"\n country \"US\"\n end\n\n \nLicense and Author\n==================\n\nAuthor:: Jesse Nelson (<spheromak@gmail.com>)\nAuthor:: Joshua Timberman (<joshua@chef.io>)\n=======\n\n\n```ruby\nnode.default['openssl']['restart_services'] = ['stats_collector']\n\n# other recipe code here...\nservice 'stats_collector' do\n action [:enable, :start]\nend\n\ninclude_recipe 'openssl::upgrade'\n```\n\nThis will ensure that openssl is upgraded to the latest version so the `stats_collector` service won't be exploited (hopefully!).\n\n```text\nCopyright:: 2009-2011, Chef Software, Inc\nCopyright:: 2014, Chef Software, Inc <legal@chef.io>\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n",
"maintainer": "Chef Software, Inc.",
"maintainer_email": "cookbooks@chef.io",
"license": "Apache 2.0",
"platforms": {
},
"dependencies": {
"chef-sugar": ">= 0.0.0"
},
"recommendations": {
},
"suggestions": {
},
"conflicting": {
},
"providing": {
},
"replacing": {
},
"attributes": {
},
"groupings": {
},
"recipes": {
"openssl": "Empty, this cookbook provides a library, see README.md"
}
}

View File

@@ -0,0 +1,94 @@
#
# x509 self signed cert provider
#
# Author:: Jesse Nelson <spheromak@gmail.com>
#
require 'openssl'
use_inline_resources
attr_reader :key_file, :key, :cert, :ef
action :create do
unless ::File.exists? new_resource.name
create_keys
cert_content = cert.to_pem
key_content = key.to_pem
file new_resource.name do
action :create_if_missing
mode new_resource.mode
owner new_resource.owner
group new_resource.group
content cert_content
end
file new_resource.key_file do
action :create_if_missing
mode new_resource.mode
owner new_resource.owner
group new_resource.group
content key_content
end
end
end
protected
def key_file
unless new_resource.key_file
path, file= ::File.split(new_resource.name)
filename = ::File.basename(file, ::File.extname(file) )
new_resource.key_file path + "/" + filename + ".key"
end
new_resource.key_file
end
def key
@key ||= if ::File.exists? key_file
OpenSSL::PKey::RSA.new File.read(key_file), new_resource.key_pass
else
OpenSSL::PKey::RSA.new(new_resource.key_length)
end
@key
end
def cert
@cert ||= OpenSSL::X509::Certificate.new
end
def gen_cert
cert
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
cert.not_before = Time.now
cert.not_after = Time.now + (new_resource.expire.to_i * 24 * 60 * 60)
cert.public_key = key.public_key
cert.serial = 0x0
cert.version = 2
end
def subject
@subject ||= "/C=" + new_resource.country +
"/O=" + new_resource.org +
"/OU=" + new_resource.org_unit +
"/CN=" + new_resource.common_name
end
def extensions
[
ef.create_extension("basicConstraints","CA:TRUE", true),
ef.create_extension("subjectKeyIdentifier", "hash"),
]
end
def create_keys
gen_cert
@ef ||= OpenSSL::X509::ExtensionFactory.new
ef.subject_certificate = cert
ef.issuer_certificate = cert
cert.extensions = extensions
cert.add_extension ef.create_extension("authorityKeyIdentifier",
"keyid:always,issuer:always")
cert.sign key, OpenSSL::Digest::SHA1.new
end

View File

@@ -0,0 +1,18 @@
#
# Cookbook Name:: openssl
# Recipe:: default
#
# Copyright 2009, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

View File

@@ -0,0 +1,39 @@
#
# Cookbook Name:: openssl
# Recipe:: upgrade
#
# Copyright 2014, Chef Software, Inc. <legal@chef.io>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include_recipe 'chef-sugar'
node.default['openssl']['packages'] = case
when debian_before_or_at_squeeze?, ubuntu_before_or_at_lucid?
%w{libssl0.9.8 openssl}
when debian_after_or_at_wheezy?, ubuntu_after_or_at_precise?
%w{libssl1.0.0 openssl}
when rhel?
%w{openssl}
else
[]
end
node['openssl']['packages'].each do |ssl_pkg|
package ssl_pkg do
action :upgrade
node['openssl']['restart_services'].each do |ssl_svc|
notifies :restart, "service[#{ssl_svc}]"
end
end
end

View File

@@ -0,0 +1,16 @@
actions [ :create ]
default_action :create
attribute :name, :kind_of => String, :name_attribute => true
attribute :owner, :kind_of => String
attribute :group, :kind_of => String
attribute :expire, :kind_of => Fixnum
attribute :mode
attribute :org, :kind_of => String, :required => true
attribute :org_unit, :kind_of => String, :required => true
attribute :country, :kind_of => String, :required => true
attribute :common_name, :kind_of => String, :required => true
attribute :key_file, :kind_of => String, :default => nil
attribute :key_pass, :kind_of => String, :default => nil
attribute :key_length, :kind_of => Fixnum, :default => 2048