@@ -4,61 +4,27 @@ Examples
4
4
.. toctree ::
5
5
:maxdepth: 4
6
6
7
- audit
7
+ system_backend
8
+ token_auth_method
8
9
aws
9
- sys
10
+ gcp
11
+ kubernetes_auth_method
12
+ approle_auth_method
13
+ ldap_auth_method
10
14
11
15
12
16
Authenticate to different auth backends
13
17
---------------------------------------
14
18
15
19
.. code :: python
16
20
17
- # Token
18
- client.token = ' MY_TOKEN'
19
- assert client.is_authenticated() # => True
20
21
21
22
# App ID
22
23
client.auth_app_id(' MY_APP_ID' , ' MY_USER_ID' )
23
24
24
- # App Role
25
- client.auth_approle(' MY_ROLE_ID' , ' MY_SECRET_ID' )
26
-
27
- # AWS (IAM)
28
- client.auth_aws_iam(' MY_AWS_ACCESS_KEY_ID' , ' MY_AWS_SECRET_ACCESS_KEY' )
29
- client.auth_aws_iam(' MY_AWS_ACCESS_KEY_ID' , ' MY_AWS_SECRET_ACCESS_KEY' , ' MY_AWS_SESSION_TOKEN' )
30
- client.auth_aws_iam(' MY_AWS_ACCESS_KEY_ID' , ' MY_AWS_SECRET_ACCESS_KEY' , role = ' MY_ROLE' )
31
-
32
- import boto3
33
- session = boto3.Session()
34
- credentials = session.get_credentials()
35
- client.auth_aws_iam(credentials.access_key, credentials.secret_key, credentials.token)
36
-
37
25
# GitHub
38
26
client.auth_github(' MY_GITHUB_TOKEN' )
39
27
40
- # GCP (from GCE instance)
41
- import requests
42
-
43
- VAULT_ADDR = " https://vault.example.com:8200"
44
- ROLE = " example"
45
- AUDIENCE_URL = VAULT_ADDR + " /vault/" + ROLE
46
- METADATA_HEADERS = {' Metadata-Flavor' : ' Google' }
47
- FORMAT = ' full'
48
-
49
- url = ' http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience={} &format={} ' .format(AUDIENCE_URL , FORMAT )
50
- r = requests.get(url, headers = METADATA_HEADERS )
51
- client.auth_gcp(ROLE , r.text)
52
-
53
- # Kubernetes (from k8s pod)
54
- f = open (' /var/run/secrets/kubernetes.io/serviceaccount/token' )
55
- jwt = f.read()
56
- client.auth_kubernetes(" example" , jwt)
57
-
58
- # LDAP, Username & Password
59
- client.auth_ldap(' MY_USERNAME' , ' MY_PASSWORD' )
60
- client.auth_userpass(' MY_USERNAME' , ' MY_PASSWORD' )
61
-
62
28
# TLS
63
29
client = Client(cert = (' path/to/cert.pem' , ' path/to/key.pem' ))
64
30
client.auth_tls()
@@ -81,94 +47,3 @@ Authenticate to different auth backends
81
47
82
48
# Logout
83
49
client.logout()
84
-
85
- Manage tokens
86
- -------------
87
-
88
- .. code :: python
89
-
90
- token = client.create_token(policies = [' root' ], lease = ' 1h' )
91
-
92
- current_token = client.lookup_token()
93
- some_other_token = client.lookup_token(' xxx' )
94
-
95
- client.revoke_token(' xxx' )
96
- client.revoke_token(' yyy' , orphan = True )
97
-
98
- client.revoke_token_prefix(' zzz' )
99
-
100
- client.renew_token(' aaa' )
101
-
102
- Managing tokens using accessors
103
- -------------------------------
104
-
105
- .. code :: python
106
-
107
- token = client.create_token(policies = [' root' ], lease = ' 1h' )
108
- token_accessor = token[' auth' ][' accessor' ]
109
-
110
- same_token = client.lookup_token(token_accessor, accessor = True )
111
- client.revoke_token(token_accessor, accessor = True )
112
-
113
- Wrapping/unwrapping a token
114
- ---------------------------
115
-
116
- .. code :: python
117
-
118
- wrap = client.create_token(policies = [' root' ], lease = ' 1h' , wrap_ttl = ' 1m' )
119
- result = self .client.unwrap(wrap[' wrap_info' ][' token' ])
120
-
121
- Manipulate auth backends
122
- ------------------------
123
-
124
- .. code :: python
125
-
126
- backends = client.list_auth_backends()
127
-
128
- client.enable_auth_backend(' userpass' , mount_point = ' customuserpass' )
129
- client.disable_auth_backend(' github' )
130
-
131
- Manipulate secret backends
132
- --------------------------
133
-
134
- .. code :: python
135
-
136
- backends = client.list_secret_backends()
137
-
138
- client.enable_secret_backend(' aws' , mount_point = ' aws-us-east-1' )
139
- client.disable_secret_backend(' mysql' )
140
-
141
- client.tune_secret_backend(' generic' , mount_point = ' test' , default_lease_ttl = ' 3600s' , max_lease_ttl = ' 8600s' )
142
- client.get_secret_backend_tuning(' generic' , mount_point = ' test' )
143
-
144
- client.remount_secret_backend(' aws-us-east-1' , ' aws-east' )
145
-
146
- Manipulate policies
147
- -------------------
148
-
149
- .. code :: python
150
-
151
- policies = client.list_policies() # => ['root']
152
-
153
- policy = """
154
- path "sys" {
155
- policy = "deny"
156
- }
157
-
158
- path "secret" {
159
- policy = "write"
160
- }
161
-
162
- path "secret/foo" {
163
- policy = "read"
164
- }
165
- """
166
-
167
- client.set_policy(' myapp' , policy)
168
-
169
- client.delete_policy(' oldthing' )
170
-
171
- policy = client.get_policy(' mypolicy' )
172
-
173
- # Requires pyhcl to automatically parse HCL into a Python dictionary
174
- policy = client.get_policy(' mypolicy' , parse = True )
0 commit comments