File: approle.rst

package info (click to toggle)
python-hvac 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: python: 29,360; makefile: 42; sh: 14
file content (88 lines) | stat: -rw-r--r-- 1,651 bytes parent folder | download | duplicates (3)
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
Approle
=======

.. contents::

Enabling
--------

:py:meth:`hvac.api.system_backend.Auth.enable_auth_method`

.. code:: python

    import hvac
    client = hvac.Client()

    client.sys.enable_auth_method(
        method_type='approle',
    )

    # Mount approle auth method under a different path:
    client.sys.enable_auth_method(
        method_type='approle',
        path='my-approle',
    )

Authentication
--------------

:py:meth:`hvac.api.auth_methods.AppRole.login`

.. code:: python

    import hvac
    client = hvac.Client()


    client.auth.approle.login(
        role_id='<some_role_id>',
        secret_id='<some_secret_id>',
    )

Create or Update AppRole
------------------------

:py:meth:`hvac.api.auth_methods.AppRole.create_or_update_approle`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.approle.create_or_update_approle(
        role_name='some-role',
        token_policies=['some-policy'],
        token_type='service,
    )

Read Role ID
------------

:py:meth:`hvac.api.auth_methods.AppRole.read_role_id`

.. code:: python

    import hvac
    client = hvac.Client()

    resp = client.auth.approle.read_role_id(
        role_name='some-role',
    )
    print(f'AppRole role ID for some-role: {resp["data"]["role_id"]}')


Generate Secret ID
------------------

:py:meth:`hvac.api.auth_methods.AppRole.generate_secret_id`

.. code:: python

    import hvac
    client = hvac.Client()

    resp = client.auth.approle.generate_secret_id(
        role_name='some-role',
        cidr_list=['127.0.0.1/32'],
    )
    print(f'AppRole secret ID for some-role: {resp["data"]["secret_id"]}')