Skip to content

Commit 10f70d2

Browse files
committed
rot13 Chef cookbook, please don't use this for reals...
0 parents  commit 10f70d2

File tree

22 files changed

+443
-0
lines changed

22 files changed

+443
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Gemfile.lock
2+
Cheffile.lock
3+
.librarian/
4+
tmp/
5+
.kitchen/
6+
.kitchen.local.yml
7+
.bundle/

.kitchen.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
driver:
3+
name: docker
4+
socket: <%= ENV['DOCKER_HOST'] %>
5+
6+
kitchen:
7+
test_base_path: spec/integration
8+
9+
provisioner:
10+
name: chef_solo
11+
12+
platforms:
13+
- name: ubuntu-12.04
14+
- name: centos-6.4
15+
16+
suites:
17+
- name: default
18+
run_list:
19+
- recipe[test]

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: ruby
2+
rvm:
3+
- 2.1
4+
bundler_args: --without integration development

Cheffile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env ruby
2+
#^syntax detection
3+
4+
site "http://community.opscode.com/api/v1"
5+
6+
cookbook "rot13", path: "."
7+
cookbook "fixtures", path: "spec/unit/fixtures"
8+
cookbook "test", path: "spec/integration/cookbooks/test"

Gemfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
source "https://rubygems.org"
2+
3+
gem "chefspec"
4+
gem "emeril"
5+
gem "foodcritic", "~> 3.0"
6+
gem "librarian-chef"
7+
8+
group :development do
9+
gem "guard-rspec"
10+
end
11+
12+
group :integration do
13+
gem "test-kitchen"
14+
gem "kitchen-docker"
15+
end

Guardfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
guard :rspec do
2+
watch(%r{^spec/unit/.+_spec\.rb$})
3+
watch(%r{^(libraries|providers|recipes|resources)/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}/#{m[2]}_spec.rb" }
4+
watch("spec/unit/spec_helper.rb") { "spec/unit" }
5+
end

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# <a name="title"></a> Rot13 Chef Cookbook
2+
3+
[![Build Status](https://secure.travis-ci.org/ut-cookbooks/rot13.png?branch=master)](http://travis-ci.org/ut-cookbooks/rot13)
4+
5+
## <a name="description"></a> Description
6+
7+
Chef cookbook for securing sensitive payloads on nodes using a classic Caesar cipher. You know, 'cause it had to be done.
8+
9+
* Source Code: https://github.com/ut-cookbooks/rot13
10+
* Community Site: http://community.opscode.com/cookbooks/rot13
11+
12+
## <a name="usage"></a> Usage
13+
14+
Simply add a `depends "rot13"` in one of your cookbooks or include `recipe[rot13]` in your run\_list and you will have access to the `rot13_vault` [lwrp](#lwrps).
15+
16+
## <a name="requirements"></a> Requirements
17+
18+
### <a name="requirements-chef"></a> Chef
19+
20+
Tested on 11.10.4 but newer and older versions should work just fine.
21+
File an [issue][issues] if this isn't the case.
22+
23+
### <a name="requirements-platform"></a> Platform
24+
25+
The following platforms have been tested with this cookbook, meaning that the
26+
recipes run on these platforms without error:
27+
28+
* ubuntu (12.04)
29+
* centos (6.4)
30+
31+
Please [report][issues] any additional platforms so they can be added.
32+
33+
### <a name="requirements-cookbooks"></a> Cookbooks
34+
35+
This cookbook has **no** cookbook dependencies.
36+
37+
## <a name="recipes"></a> Recipes
38+
39+
### <a name="recipes-default"></a> default
40+
41+
This recipe, gloriously, does nothing.
42+
43+
## <a name="attributes"></a> Attributes
44+
45+
This cookbook depends on **no** attributes.
46+
47+
## <a name="lwrps"></a> Resources and Providers
48+
49+
### <a name="lwrps-rot13-vault"></a> rot13\_vault
50+
51+
### <a name="lwrps-rot13-vault-actions"></a> Actions
52+
53+
| Action | Description | Default |
54+
|--------|---------------------------|---------|
55+
| create | Creates the encoded file. | Yes |
56+
57+
### <a name="lwrps-rot13-vault-attributes"></a> Attributes
58+
59+
| Attribute | Description | Default Value |
60+
|-----------|---------------------------|---------------|
61+
| path | **Name attribute:** The path for the file. | `nil` |
62+
| owner | The owner of the file. | `nil` |
63+
| group | The group ownership of the file. | `nil` |
64+
| mode | The permissions of the file. | `nil` |
65+
| payload | The content that is to be encoded in the file. | `nil` |
66+
67+
#### <a name="lwrps-rot13-vault-examples"></a> Examples
68+
69+
rot13_vault "lockdown" do
70+
path "/etc/private/nopeek"
71+
owner "root"
72+
group "root"
73+
mode "0400"
74+
payload "please don't decode this"
75+
end
76+
77+
rot13_vault "/tmp/nothin" do
78+
payload <<-PAYLOAD
79+
once upon a time, ...
80+
PAYLOAD
81+
end
82+
83+
## <a name="development"></a> Development
84+
85+
* Source hosted at [GitHub][repo]
86+
* Report issues/Questions/Feature requests on [GitHub Issues][issues]
87+
88+
Pull requests are very welcome! Make sure your patches are well tested.
89+
Ideally create a topic branch for every separate change you make.
90+
91+
## <a name="license"></a> License and Author
92+
93+
Author:: [Fletcher Nichol][fnichol] (<[email protected]>) [![endorse](http://api.coderwall.com/fnichol/endorsecount.png)](http://coderwall.com/fnichol)
94+
95+
Copyright 2014, Fletcher Nichol
96+
97+
Licensed under the Apache License, Version 2.0 (the "License");
98+
you may not use this file except in compliance with the License.
99+
You may obtain a copy of the License at
100+
101+
http://www.apache.org/licenses/LICENSE-2.0
102+
103+
Unless required by applicable law or agreed to in writing, software
104+
distributed under the License is distributed on an "AS IS" BASIS,
105+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106+
See the License for the specific language governing permissions and
107+
limitations under the License.
108+
109+
[fnichol]: https://github.com/fnichol
110+
[repo]: https://github.com/ut-cookbooks/rot13
111+
[issues]: https://github.com/ut-cookbooks/rot13/issues

Rakefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env rake
2+
3+
begin
4+
require 'emeril/rake'
5+
rescue LoadError
6+
puts ">>>>> Emeril gem not loaded, omitting tasks" unless ENV['CI']
7+
end
8+
9+
require 'rspec/core/rake_task'
10+
RSpec::Core::RakeTask.new(:unit) do |t|
11+
t.rspec_opts = "--color --format documentation"
12+
t.pattern = ["spec/unit/**/*_spec.rb"]
13+
end
14+
15+
require 'foodcritic'
16+
FoodCritic::Rake::LintTask.new do |t|
17+
t.options = { :fail_tags => ['any'] }
18+
end
19+
20+
begin
21+
require 'kitchen/rake_tasks'
22+
Kitchen::RakeTasks.new
23+
rescue LoadError
24+
puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
25+
end
26+
27+
task :default => [:foodcritic, :unit]

libraries/matchers.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#
2+
# Cookbook Name:: rot13
3+
# Library:: matchers
4+
#
5+
# Copyright 2014, Fletcher Nichol
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
if defined?(ChefSpec)
21+
def create_rot13_vault(name)
22+
ChefSpec::Matchers::ResourceMatcher.new(:rot13_vault, :create, name)
23+
end
24+
25+
def delete_rot13_vault(name)
26+
ChefSpec::Matchers::ResourceMatcher.new(:rot13_vault, :delete, name)
27+
end
28+
end

libraries/rot13.rb

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Cookbook Name:: rot13
3+
# Library:: rot13
4+
#
5+
# Copyright 2014, Fletcher Nichol
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
module Rot13
21+
def self.encode(string)
22+
return nil if string.nil?
23+
24+
string.each_char.map { |ch|
25+
case ch
26+
when /^[a-z]$/
27+
(((ch.ord - "a".ord + 13) % 26) + "a".ord).chr
28+
when /^[A-Z]$/
29+
(((ch.ord - "A".ord + 13) % 26) + "A".ord).chr
30+
else
31+
ch
32+
end
33+
}.join
34+
end
35+
end

metadata.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name "rot13"
2+
version "1.0.0"

providers/vault.rb

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# Cookbook Name:: rot13
3+
# Provider:: rot13_vault
4+
#
5+
# Copyright 2014, Fletcher Nichol
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
def whyrun_supported?
21+
true
22+
end
23+
24+
use_inline_resources
25+
26+
action :create do
27+
f = file new_resource.path do
28+
owner new_resource.owner
29+
group new_resource.group
30+
mode new_resource.mode
31+
content new_resource.encoded
32+
end
33+
new_resource.updated_by_last_action(f.updated_by_last_action?)
34+
end

resources/vault.rb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Cookbook Name:: rot13
3+
# Resource:: vault
4+
#
5+
# Copyright 2014, Fletcher Nichol
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
actions :create
21+
default_action :create
22+
23+
attribute :path, :kind_of => String, :name_attribute => true
24+
attribute :owner, :kind_of => String
25+
attribute :group, :kind_of => String
26+
attribute :mode, :kind_of => [String, Integer]
27+
attribute :payload, :kind_of => String
28+
29+
include Rot13
30+
31+
def encoded
32+
Rot13.encode(payload)
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name "test"
2+
version "1.0.0"
3+
4+
depends "rot13"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
protectme = <<-SECRETS
2+
Men Wanted: For hazardous journey. Small wages, bitter cold, long months of
3+
complete darkness, constant danger, safe return doubtful. Honour and
4+
recognition in case of success.
5+
6+
- Earnest Shackleton
7+
SECRETS
8+
9+
rot13_vault "/tmp/thevault" do
10+
payload protectme
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require "serverspec"
2+
3+
include Serverspec::Helper::Exec
4+
include Serverspec::Helper::DetectOS
5+
6+
RSpec.configure do |c|
7+
c.before :all do
8+
c.path = "/sbin:/usr/sbin"
9+
end
10+
end
11+
12+
describe "Rot13" do
13+
14+
it "encodes a file, leading to pretty secure protection, probably" do
15+
expect(file("/tmp/thevault").content).to match(%r{- Rnearfg Funpxyrgba})
16+
end
17+
end

spec/unit/fixtures/metadata.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name "fixtures"
2+
version "9.0.210"
3+
4+
depends "rot13"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rot13_vault "create-full" do
2+
path "/tmp/vault"
3+
owner "frank"
4+
group "winners"
5+
mode "0400"
6+
payload "Whoops"
7+
end
8+
9+
rot13_vault "/another/store"

0 commit comments

Comments
 (0)