1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#
# Copyright (C) 2014 Catalyst IT Limited.
#
# 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.
#
# Author: Ricardo Rocha <ricardo@catalyst.net.nz>
#
# Handles ceph keys (cephx), generates keys, creates keyring files, injects
# keys into or delete keys from the cluster/keyring via ceph and ceph-authtool
# tools.
#
# == Define: ceph::key
#
# The full ceph ID name, e.g. 'client.admin' or 'mon.'.
#
# === Parameters:
#
# [*secret*] Key secret.
# Mandatory. Can be created with ceph-authtool --gen-print-key.
#
# [*cluster*] The ceph cluster
# Optional. Same default as ceph.
#
# [*keyring_path*] Path to the keyring file.
# Optional. Absolute path to the keyring file, including the file name.
# Defaults to /etc/ceph/ceph.${name}.keyring.
#
# [*cap_mon*] cephx capabilities for MON access.
# Optional. e.g. 'allow *'
# Defaults to 'undef'.
#
# [*cap_osd*] cephx capabilities for OSD access.
# Optional. e.g. 'allow *'
# Defaults to 'undef'.
#
# [*cap_mds*] cephx capabilities for MDS access.
# Optional. e.g. 'allow *'
# Defaults to 'undef'.
#
# [*cap_mgr*] cephx capabilities for MGR access.
# Optional. e.g. 'allow *'
# Defaults to 'undef'.
#
# [*user*] Owner of the *keyring_path* file.
# Optional. Defaults to 'root'.
#
# [*group*] Group of the *keyring_path* file.
# Optional. Defaults to 'root'.
#
# [*mode*] Mode (permissions) of the *keyring_path* file.
# Optional. Defaults to 0600.
#
# [*inject*] True if the key should be injected into the cluster.
# Optional. Boolean value (true to inject the key).
# Default to false.
#
# [*inject_as_id*] the ceph ID used to inject the key Optional. Only
# taken into account if 'inject' was set to true, in which case it
# overrides the ceph default if set to a value other than
# undef. Default to undef.
#
# [*inject_keyring*] keyring file with injection credentials
# Optional. Only taken into account if 'inject' was set to true. If
# set to a value other than undef, it overrides the ceph default
# inferred from the client name. Default to undef.
#
define ceph::key (
$secret,
$cluster = undef,
$keyring_path = "/etc/ceph/ceph.${name}.keyring",
$cap_mon = undef,
$cap_osd = undef,
$cap_mds = undef,
$cap_mgr = undef,
$user = 'root',
$group = 'root',
$mode = '0600',
$inject = false,
$inject_as_id = undef,
$inject_keyring = undef,
) {
if $cluster {
$cluster_option = "--cluster ${cluster}"
} else
{
$cluster_option = ''
}
if $cap_mon {
$mon_caps = "--cap mon '${cap_mon}' "
} else {
$mon_caps = ''
}
if $cap_osd {
$osd_caps = "--cap osd '${cap_osd}' "
} else {
$osd_caps = ''
}
if $cap_mds {
$mds_caps = "--cap mds '${cap_mds}' "
} else {
$mds_caps = ''
}
if $cap_mgr {
$mgr_caps = "--cap mgr '${cap_mgr}' "
} else {
$mgr_caps = ''
}
$caps = "${mon_caps}${osd_caps}${mds_caps}${mgr_caps}"
# this allows multiple defines for the same 'keyring file',
# which is supported by ceph-authtool
if ! defined(File[$keyring_path]) {
file { $keyring_path:
ensure => file,
owner => $user,
group => $group,
mode => $mode,
selinux_ignore_defaults => true,
require => Package[$ceph::params::packages],
}
}
# ceph-authtool --add-key is idempotent, will just update pre-existing keys
exec { "ceph-key-${name}":
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ceph-authtool ${keyring_path} --name '${name}' --add-key '${secret}' ${caps}",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -x
NEW_KEYRING=\$(mktemp)
ceph-authtool \$NEW_KEYRING --name '${name}' --add-key '${secret}' ${caps}
diff -N \$NEW_KEYRING ${keyring_path}
rv=\$?
rm \$NEW_KEYRING
exit \$rv",
require => [ File[$keyring_path], ],
logoutput => true,
}
if $inject {
if $inject_as_id {
$inject_id_option = " --name '${inject_as_id}' "
}
else {
$inject_id_option = ''
}
if $inject_keyring {
$inject_keyring_option = " --keyring '${inject_keyring}' "
}
else {
$inject_keyring_option = ''
}
Ceph_config<||> -> Exec["ceph-injectkey-${name}"]
Ceph::Mon<||> -> Exec["ceph-injectkey-${name}"]
# ceph auth import is idempotent, will just update pre-existing keys
exec { "ceph-injectkey-${name}":
command => "/bin/true # comment to satisfy puppet syntax requirements
set -ex
ceph ${cluster_option} ${inject_id_option} ${inject_keyring_option} auth import -i ${keyring_path}",
unless => "/bin/true # comment to satisfy puppet syntax requirements
set -x
OLD_KEYRING=\$(mktemp)
TMP_KEYRING=\$(mktemp)
cat ${keyring_path} | sed -e 's/\\\\//g' > \$TMP_KEYRING
ceph ${cluster_option} ${inject_id_option} ${inject_keyring_option} auth get ${name} -o \$OLD_KEYRING || true
diff -N \$OLD_KEYRING \$TMP_KEYRING
rv=$?
rm \$OLD_KEYRING
rm \$TMP_KEYRING
exit \$rv",
require => [ Class['ceph'], Exec["ceph-key-${name}"], ],
logoutput => true,
}
}
}
|