From ded917c4b9226a6708c60a84c9d0bc40a1615f3c Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:17:17 +0200 Subject: [PATCH 1/7] autobanner + description --- CHANGELOG.md | 5 ++++ lib/facter/eypconf_description.rb | 14 +++++++++++ manifests/autobanner.pp | 14 +++++++++++ manifests/setdescription.pp | 14 +++++++++++ metadata.json | 2 +- templates/autobanner.erb | 41 +++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 lib/facter/eypconf_description.rb create mode 100644 manifests/autobanner.pp create mode 100644 manifests/setdescription.pp create mode 100644 templates/autobanner.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ae9e1..f1fbc66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.1.18 + +* added fact **eypconf_description** +* added **eyplib::autobanner** intended for generating a SSH banner file + ## 0.1.17 * renamed unused facts diff --git a/lib/facter/eypconf_description.rb b/lib/facter/eypconf_description.rb new file mode 100644 index 0000000..a2a5fab --- /dev/null +++ b/lib/facter/eypconf_description.rb @@ -0,0 +1,14 @@ +if File.exists?('/opt/eypconf/id/description.sh') then + description = Facter::Util::Resolution.exec('bash /opt/eypconf/id/description.sh').to_s +else + description = Facter::Util::Resolution.exec('bash -c \'if [ -f /opt/eypconf/id/description ]; then cat /opt/eypconf/id/description | paste -sd,; fi\'').to_s +end + +unless description.nil? or description.empty? + Facter.add('eypconf_description') do + setcode do + description + end + end + +end diff --git a/manifests/autobanner.pp b/manifests/autobanner.pp new file mode 100644 index 0000000..60b4ea0 --- /dev/null +++ b/manifests/autobanner.pp @@ -0,0 +1,14 @@ +class eyplib::autobanner( + $autobanner_file = '/opt/eypconf/autobanner', + $include_legal = false, + $include_description = true, + $include_puppet_managed_server = true, + ) { + file { $autobanner_file: + ensure => 'present', + owner => 'root', + group => 'root', + mode => '0644', + content => template("${module_name}/autobanner.erb"), + } +} diff --git a/manifests/setdescription.pp b/manifests/setdescription.pp new file mode 100644 index 0000000..34cd46b --- /dev/null +++ b/manifests/setdescription.pp @@ -0,0 +1,14 @@ +class eyplib::setdescription( + $description = undef + ) { + if($description!=undef) + { + file { '/opt/eypconf/id/description': + ensure => 'present', + owner => 'root', + group => 'root', + mode => '0644', + content => $description, + } + } +} diff --git a/metadata.json b/metadata.json index bc3f9e9..d120a53 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-eyplib", - "version": "0.1.17", + "version": "0.1.18", "author": "eyp", "summary": "Utility functions for puppet modules", "license": "Apache-2.0", diff --git a/templates/autobanner.erb b/templates/autobanner.erb new file mode 100644 index 0000000..f694056 --- /dev/null +++ b/templates/autobanner.erb @@ -0,0 +1,41 @@ +<% if @include_legal -%> +******************************************************************************** + NOTICE +******************************************************************************** + +This is a private system!!! All connection attempts are logged and +monitored. All unauthorized connection attempts will be investigated and +handed over to the proper authorities. + +Users (authorized or unauthorized) have no explicit or implicit +expectation of privacy. + +Any or all uses of this system and all files on this system may be +intercepted, monitored, recorded, copied, audited, inspected, and +disclosed (included but not limited) to your employer, to authorized site, +government, and law enforcement personnel, as well as authorized +officials of government agencies, both domestic and foreign. + +By using this system, the user consents to such interception, monitoring, +recording, copying, auditing, inspection, and disclosure at the +discretion of such personnel or officials. Unauthorized or improper use +of this system may result in civil and criminal penalties and +administrative or disciplinary action, as appropriate. By continuing to +use this system you indicate your awareness of and consent to these terms +and conditions of use. LOG OFF IMMEDIATELY if you do not agree to the +conditions stated in this warning. + + +******************************************************************************** +<% end -%> +<% if @include_description -%> +<% if scope.lookupvar('::eypconf_description') -%> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + <%= scope.lookupvar('::eypconf_description') %> +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +<% end -%> +<% end -%> +<% if @include_puppet_managed -%> + * puppet managed server +<% end -%> +******************************************************************************** From 8f38cb82be7f1e65655f333ecd8f38335cfb3d56 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:20:05 +0200 Subject: [PATCH 2/7] some acceptance testing --- spec/acceptance/base_spec.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/acceptance/base_spec.rb b/spec/acceptance/base_spec.rb index 4c8d81b..591451f 100644 --- a/spec/acceptance/base_spec.rb +++ b/spec/acceptance/base_spec.rb @@ -10,12 +10,28 @@ class { 'eyplib': } + -> + + class { 'eyplib::setdescription': + description => 'ACCEPTANCE TESTING', + } + + -> + + class { 'eyplib::autobanner': } + EOF - # Run it twice and test for idempotency + # run several times - expect the 3rd run to be clean + expect(apply_manifest(pp).exit_code).to_not eq(1) expect(apply_manifest(pp).exit_code).to_not eq(1) expect(apply_manifest(pp).exit_code).to eq(0) end + describe file('/opt/eypconf/autobanner') do + it { should be_file } + its(:content) { should match 'ACCEPTANCE TESTING' } + end + end end From 15bb70eb9453ecb02757d718af1d397dd89d6603 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:22:40 +0200 Subject: [PATCH 3/7] testing legal stuff --- spec/acceptance/base_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/acceptance/base_spec.rb b/spec/acceptance/base_spec.rb index 591451f..fe251a5 100644 --- a/spec/acceptance/base_spec.rb +++ b/spec/acceptance/base_spec.rb @@ -32,6 +32,38 @@ class { 'eyplib::autobanner': } it { should be_file } its(:content) { should match 'ACCEPTANCE TESTING' } end + end + context 'legal setup' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOF + + class { 'eyplib': } + + -> + + class { 'eyplib::setdescription': + description => 'ACCEPTANCE TESTING', + } + + -> + class { 'eyplib::autobanner': + include_legal => true, + } + + EOF + + # run several times - expect the 3rd run to be clean + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to_not eq(1) + expect(apply_manifest(pp).exit_code).to eq(0) + end + + describe file('/opt/eypconf/autobanner') do + it { should be_file } + its(:content) { should match 'ACCEPTANCE TESTING' } + its(:content) { should match 'This is a private system!!! All connection attempts are logged and' } + end end end From 4bd0d230f7471916053c6c0fd48b60f2f2c15747 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:34:09 +0200 Subject: [PATCH 4/7] mkdir /opt/eypconf/id --- manifests/init.pp | 6 +++++- manifests/setdescription.pp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 62e9173..ce6c7d9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -3,5 +3,9 @@ # === eyplib documentation # class eyplib { - # nothing to do here + exec { 'mkdir -p /opt/eypconf/id': + command => 'mkdir -p /opt/eypconf/id', + path => '/usr/sbin:/usr/bin:/sbin:/bin', + creates => '/opt/eypconf/id', + } } diff --git a/manifests/setdescription.pp b/manifests/setdescription.pp index 34cd46b..69f0bab 100644 --- a/manifests/setdescription.pp +++ b/manifests/setdescription.pp @@ -1,6 +1,8 @@ class eyplib::setdescription( $description = undef ) { + include ::eyplib + if($description!=undef) { file { '/opt/eypconf/id/description': @@ -9,6 +11,7 @@ group => 'root', mode => '0644', content => $description, + require => Class['::eyplib'], } } } From 7db07ff7284449e79be3747d87c9a68b61ab57f5 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:44:57 +0200 Subject: [PATCH 5/7] estil --- templates/autobanner.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/autobanner.erb b/templates/autobanner.erb index f694056..3773560 100644 --- a/templates/autobanner.erb +++ b/templates/autobanner.erb @@ -30,12 +30,15 @@ conditions stated in this warning. <% end -%> <% if @include_description -%> <% if scope.lookupvar('::eypconf_description') -%> + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <%= scope.lookupvar('::eypconf_description') %> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <% end -%> <% end -%> <% if @include_puppet_managed -%> - * puppet managed server + + ******************************************************************************** + puppet managed server + ******************************************************************************** <% end -%> -******************************************************************************** From 8835a66c1655dcf59a499c0e1ce47b5991c0b1ec Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:45:12 +0200 Subject: [PATCH 6/7] estil --- templates/autobanner.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/autobanner.erb b/templates/autobanner.erb index 3773560..e0bd545 100644 --- a/templates/autobanner.erb +++ b/templates/autobanner.erb @@ -32,7 +32,7 @@ conditions stated in this warning. <% if scope.lookupvar('::eypconf_description') -%> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - <%= scope.lookupvar('::eypconf_description') %> + <%= scope.lookupvar('::eypconf_description') %> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% <% end -%> <% end -%> From 2acfc9189e5c57291a971e06b65ca1ec2beeb23c Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 5 Aug 2019 13:52:07 +0200 Subject: [PATCH 7/7] setdescription --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1fbc66..d3030a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.1.18 * added fact **eypconf_description** +* added **eyplib::setdescription** fet setting **eypconf_description** * added **eyplib::autobanner** intended for generating a SSH banner file ## 0.1.17