| 1 |
.. _community.okd.openshift_auth_module: |
| 2 |
|
| 3 |
|
| 4 |
**************************** |
| 5 |
community.okd.openshift_auth |
| 6 |
**************************** |
| 7 |
|
| 8 |
**Authenticate to OpenShift clusters which require an explicit login step** |
| 9 |
|
| 10 |
|
| 11 |
Version added: 0.2.0 |
| 12 |
|
| 13 |
.. contents:: |
| 14 |
:local: |
| 15 |
:depth: 1 |
| 16 |
|
| 17 |
|
| 18 |
Synopsis |
| 19 |
-------- |
| 20 |
- This module handles authenticating to OpenShift clusters requiring *explicit* authentication procedures, meaning ones where a client logs in (obtains an authentication token), performs API operations using said token and then logs out (revokes the token). |
| 21 |
- On the other hand a popular configuration for username+password authentication is one utilizing HTTP Basic Auth, which does not involve any additional login/logout steps (instead login credentials can be attached to each and every API call performed) and as such is handled directly by the ``k8s`` module (and other resource–specific modules) by utilizing the ``host``, ``username`` and ``password`` parameters. Please consult your preferred module's documentation for more details. |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
Requirements |
| 26 |
------------ |
| 27 |
The below requirements are needed on the host that executes this module. |
| 28 |
|
| 29 |
- python >= 3.6 |
| 30 |
- urllib3 |
| 31 |
- requests |
| 32 |
- requests-oauthlib |
| 33 |
|
| 34 |
|
| 35 |
Parameters |
| 36 |
---------- |
| 37 |
|
| 38 |
.. raw:: html |
| 39 |
|
| 40 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 41 |
<tr> |
| 42 |
<th colspan="1">Parameter</th> |
| 43 |
<th>Choices/<font color="blue">Defaults</font></th> |
| 44 |
<th width="100%">Comments</th> |
| 45 |
</tr> |
| 46 |
<tr> |
| 47 |
<td colspan="1"> |
| 48 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 49 |
<b>api_key</b> |
| 50 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 51 |
<div style="font-size: small"> |
| 52 |
<span style="color: purple">string</span> |
| 53 |
</div> |
| 54 |
</td> |
| 55 |
<td> |
| 56 |
</td> |
| 57 |
<td> |
| 58 |
<div>When <code>state</code> is set to <em>absent</em>, this specifies the token to revoke.</div> |
| 59 |
</td> |
| 60 |
</tr> |
| 61 |
<tr> |
| 62 |
<td colspan="1"> |
| 63 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 64 |
<b>ca_cert</b> |
| 65 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 66 |
<div style="font-size: small"> |
| 67 |
<span style="color: purple">path</span> |
| 68 |
</div> |
| 69 |
</td> |
| 70 |
<td> |
| 71 |
</td> |
| 72 |
<td> |
| 73 |
<div>Path to a CA certificate file used to verify connection to the API server. The full certificate chain must be provided to avoid certificate validation errors.</div> |
| 74 |
<div style="font-size: small; color: darkgreen"><br/>aliases: ssl_ca_cert</div> |
| 75 |
</td> |
| 76 |
</tr> |
| 77 |
<tr> |
| 78 |
<td colspan="1"> |
| 79 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 80 |
<b>host</b> |
| 81 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 82 |
<div style="font-size: small"> |
| 83 |
<span style="color: purple">string</span> |
| 84 |
/ <span style="color: red">required</span> |
| 85 |
</div> |
| 86 |
</td> |
| 87 |
<td> |
| 88 |
</td> |
| 89 |
<td> |
| 90 |
<div>Provide a URL for accessing the API server.</div> |
| 91 |
</td> |
| 92 |
</tr> |
| 93 |
<tr> |
| 94 |
<td colspan="1"> |
| 95 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 96 |
<b>password</b> |
| 97 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 98 |
<div style="font-size: small"> |
| 99 |
<span style="color: purple">string</span> |
| 100 |
</div> |
| 101 |
</td> |
| 102 |
<td> |
| 103 |
</td> |
| 104 |
<td> |
| 105 |
<div>Provide a password for authenticating with the API server.</div> |
| 106 |
</td> |
| 107 |
</tr> |
| 108 |
<tr> |
| 109 |
<td colspan="1"> |
| 110 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 111 |
<b>state</b> |
| 112 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 113 |
<div style="font-size: small"> |
| 114 |
<span style="color: purple">string</span> |
| 115 |
</div> |
| 116 |
</td> |
| 117 |
<td> |
| 118 |
<ul style="margin: 0; padding: 0"><b>Choices:</b> |
| 119 |
<li><div style="color: blue"><b>present</b> ←</div></li> |
| 120 |
<li>absent</li> |
| 121 |
</ul> |
| 122 |
</td> |
| 123 |
<td> |
| 124 |
<div>If set to <em>present</em> connect to the API server using the URL specified in <code>host</code> and attempt to log in.</div> |
| 125 |
<div>If set to <em>absent</em> attempt to log out by revoking the authentication token specified in <code>api_key</code>.</div> |
| 126 |
</td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<td colspan="1"> |
| 130 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 131 |
<b>username</b> |
| 132 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 133 |
<div style="font-size: small"> |
| 134 |
<span style="color: purple">string</span> |
| 135 |
</div> |
| 136 |
</td> |
| 137 |
<td> |
| 138 |
</td> |
| 139 |
<td> |
| 140 |
<div>Provide a username for authenticating with the API server.</div> |
| 141 |
</td> |
| 142 |
</tr> |
| 143 |
<tr> |
| 144 |
<td colspan="1"> |
| 145 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 146 |
<b>validate_certs</b> |
| 147 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 148 |
<div style="font-size: small"> |
| 149 |
<span style="color: purple">boolean</span> |
| 150 |
</div> |
| 151 |
</td> |
| 152 |
<td> |
| 153 |
<ul style="margin: 0; padding: 0"><b>Choices:</b> |
| 154 |
<li>no</li> |
| 155 |
<li><div style="color: blue"><b>yes</b> ←</div></li> |
| 156 |
</ul> |
| 157 |
</td> |
| 158 |
<td> |
| 159 |
<div>Whether or not to verify the API server's SSL certificates.</div> |
| 160 |
<div style="font-size: small; color: darkgreen"><br/>aliases: verify_ssl</div> |
| 161 |
</td> |
| 162 |
</tr> |
| 163 |
</table> |
| 164 |
<br/> |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
Examples |
| 170 |
-------- |
| 171 |
|
| 172 |
.. code-block:: yaml |
| 173 |
|
| 174 |
- name: Example Playbook |
| 175 |
hosts: localhost |
| 176 |
module_defaults: |
| 177 |
group/community.okd.okd: |
| 178 |
host: https://k8s.example.com/ |
| 179 |
ca_cert: ca.pem |
| 180 |
tasks: |
| 181 |
- name: Authenticate to OpenShift cluster and gell a list of all pods from any namespace |
| 182 |
block: |
| 183 |
# It's good practice to store login credentials in a secure vault and not |
| 184 |
# directly in playbooks. |
| 185 |
- name: Include 'openshift_passwords.yml' |
| 186 |
ansible.builtin.include_vars: openshift_passwords.yml |
| 187 |
|
| 188 |
- name: Log in (obtain access token) |
| 189 |
community.okd.openshift_auth: |
| 190 |
username: admin |
| 191 |
password: "{{ openshift_admin_password }}" |
| 192 |
register: openshift_auth_results |
| 193 |
|
| 194 |
# Previous task provides the token/api_key, while all other parameters |
| 195 |
# are taken from module_defaults |
| 196 |
- name: Get a list of all pods from any namespace |
| 197 |
kubernetes.core.k8s_info: |
| 198 |
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}" |
| 199 |
kind: Pod |
| 200 |
register: pod_list |
| 201 |
|
| 202 |
always: |
| 203 |
- name: If login succeeded, try to log out (revoke access token) |
| 204 |
when: openshift_auth_results.openshift_auth.api_key is defined |
| 205 |
community.okd.openshift_auth: |
| 206 |
state: absent |
| 207 |
api_key: "{{ openshift_auth_results.openshift_auth.api_key }}" |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
Return Values |
| 212 |
------------- |
| 213 |
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module: |
| 214 |
|
| 215 |
.. raw:: html |
| 216 |
|
| 217 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 218 |
<tr> |
| 219 |
<th colspan="2">Key</th> |
| 220 |
<th>Returned</th> |
| 221 |
<th width="100%">Description</th> |
| 222 |
</tr> |
| 223 |
<tr> |
| 224 |
<td colspan="2"> |
| 225 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 226 |
<b>k8s_auth</b> |
| 227 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 228 |
<div style="font-size: small"> |
| 229 |
<span style="color: purple">complex</span> |
| 230 |
</div> |
| 231 |
</td> |
| 232 |
<td>success</td> |
| 233 |
<td> |
| 234 |
<div>Same as returned openshift_auth. Kept only for backwards compatibility</div> |
| 235 |
<br/> |
| 236 |
</td> |
| 237 |
</tr> |
| 238 |
<tr> |
| 239 |
<td class="elbow-placeholder"> </td> |
| 240 |
<td colspan="1"> |
| 241 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 242 |
<b>api_key</b> |
| 243 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 244 |
<div style="font-size: small"> |
| 245 |
<span style="color: purple">string</span> |
| 246 |
</div> |
| 247 |
</td> |
| 248 |
<td>success</td> |
| 249 |
<td> |
| 250 |
<div>Authentication token.</div> |
| 251 |
<br/> |
| 252 |
</td> |
| 253 |
</tr> |
| 254 |
<tr> |
| 255 |
<td class="elbow-placeholder"> </td> |
| 256 |
<td colspan="1"> |
| 257 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 258 |
<b>ca_cert</b> |
| 259 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 260 |
<div style="font-size: small"> |
| 261 |
<span style="color: purple">string</span> |
| 262 |
</div> |
| 263 |
</td> |
| 264 |
<td>success</td> |
| 265 |
<td> |
| 266 |
<div>Path to a CA certificate file used to verify connection to the API server.</div> |
| 267 |
<br/> |
| 268 |
</td> |
| 269 |
</tr> |
| 270 |
<tr> |
| 271 |
<td class="elbow-placeholder"> </td> |
| 272 |
<td colspan="1"> |
| 273 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 274 |
<b>host</b> |
| 275 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 276 |
<div style="font-size: small"> |
| 277 |
<span style="color: purple">string</span> |
| 278 |
</div> |
| 279 |
</td> |
| 280 |
<td>success</td> |
| 281 |
<td> |
| 282 |
<div>URL for accessing the API server.</div> |
| 283 |
<br/> |
| 284 |
</td> |
| 285 |
</tr> |
| 286 |
<tr> |
| 287 |
<td class="elbow-placeholder"> </td> |
| 288 |
<td colspan="1"> |
| 289 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 290 |
<b>username</b> |
| 291 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 292 |
<div style="font-size: small"> |
| 293 |
<span style="color: purple">string</span> |
| 294 |
</div> |
| 295 |
</td> |
| 296 |
<td>success</td> |
| 297 |
<td> |
| 298 |
<div>Username for authenticating with the API server.</div> |
| 299 |
<br/> |
| 300 |
</td> |
| 301 |
</tr> |
| 302 |
<tr> |
| 303 |
<td class="elbow-placeholder"> </td> |
| 304 |
<td colspan="1"> |
| 305 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 306 |
<b>validate_certs</b> |
| 307 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 308 |
<div style="font-size: small"> |
| 309 |
<span style="color: purple">boolean</span> |
| 310 |
</div> |
| 311 |
</td> |
| 312 |
<td>success</td> |
| 313 |
<td> |
| 314 |
<div>Whether or not to verify the API server's SSL certificates.</div> |
| 315 |
<br/> |
| 316 |
</td> |
| 317 |
</tr> |
| 318 |
|
| 319 |
<tr> |
| 320 |
<td colspan="2"> |
| 321 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 322 |
<b>openshift_auth</b> |
| 323 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 324 |
<div style="font-size: small"> |
| 325 |
<span style="color: purple">complex</span> |
| 326 |
</div> |
| 327 |
</td> |
| 328 |
<td>success</td> |
| 329 |
<td> |
| 330 |
<div>OpenShift authentication facts.</div> |
| 331 |
<br/> |
| 332 |
</td> |
| 333 |
</tr> |
| 334 |
<tr> |
| 335 |
<td class="elbow-placeholder"> </td> |
| 336 |
<td colspan="1"> |
| 337 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 338 |
<b>api_key</b> |
| 339 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 340 |
<div style="font-size: small"> |
| 341 |
<span style="color: purple">string</span> |
| 342 |
</div> |
| 343 |
</td> |
| 344 |
<td>success</td> |
| 345 |
<td> |
| 346 |
<div>Authentication token.</div> |
| 347 |
<br/> |
| 348 |
</td> |
| 349 |
</tr> |
| 350 |
<tr> |
| 351 |
<td class="elbow-placeholder"> </td> |
| 352 |
<td colspan="1"> |
| 353 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 354 |
<b>ca_cert</b> |
| 355 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 356 |
<div style="font-size: small"> |
| 357 |
<span style="color: purple">string</span> |
| 358 |
</div> |
| 359 |
</td> |
| 360 |
<td>success</td> |
| 361 |
<td> |
| 362 |
<div>Path to a CA certificate file used to verify connection to the API server.</div> |
| 363 |
<br/> |
| 364 |
</td> |
| 365 |
</tr> |
| 366 |
<tr> |
| 367 |
<td class="elbow-placeholder"> </td> |
| 368 |
<td colspan="1"> |
| 369 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 370 |
<b>host</b> |
| 371 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 372 |
<div style="font-size: small"> |
| 373 |
<span style="color: purple">string</span> |
| 374 |
</div> |
| 375 |
</td> |
| 376 |
<td>success</td> |
| 377 |
<td> |
| 378 |
<div>URL for accessing the API server.</div> |
| 379 |
<br/> |
| 380 |
</td> |
| 381 |
</tr> |
| 382 |
<tr> |
| 383 |
<td class="elbow-placeholder"> </td> |
| 384 |
<td colspan="1"> |
| 385 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 386 |
<b>username</b> |
| 387 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 388 |
<div style="font-size: small"> |
| 389 |
<span style="color: purple">string</span> |
| 390 |
</div> |
| 391 |
</td> |
| 392 |
<td>success</td> |
| 393 |
<td> |
| 394 |
<div>Username for authenticating with the API server.</div> |
| 395 |
<br/> |
| 396 |
</td> |
| 397 |
</tr> |
| 398 |
<tr> |
| 399 |
<td class="elbow-placeholder"> </td> |
| 400 |
<td colspan="1"> |
| 401 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 402 |
<b>validate_certs</b> |
| 403 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 404 |
<div style="font-size: small"> |
| 405 |
<span style="color: purple">boolean</span> |
| 406 |
</div> |
| 407 |
</td> |
| 408 |
<td>success</td> |
| 409 |
<td> |
| 410 |
<div>Whether or not to verify the API server's SSL certificates.</div> |
| 411 |
<br/> |
| 412 |
</td> |
| 413 |
</tr> |
| 414 |
|
| 415 |
</table> |
| 416 |
<br/><br/> |
| 417 |
|
| 418 |
|
| 419 |
Status |
| 420 |
------ |
| 421 |
|
| 422 |
|
| 423 |
Authors |
| 424 |
~~~~~~~ |
| 425 |
|
| 426 |
- KubeVirt Team (@kubevirt) |
| 427 |
- Fabian von Feilitzsch (@fabianvf) |