simp-beaker-helpers 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDlhMjkxYTRmMTM5NDg4ZWY2OTk2OWQyM2E4NDgyZGJmNmVlYTkzYw==
5
+ data.tar.gz: !binary |-
6
+ ZGQ3MzBlZDg2MTNiYmUwYWQwYmNkZjdhMDQxZjg1M2E0MGM2ZjVjNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjJhMjU5YmI3MjlkNmFmMDkzNTc1OTAwMGIyNDFjMmY2MWNmZTRiZTE2OWVj
10
+ MTg4YTczOTRkY2FjYzViYTA0MGY3OWUwOGFjNDRjYTNiMzkyZWUyZmUwMjY2
11
+ NDU4YjdlMTY3MmQ1NmM5YzE5MzVmZjI2NDAxODcyOWNhMWUyMTE=
12
+ data.tar.gz: !binary |-
13
+ Mzk4MjYzYjBiZjg2YzI2MTA5NDQ3OWRhYjI2NmUyZTA2MDk2ODFmNWJjYTNi
14
+ NTFkZTA4NmVjNGJlNWIxNGY4OWI2ODliOWJhYzZjMTM0NDM1Y2UzZTY2MDJh
15
+ YTViOTY0YzI0ZGNkYWFhNTM3NmI4MTlmYjg1YzFhYTRhMzg5YmY=
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.swp
3
+ Gemfile.lock
4
+ .bundle/
5
+ *.old
@@ -0,0 +1,22 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+
5
+ # to provide the cracklib-check
6
+ sudo: required
7
+ before_install:
8
+ - sudo apt-get update -qq
9
+ - sudo apt-get install -y libcrack2
10
+
11
+ rvm:
12
+ - 1.9.3
13
+ - 2.0.0
14
+
15
+ env:
16
+ - SIMP_SKIP_NON_SIMPOS_TESTS=1
17
+
18
+
19
+ script:
20
+ - 'bundle exec rake spec'
21
+
22
+
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # Allow a comma or space-delimited list of gem servers
2
+ if simp_gem_server = ENV.fetch( 'SIMP_GEM_SERVERS', 'https://rubygems.org' )
3
+ simp_gem_server.split( / |,/ ).each{ |gem_server|
4
+ source gem_server
5
+ }
6
+ end
7
+
8
+ # read dependencies in from the gemspec
9
+ gemspec
10
+
11
+ # mandatory gems
12
+ gem 'bundler'
13
+ gem 'rake'
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ rubygem-simp-beaker-helpers - methods to help Beaker scaffolding SIMP tests
2
+
3
+ --
4
+
5
+ Per Section 105 of the Copyright Act of 1976, these works are not entitled to
6
+ domestic copyright protection under US Federal law.
7
+
8
+ The US Government retains the right to pursue copyright protections outside of
9
+ the United States.
10
+
11
+ The United States Government has unlimited rights in this software and all
12
+ derivatives thereof, pursuant to the contracts under which it was developed and
13
+ the License under which it falls.
14
+
15
+ ---
16
+
17
+ Licensed under the Apache License, Version 2.0 (the "License");
18
+ you may not use this file except in compliance with the License.
19
+ You may obtain a copy of the License at
20
+
21
+ http://www.apache.org/licenses/LICENSE-2.0
22
+
23
+ Unless required by applicable law or agreed to in writing, software
24
+ distributed under the License is distributed on an "AS IS" BASIS,
25
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ See the License for the specific language governing permissions and
27
+ limitations under the License.
@@ -0,0 +1,140 @@
1
+ # simp-beaker-helpers
2
+
3
+ Methods to assist beaker acceptance tests for SIMP.
4
+
5
+ #### Table of Contents
6
+ 1. [Overview](#overview)
7
+ 2. [Setup](#setup)
8
+ * [Beginning with simp-beaker-helpers](#beginning-with-simp-beaker-helpers)
9
+ 3. [Methods](#methods)
10
+ * [`copy_fixture_modules_to`](#copy_fixture_modules_to)
11
+ * [`fix_errata_on`](#fix_errata_on)
12
+ * [`run_fake_pki_ca_on`](#run_fake_pki_ca_on)
13
+ * [`copy_pki_to`](#copy_pki_to)
14
+ * [`copy_keydist_to`](#copy_keydist_to)
15
+ 4. [Examples](#examples)
16
+ * [Prep OS, Generate and copy PKI certs to each SUT](#prep-os-generate-and-copy-pki-certs-to-each-sut)
17
+ 5. [License](#license)
18
+
19
+ ## Overview
20
+
21
+ ## Setup
22
+
23
+ ### Beginning with simp-beaker-helpers
24
+
25
+ Add this to your project's `Gemfile`:
26
+
27
+ ```ruby
28
+ gem 'simp-beaker-helpers'
29
+ ```
30
+
31
+ Add this to your project's `spec/spec_helper_acceptance.rb`:
32
+ ```ruby
33
+ require 'simp-beaker-helpers'
34
+ include SIMP::BeakerHelpers
35
+ ```
36
+
37
+
38
+
39
+ ## Methods
40
+
41
+ #### `copy_fixture_modules_to`
42
+
43
+ Copies the local fixture modules (under `spec/fixtures/modules`) onto a list of SUTs
44
+ `copy_fixture_modules_to( suts = hosts )`
45
+
46
+
47
+ #### `fix_errata_on`
48
+
49
+ Apply any OS fixes we need on each SUT
50
+ `fix_errata_on( suts = hosts )`
51
+
52
+
53
+ #### `run_fake_pki_ca_on`
54
+
55
+ Generate a fake openssl CA + certs for each host on a given SUT and copy the
56
+ files back to a local directory.
57
+
58
+ **NOTE:** this needs to generate everything inside an SUT. It is assumed the
59
+ SUT will have the appropriate openssl in its environment.
60
+
61
+ `run_fake_pki_ca_on( ca_sut = master, suts = hosts, local_dir = '' )`
62
+
63
+ - **ca_sut** = the SUT to generate the CA & certs on
64
+ - **suts** = list of SUTs to generate certs for
65
+ - **local_dir** = local path where the CA+cert directory tree should copied back to
66
+
67
+ #### `copy_pki_to`
68
+
69
+ Copy a single SUT's PKI certs (with cacerts) onto an SUT. This simulates the result of `pki::copy`.
70
+
71
+ The directory structure copied to the SUT is:
72
+ ```
73
+ HOST_PKI_DIR/
74
+ cacerts/cacert.pem
75
+ public/fdqn.pub
76
+ private/fdqn.pem
77
+
78
+ ```
79
+
80
+ `copy_pki_to(sut, local_pki_dir, sut_pki_dir = '/etc/pki/simp-testing')`
81
+
82
+
83
+ #### `copy_keydist_to`
84
+
85
+ Copy a CA keydist/ directory of CA+host certs into an SUT
86
+
87
+ This simulates the output of FakeCA's `gencerts_nopass.sh` into `keydist/`
88
+
89
+ `def copy_keydist_to( ca_sut = master )`
90
+
91
+
92
+ ## Examples
93
+
94
+ ### Prep OS, Generate and copy PKI certs to each SUT
95
+ This pattern serves to prepare component modules that use PKI
96
+
97
+ ```ruby
98
+ # spec/spec_acceptance_helpers.rb
99
+ require 'beaker-rspec'
100
+ require 'tmpdir'
101
+ require 'simp/beaker_helpers'
102
+ include Simp::BeakerHelpers
103
+
104
+ unless ENV['BEAKER_provision'] == 'no'
105
+ hosts.each do |host|
106
+ # Install Puppet
107
+ if host.is_pe?
108
+ install_pe
109
+ else
110
+ install_puppet
111
+ end
112
+ end
113
+ end
114
+
115
+
116
+ RSpec.configure do |c|
117
+ # ensure that environment OS is ready on each host
118
+ fix_errata_on hosts
119
+
120
+ # Readable test descriptions
121
+ c.formatter = :documentation
122
+
123
+ # Configure all nodes in nodeset
124
+ c.before :suite do
125
+ begin
126
+ # Install modules and dependencies from spec/fixtures/modules
127
+ copy_fixture_modules_to( hosts )
128
+ Dir.mktmpdir do |cert_dir|
129
+ run_fake_pki_ca_on( default, hosts, cert_dir )
130
+ hosts.each{ |host| copy_pki_to( host, cert_dir, '/etc/pki/simp-testing' )}
131
+ end
132
+ rescue StandardError, ScriptError => e
133
+ require 'pry'; binding.pry if ENV['PRY']
134
+ end
135
+ end
136
+ end
137
+ ```
138
+
139
+ ## License
140
+ See [LICENSE](LICENSE)
@@ -0,0 +1,141 @@
1
+ $: << File.expand_path( '../lib/', __FILE__ )
2
+
3
+ require 'rubygems'
4
+ require 'rake/clean'
5
+ require 'fileutils'
6
+ require 'find'
7
+
8
+ @package='simp-beaker-helpers'
9
+ @rakefile_dir=File.dirname(__FILE__)
10
+
11
+
12
+ CLEAN.include "#{@package}-*.gem"
13
+ CLEAN.include 'pkg'
14
+ CLEAN.include 'dist'
15
+ Find.find( @rakefile_dir ) do |path|
16
+ if File.directory? path
17
+ CLEAN.include path if File.basename(path) == 'tmp'
18
+ else
19
+ Find.prune
20
+ end
21
+ end
22
+
23
+
24
+ desc 'Ensure gemspec-safe permissions on all files'
25
+ task :chmod do
26
+ gemspec = File.expand_path( "#{@package}.gemspec", @rakefile_dir ).strip
27
+ spec = Gem::Specification::load( gemspec )
28
+ spec.files.each do |file|
29
+ FileUtils.chmod 'go=r', file
30
+ end
31
+ end
32
+
33
+ desc 'special notes about these rake commands'
34
+ task :help do
35
+ puts %Q{
36
+ == environment variables ==
37
+ SIMP_RPM_BUILD when set, alters the gem produced by pkg:gem to be RPM-safe.
38
+ 'pkg:gem' sets this automatically.
39
+ }
40
+ end
41
+
42
+ desc 'run all RSpec tests'
43
+ task :spec do
44
+ Dir.chdir @rakefile_dir
45
+ sh 'bundle exec rspec spec'
46
+ end
47
+
48
+ desc %q{run all RSpec tests (alias of 'spec')}
49
+ task :test => :spec
50
+
51
+ namespace :pkg do
52
+ @specfile_template = "rubygem-#{@package}.spec.template"
53
+ @specfile = "build/rubygem-#{@package}.spec"
54
+
55
+ # ----------------------------------------
56
+ # DO NOT UNCOMMENT THIS: the spec file requires a lot of tweaking
57
+ # ----------------------------------------
58
+ # desc "generate RPM spec file for #{@package}"
59
+ # task :spec => [:clean, :gem] do
60
+ # Dir.glob("pkg/#{@package}*.gem") do |pkg|
61
+ # sh %Q{gem2rpm -t "#{@specfile_template}" "#{pkg}" > "#{@specfile}"}
62
+ # end
63
+ # end
64
+
65
+ desc "build rubygem package for #{@package}"
66
+ task :gem => :chmod do
67
+ Dir.chdir @rakefile_dir
68
+ Dir['*.gemspec'].each do |spec_file|
69
+ cmd = %Q{SIMP_RPM_BUILD=1 bundle exec gem build "#{spec_file}"}
70
+ sh cmd
71
+ FileUtils.mkdir_p 'dist'
72
+ FileUtils.mv Dir.glob("#{@package}*.gem"), 'dist/'
73
+ end
74
+ end
75
+
76
+
77
+ desc "build and install rubygem package for #{@package}"
78
+ task :install_gem => [:clean, :gem] do
79
+ Dir.chdir @rakefile_dir
80
+ Dir.glob("dist/#{@package}*.gem") do |pkg|
81
+ sh %Q{bundle exec gem install #{pkg}}
82
+ end
83
+ end
84
+
85
+
86
+ desc "generate RPM for #{@package}"
87
+ require 'tmpdir'
88
+ task :rpm, [:mock_root] => [:clean, :gem] do |t, args|
89
+ mock_root = args[:mock_root]
90
+ # TODO : Get rid of this terrible code. Shoe-horned in until
91
+ # we have a better idea for auto-decet
92
+ if mock_root =~ /^epel-6/ then el_version = '6'
93
+ elsif mock_root =~ /^epel-7/ then el_version = '7'
94
+ else puts 'WARNING: Did not detect epel version'
95
+ end
96
+ tmp_dir = ''
97
+
98
+ if tmp_dir = ENV.fetch( 'SIMP_MOCK_SIMPGEM_ASSETS_DIR', false )
99
+ FileUtils.mkdir_p tmp_dir
100
+ else
101
+ tmp_dir = Dir.mktmpdir( "build_#{@package}" )
102
+ end
103
+
104
+ begin
105
+ Dir.chdir tmp_dir
106
+ specfile = "#{@rakefile_dir}/build/rubygem-#{@package}.el#{el_version}.spec"
107
+ tmp_specfile = "#{tmp_dir}/rubygem-#{@package}.el#{el_version}.spec"
108
+
109
+ # We have to copy to a local directory because mock bugs out in NFS
110
+ # home directories (where SIMP devs often work)
111
+ FileUtils.cp specfile, tmp_specfile, :preserve => true
112
+ Dir.glob("#{@rakefile_dir}/dist/#{@package}*.gem") do |pkg|
113
+ FileUtils.cp pkg, tmp_dir, :preserve => true
114
+ end
115
+
116
+ # Build SRPM from specfile
117
+ sh %Q{mock -r #{mock_root} --buildsrpm --source="#{tmp_dir}" --spec="#{tmp_specfile}" --resultdir="#{tmp_dir}"}
118
+
119
+ # Build RPM from SRPM
120
+ Dir.glob("#{tmp_dir}/rubygem-#{@package}-*.el#{el_version}*.src.rpm") do |pkg|
121
+ sh %Q{mock -r #{mock_root} --rebuild "#{pkg}" --resultdir=#{tmp_dir} --no-cleanup-after}
122
+ end
123
+
124
+ sh %Q{ls -l "#{tmp_dir}"}
125
+
126
+ # copy RPM back into pkg/
127
+ Dir.glob("#{tmp_dir}/rubygem-#{@package}-*.el#{el_version}*.rpm") do |pkg|
128
+ sh %Q{cp "#{pkg}" "#{@rakefile_dir}/dist/"}
129
+ FileUtils.cp pkg, "#{@rakefile_dir}/dist/"
130
+ end
131
+ ensure
132
+ Dir.chdir @rakefile_dir
133
+ # cleanup if needed
134
+ if ! ENV.fetch( 'SIMP_MOCK_SIMPGEM_ASSETS_DIR', false )
135
+ FileUtils.remove_entry_secure tmp_dir
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ # vim: syntax=ruby
@@ -0,0 +1 @@
1
+ rm -rf working demoCA keydist cacertkey ca.cnf
@@ -0,0 +1,58 @@
1
+ DAYS="-days 365"
2
+ REQ="openssl req $SSLEAY_CONFIG"
3
+ CA="openssl ca $SSLEAY_CONFIG -config ca.cnf"
4
+ VERIFY="openssl verify"
5
+ X509="openssl x509"
6
+
7
+ CATOP=./demoCA
8
+ CAKEY=./cakey.pem
9
+ CACERT=./cacert.pem
10
+ CASERIAL=`uuidgen | cut -f1 -d'-'`
11
+
12
+
13
+ keydist=keydist
14
+
15
+ # start clean
16
+ bash clean.sh
17
+
18
+ mkdir -p working "${keydist}" "${keydist}/cacerts"
19
+
20
+ # Create new CA
21
+ # ------------------------------------------------------------------------------
22
+ dd if=/dev/urandom status=none bs=60 count=1 | openssl base64 -e -nopad | tr -d '\n' > cacertkey
23
+ echo '' >> cacertkey
24
+ mkdir ${CATOP}
25
+ mkdir ${CATOP}/certs
26
+ mkdir ${CATOP}/crl
27
+ mkdir ${CATOP}/newcerts
28
+ mkdir ${CATOP}/private
29
+ echo "01" > ${CATOP}/serial
30
+ touch ${CATOP}/index.txt
31
+
32
+ echo "== Making CA certificate ..."
33
+ sed "s/^\([[:space:]]*commonName_default\).*/\1 \t\t= Fake Org Fake CA - ${CASERIAL}/" template_ca.cnf > ca.cnf
34
+
35
+ $REQ -verbose -batch -passout file:cacertkey -new -x509 -keyout ${CATOP}/private/$CAKEY -out ${CATOP}/$CACERT $DAYS
36
+
37
+ echo "== Making Client certificates ..."
38
+ for hname in $*; do
39
+ echo "-- $hname"
40
+ mkdir -p "${keydist}/${hname}/cacerts"
41
+ sed -e "s/#HOSTNAME#/$hname/" template_host.cnf > "working/${hname}.cnf"
42
+ echo "-- running openssl req"
43
+ $REQ -config "working/${hname}.cnf" -new -nodes -keyout ${keydist}/${hname}/${hname}.pem -out working/"${hname}"req.pem -days 360 -batch;
44
+ echo "-- running openssl ca"
45
+ $CA -passin file:cacertkey -batch -out ${keydist}/${hname}/${hname}.pub -infiles working/"${hname}"req.pem
46
+ cat ${keydist}/${hname}/${hname}.pub >> ${keydist}/${hname}/${hname}.pem
47
+ done
48
+
49
+ echo "== Hashing CA certs"
50
+ cacerts="${keydist}/cacerts"
51
+ hash=`openssl x509 -in ${CATOP}/${CACERT} -hash -noout`;
52
+ cp ${CATOP}/${CACERT} $cacerts/cacert_${CASERIAL}.pem
53
+ cd $cacerts
54
+ ln -s cacert_${CASERIAL}.pem $hash.0
55
+ cd -
56
+
57
+ chmod -R u+rwX,g+rX,o-rwx $keydist
58
+ #chown -R root:puppet $keydist
@@ -0,0 +1,259 @@
1
+ #
2
+ # OpenSSL example configuration file.
3
+ # This is mostly being used for generation of certificate requests.
4
+ #
5
+
6
+ # This definition stops the following lines choking if HOME isn't
7
+ # defined.
8
+ HOME = .
9
+ RANDFILE = $ENV::HOME/.rnd
10
+
11
+ # Extra OBJECT IDENTIFIER info:
12
+ #oid_file = $ENV::HOME/.oid
13
+ oid_section = new_oids
14
+
15
+ # To use this configuration file with the "-extfile" option of the
16
+ # "openssl x509" utility, name here the section containing the
17
+ # X.509v3 extensions to use:
18
+ # extensions =
19
+ # (Alternatively, use a configuration file that has only
20
+ # X.509v3 extensions in its main [= default] section.)
21
+
22
+ [ new_oids ]
23
+
24
+ # We can add new OIDs in here for use by 'ca' and 'req'.
25
+ # Add a simple OID like this:
26
+ # testoid1=1.2.3.4
27
+ # Or use config file substitution like this:
28
+ # testoid2=${testoid1}.5.6
29
+
30
+ ####################################################################
31
+ [ ca ]
32
+ default_ca = CA_default # The default ca section
33
+
34
+ ####################################################################
35
+ [ CA_default ]
36
+
37
+ dir = ./demoCA # Where everything is kept
38
+ certs = $dir/certs # Where the issued certs are kept
39
+ crl_dir = $dir/crl # Where the issued crl are kept
40
+ database = $dir/index.txt # database index file.
41
+ new_certs_dir = $dir/newcerts # default place for new certs.
42
+
43
+ certificate = $dir/cacert.pem # The CA certificate
44
+ serial = $dir/serial # The current serial number
45
+ crl = $dir/crl.pem # The current CRL
46
+ private_key = $dir/private/cakey.pem# The private key
47
+ RANDFILE = $dir/private/.rand # private random number file
48
+
49
+ x509_extensions = usr_cert # The extentions to add to the cert
50
+
51
+ # Comment out the following two lines for the "traditional"
52
+ # (and highly broken) format.
53
+ name_opt = ca_default # Subject Name options
54
+ cert_opt = ca_default # Certificate field options
55
+
56
+ # Extension copying option: use with caution.
57
+ # copy_extensions = copy
58
+
59
+ # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
60
+ # so this is commented out by default to leave a V1 CRL.
61
+ # crl_extensions = crl_ext
62
+
63
+ default_days = 365 # how long to certify for
64
+ default_crl_days= 30 # how long before next CRL
65
+ default_md = sha256 # which md to use.
66
+ preserve = no # keep passed DN ordering
67
+
68
+ # A few difference way of specifying how similar the request should look
69
+ # For type CA, the listed attributes must be the same, and the optional
70
+ # and supplied fields are just that :-)
71
+ policy = policy_anything
72
+
73
+ # For the CA policy
74
+ [ policy_match ]
75
+ countryName = match
76
+ stateOrProvinceName = match
77
+ organizationName = match
78
+ organizationalUnitName = optional
79
+ commonName = supplied
80
+ emailAddress = optional
81
+
82
+ # For the 'anything' policy
83
+ # At this point in time, you must list all acceptable 'object'
84
+ # types.
85
+ [ policy_anything ]
86
+ countryName = optional
87
+ stateOrProvinceName = optional
88
+ localityName = optional
89
+ organizationName = optional
90
+ organizationalUnitName = optional
91
+ commonName = supplied
92
+ emailAddress = optional
93
+
94
+ ####################################################################
95
+ [ req ]
96
+ default_bits = 2048
97
+ default_keyfile = privkey.pem
98
+ distinguished_name = req_distinguished_name
99
+ attributes = req_attributes
100
+ x509_extensions = v3_ca # The extentions to add to the self signed cert
101
+
102
+ # Passwords for private keys if not present they will be prompted for
103
+ # input_password = secret
104
+ # output_password = secret
105
+
106
+ # This sets a mask for permitted string types. There are several options.
107
+ # default: PrintableString, T61String, BMPString.
108
+ # pkix : PrintableString, BMPString.
109
+ # utf8only: only UTF8Strings.
110
+ # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
111
+ # MASK:XXXX a literal mask value.
112
+ # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
113
+ # so use this option with caution!
114
+ string_mask = nombstr
115
+
116
+ # req_extensions = v3_req # The extensions to add to a certificate request
117
+
118
+ [ req_distinguished_name ]
119
+ countryName = Country Name (2 letter code)
120
+ countryName_default = ZZ
121
+ countryName_min = 2
122
+ countryName_max = 2
123
+
124
+ #stateOrProvinceName = State or Province Name (full name)
125
+ #stateOrProvinceName_default = Berkshire
126
+
127
+ #localityName = Locality Name (eg, city)
128
+ #localityName_default = Newbury
129
+
130
+ 0.organizationName = Organization Name (eg, company)
131
+ 0.organizationName_default = Fake Org
132
+
133
+ # we can do this but it is not needed normally :-)
134
+ #1.organizationName = Second Organization Name (eg, company)
135
+ #1.organizationName_default = World Wide Web Pty Ltd
136
+
137
+ organizationalUnitName = Organizational Unit Name (eg, section)
138
+ organizationalUnitName_default = Hosts
139
+
140
+ commonName = Common Name (eg, your name or your server\'s hostname)
141
+ commonName_max = 64
142
+ commonName_default = Fake Org Fake CA - #SERIAL#
143
+
144
+ #emailAddress = Email Address
145
+ #emailAddress_max = 64
146
+
147
+ # SET-ex3 = SET extension number 3
148
+
149
+ [ req_attributes ]
150
+ #challengePassword = A challenge password
151
+ #challengePassword_min = 4
152
+ #challengePassword_max = 20
153
+ #challengePassword_default = password
154
+
155
+ unstructuredName = An optional company name
156
+
157
+ [ usr_cert ]
158
+
159
+ # These extensions are added when 'ca' signs a request.
160
+
161
+ # This goes against PKIX guidelines but some CAs do it and some software
162
+ # requires this to avoid interpreting an end user certificate as a CA.
163
+
164
+ basicConstraints=CA:FALSE
165
+
166
+ # Here are some examples of the usage of nsCertType. If it is omitted
167
+ # the certificate can be used for anything *except* object signing.
168
+
169
+ # This is OK for an SSL server.
170
+ # nsCertType = server
171
+
172
+ # For an object signing certificate this would be used.
173
+ # nsCertType = objsign
174
+
175
+ # For normal client use this is typical
176
+ # nsCertType = client, email
177
+
178
+ # and for everything including object signing:
179
+ # nsCertType = client, email, objsign
180
+
181
+ # This is typical in keyUsage for a client certificate.
182
+ # keyUsage = nonRepudiation, digitalSignature, keyEncipherment
183
+
184
+ # This will be displayed in Netscape's comment listbox.
185
+ nsComment = "Completely Fake Certificate"
186
+
187
+ # PKIX recommendations harmless if included in all certificates.
188
+ subjectKeyIdentifier=hash
189
+ authorityKeyIdentifier=keyid,issuer:always
190
+
191
+ # This stuff is for subjectAltName and issuerAltname.
192
+ # Import the email address.
193
+ subjectAltName=email:copy
194
+ # An alternative to produce certificates that aren't
195
+ # deprecated according to PKIX.
196
+ # subjectAltName=email:move
197
+
198
+ # Copy subject details
199
+ # issuerAltName=issuer:copy
200
+
201
+ #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
202
+ #nsBaseUrl
203
+ #nsRevocationUrl
204
+ #nsRenewalUrl
205
+ #nsCaPolicyUrl
206
+ #nsSslServerName
207
+
208
+ [ v3_req ]
209
+
210
+ # Extensions to add to a certificate request
211
+
212
+ basicConstraints = CA:FALSE
213
+ #keyUsage = nonRepudiation, digitalSignature, keyEncipherment
214
+ keyUsage = keyEncipherment
215
+
216
+ [ v3_ca ]
217
+
218
+
219
+ # Extensions for a typical CA
220
+
221
+
222
+ # PKIX recommendation.
223
+
224
+ subjectKeyIdentifier=hash
225
+
226
+ authorityKeyIdentifier=keyid:always,issuer:always
227
+
228
+ # This is what PKIX recommends but some broken software chokes on critical
229
+ # extensions.
230
+ #basicConstraints = critical,CA:true
231
+ # So we do this instead.
232
+ basicConstraints = CA:true
233
+
234
+ # Key usage: this is typical for a CA certificate. However since it will
235
+ # prevent it being used as an test self-signed certificate it is best
236
+ # left out by default.
237
+ # keyUsage = cRLSign, keyCertSign
238
+
239
+ # Some might want this also
240
+ # nsCertType = sslCA, emailCA
241
+
242
+ # Include email address in subject alt name: another PKIX recommendation
243
+ # subjectAltName=email:copy
244
+ # Copy issuer details
245
+ # issuerAltName=issuer:copy
246
+
247
+ # DER hex encoding of an extension: beware experts only!
248
+ # obj=DER:02:03
249
+ # Where 'obj' is a standard or added object
250
+ # You can even override a supported extension:
251
+ # basicConstraints= critical, DER:30:03:01:01:FF
252
+
253
+ [ crl_ext ]
254
+
255
+ # CRL extensions.
256
+ # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
257
+
258
+ # issuerAltName=issuer:copy
259
+ authorityKeyIdentifier=keyid:always,issuer:always
@@ -0,0 +1,262 @@
1
+ #
2
+ # OpenSSL example configuration file.
3
+ # This is mostly being used for generation of certificate requests.
4
+ #
5
+
6
+ # This definition stops the following lines choking if HOME isn't
7
+ # defined.
8
+ HOME = .
9
+ RANDFILE = $ENV::HOME/.rnd
10
+
11
+ # Extra OBJECT IDENTIFIER info:
12
+ #oid_file = $ENV::HOME/.oid
13
+ oid_section = new_oids
14
+
15
+ # To use this configuration file with the "-extfile" option of the
16
+ # "openssl x509" utility, name here the section containing the
17
+ # X.509v3 extensions to use:
18
+ # extensions =
19
+ # (Alternatively, use a configuration file that has only
20
+ # X.509v3 extensions in its main [= default] section.)
21
+
22
+ [ new_oids ]
23
+
24
+ # We can add new OIDs in here for use by 'ca' and 'req'.
25
+ # Add a simple OID like this:
26
+ # testoid1=1.2.3.4
27
+ # Or use config file substitution like this:
28
+ # testoid2=${testoid1}.5.6
29
+
30
+ ####################################################################
31
+ [ ca ]
32
+ default_ca = CA_default # The default ca section
33
+
34
+ ####################################################################
35
+ [ CA_default ]
36
+
37
+ dir = ./demoCA # Where everything is kept
38
+ certs = $dir/certs # Where the issued certs are kept
39
+ crl_dir = $dir/crl # Where the issued crl are kept
40
+ database = $dir/index.txt # database index file.
41
+ new_certs_dir = $dir/newcerts # default place for new certs.
42
+
43
+ certificate = $dir/cacert.pem # The CA certificate
44
+ serial = $dir/serial # The current serial number
45
+ crl = $dir/crl.pem # The current CRL
46
+ private_key = $dir/private/cakey.pem# The private key
47
+ RANDFILE = $dir/private/.rand # private random number file
48
+
49
+ x509_extensions = usr_cert # The extentions to add to the cert
50
+
51
+ input_password = test
52
+ output_password = test
53
+
54
+ # Comment out the following two lines for the "traditional"
55
+ # (and highly broken) format.
56
+ name_opt = ca_default # Subject Name options
57
+ cert_opt = ca_default # Certificate field options
58
+
59
+ # Extension copying option: use with caution.
60
+ # copy_extensions = copy
61
+
62
+ # Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
63
+ # so this is commented out by default to leave a V1 CRL.
64
+ # crl_extensions = crl_ext
65
+
66
+ default_days = 365 # how long to certify for
67
+ default_crl_days= 30 # how long before next CRL
68
+ default_md = sha256 # which md to use.
69
+ preserve = no # keep passed DN ordering
70
+
71
+ # A few difference way of specifying how similar the request should look
72
+ # For type CA, the listed attributes must be the same, and the optional
73
+ # and supplied fields are just that :-)
74
+ policy = policy_anything
75
+
76
+ # For the CA policy
77
+ [ policy_match ]
78
+ countryName = match
79
+ stateOrProvinceName = match
80
+ organizationName = match
81
+ organizationalUnitName = optional
82
+ commonName = supplied
83
+ emailAddress = optional
84
+
85
+ # For the 'anything' policy
86
+ # At this point in time, you must list all acceptable 'object'
87
+ # types.
88
+ [ policy_anything ]
89
+ countryName = optional
90
+ stateOrProvinceName = optional
91
+ localityName = optional
92
+ organizationName = optional
93
+ organizationalUnitName = optional
94
+ commonName = supplied
95
+ emailAddress = optional
96
+
97
+ ####################################################################
98
+ [ req ]
99
+ default_bits = 2048
100
+ default_keyfile = privkey.pem
101
+ distinguished_name = req_distinguished_name
102
+ attributes = req_attributes
103
+ x509_extensions = v3_ca # The extentions to add to the self signed cert
104
+
105
+ # Passwords for private keys if not present they will be prompted for
106
+ # input_password = secret
107
+ # output_password = secret
108
+
109
+ # This sets a mask for permitted string types. There are several options.
110
+ # default: PrintableString, T61String, BMPString.
111
+ # pkix : PrintableString, BMPString.
112
+ # utf8only: only UTF8Strings.
113
+ # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
114
+ # MASK:XXXX a literal mask value.
115
+ # WARNING: current versions of Netscape crash on BMPStrings or UTF8Strings
116
+ # so use this option with caution!
117
+ string_mask = nombstr
118
+
119
+ # req_extensions = v3_req # The extensions to add to a certificate request
120
+
121
+ [ req_distinguished_name ]
122
+ countryName = Country Name (2 letter code)
123
+ countryName_default = ZZ
124
+ countryName_min = 2
125
+ countryName_max = 2
126
+
127
+ #stateOrProvinceName = State or Province Name (full name)
128
+ #stateOrProvinceName_default = Berkshire
129
+
130
+ #localityName = Locality Name (eg, city)
131
+ #localityName_default = Newbury
132
+
133
+ 0.organizationName = Organization Name (eg, company)
134
+ 0.organizationName_default = Fake Org
135
+
136
+ # we can do this but it is not needed normally :-)
137
+ #1.organizationName = Second Organization Name (eg, company)
138
+ #1.organizationName_default = World Wide Web Pty Ltd
139
+
140
+ organizationalUnitName = Organizational Unit Name (eg, section)
141
+ organizationalUnitName_default = Hosts
142
+
143
+ commonName = Common Name (eg, your name or your server\'s hostname)
144
+ commonName_max = 64
145
+ commonName_default = #HOSTNAME#
146
+
147
+ #emailAddress = Email Address
148
+ #emailAddress_max = 64
149
+
150
+ # SET-ex3 = SET extension number 3
151
+
152
+ [ req_attributes ]
153
+ #challengePassword = A challenge password
154
+ #challengePassword_min = 4
155
+ #challengePassword_max = 20
156
+ #challengePassword_default = password
157
+
158
+ unstructuredName = Fake Cert
159
+
160
+ [ usr_cert ]
161
+
162
+ # These extensions are added when 'ca' signs a request.
163
+
164
+ # This goes against PKIX guidelines but some CAs do it and some software
165
+ # requires this to avoid interpreting an end user certificate as a CA.
166
+
167
+ basicConstraints=CA:FALSE
168
+
169
+ # Here are some examples of the usage of nsCertType. If it is omitted
170
+ # the certificate can be used for anything *except* object signing.
171
+
172
+ # This is OK for an SSL server.
173
+ #nsCertType = server
174
+
175
+ # For an object signing certificate this would be used.
176
+ # nsCertType = objsign
177
+
178
+ # For normal client use this is typical
179
+ # nsCertType = client, email
180
+ # nsCertType = client
181
+
182
+ # and for everything including object signing:
183
+ nsCertType = server, client, email, objsign
184
+
185
+ # This is typical in keyUsage for a client certificate.
186
+ keyUsage = nonRepudiation, digitalSignature, keyEncipherment
187
+
188
+ # This will be displayed in Netscape's comment listbox.
189
+ #nsComment = "Test Certificate"
190
+
191
+ # PKIX recommendations harmless if included in all certificates.
192
+ subjectKeyIdentifier=hash
193
+ authorityKeyIdentifier=keyid,issuer:always
194
+
195
+ # This stuff is for subjectAltName and issuerAltname.
196
+ # Import the email address.
197
+ # subjectAltName=email:copy
198
+ # An alternative to produce certificates that aren't
199
+ # deprecated according to PKIX.
200
+ # subjectAltName=email:move
201
+
202
+ # Copy subject details
203
+ # issuerAltName=issuer:copy
204
+
205
+ #nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
206
+ #nsBaseUrl
207
+ #nsRevocationUrl
208
+ #nsRenewalUrl
209
+ #nsCaPolicyUrl
210
+ #nsSslServerName
211
+
212
+ [ v3_req ]
213
+
214
+ # Extensions to add to a certificate request
215
+
216
+ basicConstraints = CA:FALSE
217
+ keyUsage = nonRepudiation, digitalSignature, keyEncipherment
218
+
219
+ [ v3_ca ]
220
+
221
+
222
+ # Extensions for a typical CA
223
+
224
+
225
+ # PKIX recommendation.
226
+
227
+ subjectKeyIdentifier=hash
228
+
229
+ authorityKeyIdentifier=keyid:always,issuer:always
230
+
231
+ # This is what PKIX recommends but some broken software chokes on critical
232
+ # extensions.
233
+ #basicConstraints = critical,CA:true
234
+ # So we do this instead.
235
+ basicConstraints = CA:true
236
+
237
+ # Key usage: this is typical for a CA certificate. However since it will
238
+ # prevent it being used as an test self-signed certificate it is best
239
+ # left out by default.
240
+ # keyUsage = cRLSign, keyCertSign
241
+
242
+ # Some might want this also
243
+ # nsCertType = sslCA, emailCA
244
+
245
+ # Include email address in subject alt name: another PKIX recommendation
246
+ # subjectAltName=email:copy
247
+ # Copy issuer details
248
+ # issuerAltName=issuer:copy
249
+
250
+ # DER hex encoding of an extension: beware experts only!
251
+ # obj=DER:02:03
252
+ # Where 'obj' is a standard or added object
253
+ # You can even override a supported extension:
254
+ # basicConstraints= critical, DER:30:03:01:01:FF
255
+
256
+ [ crl_ext ]
257
+
258
+ # CRL extensions.
259
+ # Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
260
+
261
+ # issuerAltName=issuer:copy
262
+ authorityKeyIdentifier=keyid:always,issuer:always
@@ -0,0 +1,146 @@
1
+ module Simp; end
2
+
3
+ module Simp::BeakerHelpers
4
+ VERSION = '1.0.0'
5
+
6
+ # Locates .fixture.yml in or above this directory.
7
+ def fixtures_yml_path
8
+ fixtures_yml = ''
9
+ dir = '.'
10
+ while( fixtures_yml.empty? && File.expand_path(dir) != '/' ) do
11
+ file = File.expand_path( '.fixtures.yml', dir )
12
+ if File.exists? file
13
+ fixtures_yml = file
14
+ break
15
+ end
16
+ end
17
+ raise 'ERROR: cannot locate .fixtures.yml!' if fixtures_yml.empty?
18
+ fixtures_yml
19
+ end
20
+
21
+
22
+ # returns an Array of puppet modules declared in .fixtures.yml
23
+ def pupmods_in_fixtures_yml
24
+ fixtures_yml = fixtures_yml_path
25
+ data = YAML.load_file( fixtures_yml )
26
+ repos = data.fetch('fixtures').fetch('repositories', {}).keys || []
27
+ symlinks = data.fetch('fixtures').fetch('symlinks', {}).keys || []
28
+ (repos + symlinks)
29
+ end
30
+
31
+
32
+ # Ensures that the fixture modules (under `spec/fixtures/modules`) exists.
33
+ # if any fixture modules are missing, run 'rake spec_prep' to populate the
34
+ # fixtures/modules
35
+ def ensure_fixture_modules
36
+ unless ENV['BEAKER_spec_prep'] == 'no'
37
+ puts "== checking prepped modules from .fixtures.yml"
38
+ missing_modules = []
39
+ pupmods_in_fixtures_yml.each do |pupmod|
40
+ mod_root = File.expand_path( "spec/fixtures/modules/#{pupmod}", File.dirname( fixtures_yml_path ))
41
+ missing_modules << pupmod unless File.directory? mod_root
42
+ end
43
+ puts " -- #{missing_modules.size} modules need to be prepped"
44
+ unless missing_modules.empty?
45
+ cmd = 'bundle exec rake spec_prep'
46
+ puts " -- running spec_prep: '#{cmd}'"
47
+ %x(#{cmd})
48
+ else
49
+ puts " == all fixture modules present"
50
+ end
51
+ end
52
+ end
53
+
54
+ # Copy the local fixture modules (under `spec/fixtures/modules`) onto each SUT
55
+ def copy_fixture_modules_to( suts = hosts )
56
+ ensure_fixture_modules
57
+ suts.each do |sut|
58
+ # allow spec_prep to provide modules (to support isolated networks)
59
+ unless ENV['BEAKER_use_fixtures_dir_for_modules'] == 'no'
60
+ pupmods_in_fixtures_yml.each do |pupmod|
61
+ mod_root = File.expand_path( "spec/fixtures/modules/#{pupmod}", File.dirname( fixtures_yml_path ))
62
+ copy_module_to( sut, {:source => mod_root, :module_name => pupmod} )
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+
69
+ # Apply known OS fixes we need to run Beaker on each SUT
70
+ def fix_errata_on( suts = hosts )
71
+ suts.each do |sut|
72
+ # net-tools required for netstat utility being used by be_listening
73
+ if fact_on(sut, 'osfamily') == 'RedHat' && fact_on(sut, 'operatingsystemmajrelease') == '7'
74
+ pp = <<-EOS
75
+ package { 'net-tools': ensure => installed }
76
+ EOS
77
+ apply_manifest_on(sut, pp, :catch_failures => false)
78
+ end
79
+ end
80
+ end
81
+
82
+
83
+ # Generate a fake openssl CA + certs for each host on a given SUT
84
+ #
85
+ # The directory structure is the same as what FakeCA drops into keydist/
86
+ #
87
+ # NOTE: This generates everything within an SUT and copies it back out.
88
+ # This is because it is assumed the SUT will have the appropriate
89
+ # openssl in its environment, which may not be true of the host.
90
+ def run_fake_pki_ca_on( ca_sut = master, suts = hosts, local_dir = '' )
91
+ puts "== Fake PKI CA"
92
+ pki_dir = File.expand_path( "../../files/pki", File.dirname(__FILE__))
93
+ host_dir = '/root/pki'
94
+ fqdns = fact_on hosts, 'fqdn'
95
+
96
+ on ca_sut, %Q(mkdir -p "#{host_dir}")
97
+ Dir[ File.join(pki_dir, '*')].each {|f| scp_to( ca_sut, f, host_dir)}
98
+
99
+ # generate PKI certs for each SUT
100
+ Dir.mktmpdir do |dir|
101
+ pki_hosts_file = File.join(dir, 'pki.hosts')
102
+ File.open(pki_hosts_file, 'w'){|fh| fqdns.each{|fqdn| fh.puts fqdn}}
103
+ scp_to(ca_sut, pki_hosts_file, host_dir)
104
+ # generate certs
105
+ on ca_sut, "cd #{host_dir}; cat #{host_dir}/pki.hosts | xargs bash make.sh"
106
+ end
107
+
108
+ scp_from( ca_sut, host_dir, local_dir ) unless local_dir.empty?
109
+ end
110
+
111
+
112
+ # Copy a single SUT's PKI certs (with cacerts) onto an SUT.
113
+ #
114
+ # This simulates the result of pki::copy
115
+ #
116
+ # The directory structure is:
117
+ #
118
+ # HOST_PKI_DIR/
119
+ # cacerts/cacert.pem
120
+ # public/fdqn.pub
121
+ # private/fdqn.pem
122
+ def copy_pki_to(sut, local_pki_dir, sut_pki_dir = '/etc/pki/simp-testing')
123
+ fqdn = fact_on(sut, 'fqdn')
124
+ local_host_pki_tree = File.join(local_pki_dir,'pki','keydist',fqdn)
125
+ ###local_cacert_pki_tree = File.join(local_pki_dir,'pki','keydist','cacerts')
126
+ local_cacert = File.join(local_pki_dir,'pki','demoCA','cacert.pem')
127
+ on sut, %Q(mkdir -p "#{sut_pki_dir}/public" "#{sut_pki_dir}/private" "#{sut_pki_dir}/cacerts")
128
+ scp_to(sut, "#{local_host_pki_tree}/#{fqdn}.pem", "#{sut_pki_dir}/private/")
129
+ scp_to(sut, "#{local_host_pki_tree}/#{fqdn}.pub", "#{sut_pki_dir}/public/")
130
+ ###scp_to(sut, local_cacert_pki_tree, sut_pki_dir)
131
+ scp_to(sut, local_cacert, "#{sut_pki_dir}/cacerts/")
132
+ end
133
+
134
+
135
+ # Copy a CA keydist/ directory of CA+host certs into an SUT
136
+ #
137
+ # This simulates the output of FakeCA's gencerts_nopass.sh to keydist/
138
+ #
139
+ # FIXME: update keydist to use a more flexible path
140
+ def copy_keydist_to( ca_sut = master )
141
+ modulepath = on(ca_sut, 'puppet config print modulepath --environment production' ).output.chomp.split(':')
142
+ on ca_sut, "rm -rf #{modulepath.first}/pki/files/keydist/*"
143
+ on ca_sut, "cp -a /root/pki/keydist/ #{modulepath.first}/pki/files/"
144
+ on ca_sut, "chgrp -R puppet #{modulepath.first}/pki/files/keydist"
145
+ end
146
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
+ require 'simp/beaker_helpers.rb'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'simp-beaker-helpers'
7
+ s.date = Date.today.to_s
8
+ s.summary = 'beaker helper methods for SIMP'
9
+ s.description = <<-EOF
10
+ Beaker helper methods to stick in spec_acceptance_helper.rb
11
+ EOF
12
+ s.version = Simp::BeakerHelpers::VERSION
13
+ s.license = 'Apache-2.0'
14
+ s.authors = ['Chris Tessmer']
15
+ s.email = 'simp@simp-project.org'
16
+ s.homepage = 'https://github.com/simp/rubygem-simp-beaker-helpers'
17
+ s.metadata = {
18
+ 'issue_tracker' => 'https://simp-project.atlassian.net'
19
+ }
20
+
21
+ s.add_runtime_dependency 'beaker', '~> 2'
22
+
23
+ ### s.files = Dir['Rakefile', '{bin,lib,spec}/**/*', 'README*', 'LICENSE*'] & `git ls-files -z .`.split("\0")
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simp-beaker-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Tessmer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: beaker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ description: ! ' Beaker helper methods to stick in spec_acceptance_helper.rb
28
+
29
+ '
30
+ email: simp@simp-project.org
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - .travis.yml
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - files/pki/clean.sh
42
+ - files/pki/make.sh
43
+ - files/pki/template_ca.cnf
44
+ - files/pki/template_host.cnf
45
+ - lib/simp/beaker_helpers.rb
46
+ - simp-beaker-helpers.gemspec
47
+ homepage: https://github.com/simp/rubygem-simp-beaker-helpers
48
+ licenses:
49
+ - Apache-2.0
50
+ metadata:
51
+ issue_tracker: https://simp-project.atlassian.net
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.4.8
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: beaker helper methods for SIMP
72
+ test_files: []