File: okta.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 (203 lines) | stat: -rw-r--r-- 4,613 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
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
193
194
195
196
197
198
199
200
201
202
203
Okta
====

.. note::
    Every method under the :py:attr:`Client class's okta attribute<hvac.v1.Client.okta>` includes a `mount_point` parameter that can be used to address the Okta auth method under a custom mount path. E.g., If enabling the Okta auth method using Vault's CLI commands via `vault secret enable -path=my-okta okta`", the `mount_point` parameter in Source reference: :py:meth:`hvac.api.auth_methods.Okta` methods would be set to "my-okta".

Enabling the Auth Method
------------------------

Source reference: :py:meth:`hvac.v1.client.sys.enable_secrets_engine`

.. code:: python

    import hvac
    client = hvac.Client()

    okta_path = 'company-okta'
    description = 'Auth method for use by team members in our company's Okta organization'

    if '%s/' % okta_path not in vault_client.sys.list_auth_methods()['data']:
        print('Enabling the okta secret backend at mount_point: {path}'.format(
            path=okta_secret_path,
        ))
        client.sys.enable_auth_method(
            method_type='okta',
            description=description,
            path=okta_secret_path,
        )


Configure
---------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.configure`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.okta.configure(
        org_name='hvac-project'
    )

Read Config
-------------------------------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.read_config`

.. code:: python

    import hvac
    client = hvac.Client()

    okta_config = client.auth.okta.read_config()
    print('The Okta auth method at path /okta has a configured organization name of: {name}'.format(
        name=okta_config['data']['org_name'],
    ))

List Users
----------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.list_users`

.. code:: python

    import hvac
    client = hvac.Client()

    users = client.auth.okta.list_users()
    print('The following Okta users are registered: {users}'.format(
        users=','.join(users['data']['keys']),
    ))

Register User
-------------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.register_user`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.okta.register_user(
        username='hvac-person',
        policies=['hvac-admin'],
    )

Read User
---------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.read_user`

.. code:: python

    import hvac
    client = hvac.Client()

    read_user = client.auth.okta.read_user(
        username='hvac-person',
    )
    print('Okta user "{name}" has the following attached policies: {policies}'.format(
        name='hvac-person',
        policies=', '.join(read_user['data']['policies'],
    ))

Delete User
-----------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.delete_user`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.okta.delete_user(
        username='hvac-person'
    )

List Groups
-----------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.list_groups`

.. code:: python

    import hvac
    client = hvac.Client()

    groups = client.auth.okta.list_groups()
    print('The following Okta groups are registered: {groups}'.format(
        groups=','.join(groups['data']['keys']),
    ))

Register Group
--------------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.register_group`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.okta.register_group(
        name='hvac-group',
        policies=['hvac-group-members'],
    )

Read Group
----------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.read_group`

.. code:: python

    import hvac
    client = hvac.Client()

    read_group = client.auth.okta.read_group(
        name='hvac-group',
    )
    print('Okta group "{name}" has the following attached policies: {policies}'.format(
        name='hvac-group',
        policies=', '.join(read_group['data']['policies'],
    ))

Delete Group
------------

Source reference: :py:meth:`hvac.api.auth_methods.Okta.delete_group`

.. code:: python

    import hvac
    client = hvac.Client()

    client.auth.okta.delete_group(
        name='hvac-group',
    )

Login
-----

Source reference: :py:meth:`hvac.api.auth_methods.Okta.login`

.. code:: python

    from getpass import getpass

    import hvac
    client = hvac.Client()


    password_prompt = 'Please enter your password for the Okta authentication backend: '
    okta_password = getpass(prompt=password_prompt)

    client.auth.okta.login(
        username='hvac-person',
        password=okta_password,
    )