• This repository has been archived on 14/May/2021
  • Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chef cookbook to help store secrets in S3 in a secure fashion

Citadel Cookbook

Build Status Gem Version Cookbook Version Coverage Gemnasium License

Using a combination of IAM roles, S3 buckets, and EC2 it is possible to use AWS as a trusted-third-party for distributing secret or otherwise sensitive data.

Overview

IAM roles allow specifying snippets of IAM policies in a way that can be used from an EC2 virtual machine. Combined with a private S3 bucket, this can be used to authorize specific hosts to specific files.

IAM Roles can be created in the AWS Console. While the policies applied to a role can be changed later, the name cannot so be careful when choosing them.

Requirements

This cookbook requires Chef 12 or newer. It also requires the EC2 ohai plugin to be active. If you are using a VPC, this may require setting the hint file depending on your version of Ohai/Chef:

$ mkdir -p /etc/chef/ohai/hints
$ touch /etc/chef/ohai/hints/ec2.json

If you use knife-ec2 to start the instance, the hint file is already set for you.

In Chef 13 and newer, this plugin is automatically enabled so you don't need to do anything.

IAM Policy

By default, your role will not be able to access any files in your private S3 bucket. You can create IAM policies that whitelist specific keys for each role:

{
  "Version": "2008-10-17",
  "Id": "<policy name>",
  "Statement": [
    {
      "Sid": "<statement name>",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<AWS account number>:role/<role name>"
      },
      "Action": "s3:GetObject",
      "Resource": "arn:aws:s3:::<bucket name>/<key pattern>"
    }
  ]
}

The key pattern can include * and ? metacharacters, so for example arn:aws:s3:::myapp.citadel/deploy_keys/* to allow access to all files in the deploy_keys folder.

This policy can be attached to either the IAM role or the S3 bucket with equal effect.

Limitations

Each EC2 VM can only be assigned a single IAM role. This can complicate situations where some secrets need to be shared by overlapping subsets of your servers. A possible improvement to this would be to make a script to create all needed composite IAM roles, possibly driven by Chef roles or other metadata.

Attributes

  • node['citadel']['bucket'] โ€“ The default S3 bucket to use.

Recipe Usage

You can access secret data via the citadel method.

file '/etc/secret' do
  owner 'root'
  group 'root'
  mode '600'
  content citadel['keys/secret.pem']
end

By default the node attribute node['citadel']['bucket'] is used to find the S3 bucket to query, however you can override this:

template '/etc/secret' do
  owner 'root'
  group 'root'
  mode '600'
  variables secret: citadel('mybucket')['id_rsa']
end

Developing with Vagrant

While developing in a local VM, you can use the node attributes node['citadel']['access_key_id'] and node['citadel']['secret_access_key'] to provide credentials. The recommended way to do this is via environment variables so that the Vagrantfile itself can still be kept in source control without leaking credentials:

config.vm.provision :chef_solo do |chef|
  chef.json = {
    citadel: {
      access_key_id: ENV['ACCESS_KEY_ID'],
      secret_access_key: ENV['SECRET_ACCESS_KEY'],
    },
  }
end

WARNING: Use of these attributes in production should be considered a likely security risk as they will end up visible in the node data, or in the role/environment/cookbook that sets them. This can be mitigated using Enterprise Chef ACLs, however such configurations are generally error-prone due to the defaults being wide open.

Testing with Test-Kitchen

Similarly you can use the same attributes with Test-Kitchen

provisioner:
  name: chef_solo
  attributes:
    citadel:
      access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
      secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>

Recommended S3 Layout

Within your S3 bucket I recommend you create one folder for each group of secrets, and in your IAM policies have one statement per group. Each group of secrets is a set of data with identical security requirements. Many groups will start out only containing a single file, however having the flexibility to change this in the future allows for things like key rotation without rewriting all of your IAM policies.

An example of an IAM policy resource would be:

"Resource": "arn:aws:s3:::mybucket/myfolder/*"

Creating and Updating Secrets

You can use any S3 client you prefer to manage your secrets, however make sure that new files are set to private (accessible only to the creating user) by default.

Sponsors

The Poise test server infrastructure is sponsored by Rackspace.

License

Copyright 2013-2016, Balanced, Inc. Copyright 2016, Noah Kantrowitz

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.

More Repositories

1

python

THIS COOKBOOK IS DEPRECATED โ€“ Chef cookbook to install Python and related tools
Python
571
star
2

application

A Chef cookbook to deploy applications.
Ruby
144
star
3

poise-python

A Chef cookbook to provide a unified interface for installing Python, managing Python packages, and creating virtualenvs.
Ruby
124
star
4

application_ruby

Development repository for Opscode Cookbook application_ruby
Ruby
124
star
5

poise

A set of libraries for writing reusable Chef cookbooks
Ruby
106
star
6

application_python

A Chef cookbook to deploy Python applications.
Ruby
73
star
7

supervisor

Development repository for Opscode Cookbook supervisor
Ruby
64
star
8

poise-service

A Chef cookbook to provide a unified interface for services.
Ruby
43
star
9

halite

Write as a gem, release as a cookbook.
Ruby
42
star
10

application_nginx

Development repository for Opscode Cookbook application_nginx
Ruby
34
star
11

poise-ruby

A Chef cookbook to provide a unified interface for installing Ruby and running things with it.
Ruby
27
star
12

poise-derived

A Chef cookbook for defining lazily evaluated node attributes.
Ruby
22
star
13

application_php

Development repository for Opscode Cookbook application_php
Ruby
21
star
14

application_java

Development repository for Opscode Cookbook application_java
Ruby
21
star
15

yolover-example

YoloVer example repository
Ruby
14
star
16

poise-hoist

A cookbook to help automate "attribute hoisting" when using Chef with Policyfiles.
Ruby
13
star
17

berkshelf-api

A Chef cookbook to install a Berkshelf API server
Ruby
13
star
18

application_git

A Chef cookbook to handle deploying code from git when using the application cookbook.
Ruby
11
star
19

poise-profiler

A Chef cookbook to display profiling information at the end of the run.
Ruby
11
star
20

poise-archive

A Chef cookbook to unpack file archives like TAR and ZIP files.
Ruby
10
star
21

poise-monit

A Chef cookbook to manage Monit.
Ruby
9
star
22

mercurial

Development repository for Opscode Cookbook mercurial
Ruby
9
star
23

jenkins

Ruby
8
star
24

application_javascript

A Chef cookbook to deploy server-side JavaScript applications using Node.js or io.js.
Ruby
7
star
25

poise-javascript

A Chef cookbook to provide a unified interface for installing server-side JavaScript runtimes like Node.js and io.js.
Ruby
7
star
26

poise-file

A Chef cookbook for advanced file management.
Ruby
6
star
27

poise-ruby-build

A ruby-build provider for the poise-ruby cookbook.
Ruby
5
star
28

poise-boiler

Poise-boiler is a set of helpers to reduce boilerplate in Poise/Halite style gems.
Ruby
5
star
29

poise-appenv

Helpers for application-specific envronment settings in Chef
Ruby
4
star
30

yolover

Using Policyfiles: YoloVer as a Workflow
HTML
4
star
31

rubocop-chef

Ruby
4
star
32

ci

A cookbook to configure a Jenkins CI environment
Ruby
3
star
33

poise-proxy

Generic HTTP proxy resource
Ruby
3
star
34

poise-dsl

A Chef cookbook for declaring DSL helper methods.
Ruby
2
star
35

poise-dash-prototype

CoffeeScript
2
star
36

application_examples

Examples for using the Application cookbooks.
Ruby
2
star
37

poise-supervisor

A Chef cookbook to manage Supervisor.
Ruby
2
star
38

poise-languages

Shared support code for Poise's language cookbooks.
Ruby
2
star
39

poise-service-runit

Ruby
2
star
40

poise-monit-compat

A deprecated Chef cookbook to manage Monit.
Ruby
1
star
41

test_django

An example Django application for testing cookbooks.
Python
1
star
42

poise-service-monit

Ruby
1
star
43

cookiecutter-cookbook

Cookiecutter template for a Poise-enabled Chef cookbook
Ruby
1
star
44

poise.io

Poise website and documentation.
Ruby
1
star
45

kitchen-zone

Ruby
1
star