]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/manifests/resource/authtoken.pp
Update to Kilo
[dsa-puppet.git] / 3rdparty / modules / keystone / manifests / resource / authtoken.pp
1 # == Definition: keystone::resource::authtoken
2 #
3 # This resource configures Keystone authentication resources for an OpenStack
4 # service.  It will manage the [keystone_authtoken] section in the given
5 # config resource.  It supports all of the authentication parameters specified
6 # at http://www.jamielennox.net/blog/2015/02/17/loading-authentication-plugins/
7 # with the addition of the default domain for user and project.
8 #
9 # The username and project_name parameters may be given in the form
10 # "name::domainname".  The authtoken resource will use the domains in
11 # the following order:
12 # 1) The given domain parameter (user_domain_name or project_domain_name)
13 # 2) The domain given as the "::domainname" part of username or project_name
14 # 3) The default_domain_name
15 #
16 # For example, instead of doing this::
17 #
18 #     glance_api_config {
19 #       'keystone_authtoken/admin_tenant_name': value => $keystone_tenant;
20 #       'keystone_authtoken/admin_user'       : value => $keystone_user;
21 #       'keystone_authtoken/admin_password'   : value => $keystone_password;
22 #       secret => true;
23 #       ...
24 #     }
25 #
26 # manifests should do this instead::
27 #
28 #     keystone::resource::authtoken { 'glance_api_config':
29 #       username            => $keystone_user,
30 #       password            => $keystone_password,
31 #       auth_url            => $real_identity_uri,
32 #       project_name        => $keystone_tenant,
33 #       user_domain_name    => $keystone_user_domain,
34 #       project_domain_name => $keystone_project_domain,
35 #       default_domain_name => $keystone_default_domain,
36 #       cacert              => $ca_file,
37 #       ...
38 #     }
39 #
40 # The use of `keystone::resource::authtoken` makes it easy to avoid mistakes,
41 # and makes it easier to support some of the newer authentication types coming
42 # with Keystone Kilo and later, such as Kerberos, Federation, etc.
43 #
44 # == Parameters:
45 #
46 # [*name*]
47 #   The name of the resource corresponding to the config file.  For example,
48 #   keystone::resource::authtoken { 'glance_api_config': ... }
49 #   Where 'glance_api_config' is the name of the resource used to manage
50 #   the glance api configuration.
51 #   string; required
52 #
53 # [*username*]
54 #   The name of the service user;
55 #   string; required
56 #
57 # [*password*]
58 #   Password to create for the service user;
59 #   string; required
60 #
61 # [*auth_url*]
62 #   The URL to use for authentication.
63 #   string; required
64 #
65 # [*auth_plugin*]
66 #   The plugin to use for authentication.
67 #   string; optional: default to 'password'
68 #
69 # [*user_id*]
70 #   The ID of the service user;
71 #   string; optional: default to undef
72 #
73 # [*user_domain_name*]
74 #   (Optional) Name of domain for $username
75 #   Defaults to undef
76 #
77 # [*user_domain_id*]
78 #   (Optional) ID of domain for $username
79 #   Defaults to undef
80 #
81 # [*project_name*]
82 #   Service project name;
83 #   string; optional: default to undef
84 #
85 # [*project_id*]
86 #   Service project ID;
87 #   string; optional: default to undef
88 #
89 # [*project_domain_name*]
90 #   (Optional) Name of domain for $project_name
91 #   Defaults to undef
92 #
93 # [*project_domain_id*]
94 #   (Optional) ID of domain for $project_name
95 #   Defaults to undef
96 #
97 # [*domain_name*]
98 #   (Optional) Use this for auth to obtain a domain-scoped token.
99 #   If using this option, do not specify $project_name or $project_id.
100 #   Defaults to undef
101 #
102 # [*domain_id*]
103 #   (Optional) Use this for auth to obtain a domain-scoped token.
104 #   If using this option, do not specify $project_name or $project_id.
105 #   Defaults to undef
106 #
107 # [*default_domain_name*]
108 #   (Optional) Name of domain for $username and $project_name
109 #   If user_domain_name is not specified, use $default_domain_name
110 #   If project_domain_name is not specified, use $default_domain_name
111 #   Defaults to undef
112 #
113 # [*default_domain_id*]
114 #   (Optional) ID of domain for $user_id and $project_id
115 #   If user_domain_id is not specified, use $default_domain_id
116 #   If project_domain_id is not specified, use $default_domain_id
117 #   Defaults to undef
118 #
119 # [*trust_id*]
120 #   (Optional) Trust ID
121 #   Defaults to undef
122 #
123 # [*cacert*]
124 #   (Optional) CA certificate file for TLS (https)
125 #   Defaults to undef
126 #
127 # [*cert*]
128 #   (Optional) Certificate file for TLS (https)
129 #   Defaults to undef
130 #
131 # [*key*]
132 #   (Optional) Key file for TLS (https)
133 #   Defaults to undef
134 #
135 # [*insecure*]
136 #   If true, explicitly allow TLS without checking server cert against any
137 #   certificate authorities.  WARNING: not recommended.  Use with caution.
138 #   boolean; Defaults to false (which means be secure)
139 #
140 define keystone::resource::authtoken(
141   $username,
142   $password,
143   $auth_url,
144   $auth_plugin         = 'password',
145   $user_id             = undef,
146   $user_domain_name    = undef,
147   $user_domain_id      = undef,
148   $project_name        = undef,
149   $project_id          = undef,
150   $project_domain_name = undef,
151   $project_domain_id   = undef,
152   $domain_name         = undef,
153   $domain_id           = undef,
154   $default_domain_name = undef,
155   $default_domain_id   = undef,
156   $trust_id            = undef,
157   $cacert              = undef,
158   $cert                = undef,
159   $key                 = undef,
160   $insecure            = false,
161 ) {
162
163   if !$project_name and !$project_id and !$domain_name and !$domain_id {
164     fail('Must specify either a project (project_name or project_id, for a project scoped token) or a domain (domain_name or domain_id, for a domain scoped token)')
165   }
166
167   if ($project_name or $project_id) and ($domain_name or $domain_id) {
168     fail('Cannot specify both a project (project_name or project_id) and a domain (domain_name or domain_id)')
169   }
170
171   $user_and_domain_array = split($username, '::')
172   $real_username = $user_and_domain_array[0]
173   $real_user_domain_name = pick($user_domain_name, $user_and_domain_array[1], $default_domain_name, '__nodomain__')
174
175   $project_and_domain_array = split($project_name, '::')
176   $real_project_name = $project_and_domain_array[0]
177   $real_project_domain_name = pick($project_domain_name, $project_and_domain_array[1], $default_domain_name, '__nodomain__')
178
179   create_resources($name, {'keystone_authtoken/auth_plugin' => {'value' => $auth_plugin}})
180   create_resources($name, {'keystone_authtoken/auth_url' => {'value' => $auth_url}})
181   create_resources($name, {'keystone_authtoken/username' => {'value' => $real_username}})
182   create_resources($name, {'keystone_authtoken/password' => {'value' => $password, 'secret' => true}})
183   if $user_id {
184     create_resources($name, {'keystone_authtoken/user_id' => {'value' => $user_id}})
185   } else {
186     create_resources($name, {'keystone_authtoken/user_id' => {'ensure' => 'absent'}})
187   }
188   if $real_user_domain_name == '__nodomain__' {
189     create_resources($name, {'keystone_authtoken/user_domain_name' => {'ensure' => 'absent'}})
190   } else {
191     create_resources($name, {'keystone_authtoken/user_domain_name' => {'value' => $real_user_domain_name}})
192   }
193   if $user_domain_id {
194     create_resources($name, {'keystone_authtoken/user_domain_id' => {'value' => $user_domain_id}})
195   } elsif $default_domain_id {
196     create_resources($name, {'keystone_authtoken/user_domain_id' => {'value' => $default_domain_id}})
197   } else {
198     create_resources($name, {'keystone_authtoken/user_domain_id' => {'ensure' => 'absent'}})
199   }
200   if $project_name {
201     create_resources($name, {'keystone_authtoken/project_name' => {'value' => $real_project_name}})
202   } else {
203     create_resources($name, {'keystone_authtoken/project_name' => {'ensure' => 'absent'}})
204   }
205   if $project_id {
206     create_resources($name, {'keystone_authtoken/project_id' => {'value' => $project_id}})
207   } else {
208     create_resources($name, {'keystone_authtoken/project_id' => {'ensure' => 'absent'}})
209   }
210   if $real_project_domain_name == '__nodomain__' {
211     create_resources($name, {'keystone_authtoken/project_domain_name' => {'ensure' => 'absent'}})
212   } else {
213     create_resources($name, {'keystone_authtoken/project_domain_name' => {'value' => $real_project_domain_name}})
214   }
215   if $project_domain_id {
216     create_resources($name, {'keystone_authtoken/project_domain_id' => {'value' => $project_domain_id}})
217   } elsif $default_domain_id {
218     create_resources($name, {'keystone_authtoken/project_domain_id' => {'value' => $default_domain_id}})
219   } else {
220     create_resources($name, {'keystone_authtoken/project_domain_id' => {'ensure' => 'absent'}})
221   }
222   if $domain_name {
223     create_resources($name, {'keystone_authtoken/domain_name' => {'value' => $domain_name}})
224   } else {
225     create_resources($name, {'keystone_authtoken/domain_name' => {'ensure' => 'absent'}})
226   }
227   if $domain_id {
228     create_resources($name, {'keystone_authtoken/domain_id' => {'value' => $domain_id}})
229   } else {
230     create_resources($name, {'keystone_authtoken/domain_id' => {'ensure' => 'absent'}})
231   }
232   if $trust_id {
233     create_resources($name, {'keystone_authtoken/trust_id' => {'value' => $trust_id}})
234   } else {
235     create_resources($name, {'keystone_authtoken/trust_id' => {'ensure' => 'absent'}})
236   }
237   if $cacert {
238     create_resources($name, {'keystone_authtoken/cacert' => {'value' => $cacert}})
239   } else {
240     create_resources($name, {'keystone_authtoken/cacert' => {'ensure' => 'absent'}})
241   }
242   if $cert {
243     create_resources($name, {'keystone_authtoken/cert' => {'value' => $cert}})
244   } else {
245     create_resources($name, {'keystone_authtoken/cert' => {'ensure' => 'absent'}})
246   }
247   if $key {
248     create_resources($name, {'keystone_authtoken/key' => {'value' => $key}})
249   } else {
250     create_resources($name, {'keystone_authtoken/key' => {'ensure' => 'absent'}})
251   }
252   create_resources($name, {'keystone_authtoken/insecure' => {'value' => $insecure}})
253 }