Skip to content

Commit

Permalink
Add attributes for separate items
Browse files Browse the repository at this point in the history
  • Loading branch information
realloc authored and phlipper committed May 16, 2015
1 parent 3d23478 commit 8395618
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -94,6 +94,8 @@ To use encrypted passwords, you must create an encrypted data bag. This cookbook

This cookbook expects a `mysql` item and a `system` item. Please refer to the official documentation on how to get this setup. It actually uses a MySQL example so it can be mostly copied. Ensure you cover the data bag items as described below.

You also may set expected item names via attributes `node["percona"]["encrypted_data_bag_item_mysql"]` and `node["percona"]["encrypted_data_bag_item_system"]`.

### Skip passwords
Set the `["percona"]["skip_passwords"]` attribute to skip setting up passwords. Removes the need for the encrypted data bag if using chef-solo. Is useful for setting up development and ci environments where you just want to use the root user with no password. If you are doing this you may want to set `[:percona][:server][:debian_username]` to be `"root"` also.

Expand Down Expand Up @@ -130,7 +132,7 @@ Above shows the encrypted password in the data bag. Check out the `encrypted_dat

### Replication over SSL
To enable SSL based replication, you will need to flip the attribute `node[:percona][:server][:replication][:ssl_enabled]` to `true` and add a new data_bag item
to the percona encrypted data_bag (see `node[:percona][:encrypted_data_bag]` attribute) with the id `ssl_replication` that contains this data:
to the percona encrypted data_bag (see`node[:percona][:encrypted_data_bag]` attribute) with the id `ssl_replication` ( see `node["percona"]["encrypted_data_bag_item_sslrep"]` attribute) that contains this data:

```javascript
{
Expand Down
3 changes: 3 additions & 0 deletions attributes/default.rb
Expand Up @@ -38,6 +38,9 @@
default["percona"]["keyserver"] = "keys.gnupg.net"
default["percona"]["encrypted_data_bag"] = "passwords"
default["percona"]["encrypted_data_bag_secret_file"] = ""
default["percona"]["encrypted_data_bag_item_mysql"] = "mysql"
default["percona"]["encrypted_data_bag_item_system"] = "system"
default["percona"]["encrypted_data_bag_item_sslrep"] = "ssl_replication"
default["percona"]["use_chef_vault"] = false
default["percona"]["skip_passwords"] = false
default["percona"]["skip_configure"] = false
Expand Down
13 changes: 8 additions & 5 deletions libraries/passwords.rb
Expand Up @@ -8,6 +8,8 @@ def initialize(node, bag = "passwords")
@node = node
@bag = bag
@secret_file = node["percona"]["encrypted_data_bag_secret_file"]
@mysql_item = node["percona"]["encrypted_data_bag_item_mysql"]
@system_item = node["percona"]["encrypted_data_bag_item_system"]
end

# helper for passwords
Expand All @@ -32,32 +34,33 @@ def find_password(item, user, default = nil)

# mysql root
def root_password
find_password "mysql", "root", node_server["root_password"]
find_password @mysql_item, "root", node_server["root_password"]
end

# debian script user password
def debian_password
find_password(
"system", node_server["debian_username"], node_server["debian_password"]
@system_item, node_server["debian_username"],
node_server["debian_password"]
)
end

# ?
def old_passwords
find_password "mysql", "old_passwords", node_server["old_passwords"]
find_password @mysql_item, "old_passwords", node_server["old_passwords"]
end

# password for user responsbile for replicating in master/slave environment
def replication_password
find_password(
"mysql", "replication", node_server["replication"]["password"]
@mysql_item, "replication", node_server["replication"]["password"]
)
end

# password for user responsbile for running xtrabackup
def backup_password
backup = node["percona"]["backup"]
find_password "mysql", backup["username"], backup["password"]
find_password @mysql_item, backup["username"], backup["password"]
end

private
Expand Down
5 changes: 4 additions & 1 deletion recipes/ssl.rb
Expand Up @@ -12,7 +12,10 @@
mode "0700"
end

certs = Chef::EncryptedDataBagItem.load(data_bag, "ssl_replication")
certs = Chef::EncryptedDataBagItem.load(
data_bag,
node["percona"]["encrypted_data_bag_item_sslrep"]
)

# place the CA certificate, it should be present on both master and slave
file "#{certs_path}/cacert.pem" do
Expand Down

0 comments on commit 8395618

Please sign in to comment.