Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
notebooks-operations
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
702
Projekty
notebooks-operations
Commits
e5497bae
Commit
e5497bae
authored
4 months ago
by
František Dvořák
Browse files
Options
Downloads
Patches
Plain Diff
Python linting
parent
66c78806
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vault-login.py
+30
-22
30 additions, 22 deletions
vault-login.py
with
30 additions
and
22 deletions
vault-login.py
+
30
−
22
View file @
e5497bae
...
...
@@ -8,18 +8,18 @@
import
json
import
os
import
re
import
requests
import
shutil
import
subprocess
import
sys
import
requests
payload
=
{
"
grant_type
"
:
"
client_credentials
"
,
"
scope
"
:
"
openid profile eduperson_entitlement email voperson_id
"
,
}
token_url
=
"
https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/token
"
userinfo_url
=
\
"
https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/userinfo
"
userinfo_url
=
"
https://aai.egi.eu/auth/realms/egi/protocol/openid-connect/userinfo
"
# input
if
"
CLIENT_ID
"
in
os
.
environ
:
...
...
@@ -32,39 +32,47 @@ else:
payload
[
"
client_secret
"
]
=
input
(
"
OIDC Client Secret:
"
)
# get OIDC token
r
=
requests
.
post
(
token_url
,
data
=
payload
)
r
=
requests
.
post
(
token_url
,
data
=
payload
,
timeout
=
20
)
data
=
json
.
loads
(
r
.
text
)
if
'
access_token
'
not
in
data
:
print
(
'
Error getting access token
'
)
if
"
access_token
"
not
in
data
:
print
(
"
Error getting access token
"
)
sys
.
exit
(
1
)
print
(
"
# export OIDC_ACCESS_TOKEN=
'
%s
'"
%
data
[
"
access_token
"
])
# get vault token
token
=
None
p
=
subprocess
.
Popen
([
shutil
.
which
(
"
vault
"
),
"
write
"
,
"
auth/jwt/login
"
,
"
jwt=%s
"
%
data
[
"
access_token
"
],
],
stdout
=
subprocess
.
PIPE
)
for
line
in
p
.
stdout
:
print
(
'
# %s
'
%
line
.
decode
(
"
UTF-8
"
).
rstrip
())
m
=
re
.
search
(
r
'
^token\s+(.*)
'
,
line
.
decode
(
"
UTF-8
"
))
if
m
is
not
None
:
token
=
m
.
group
(
1
)
vaultbin
=
shutil
.
which
(
"
vault
"
)
if
vaultbin
is
None
:
print
(
"
vault command not found
"
)
sys
.
exit
(
1
)
p
=
subprocess
.
Popen
(
[
vaultbin
,
"
write
"
,
"
auth/jwt/login
"
,
"
jwt=%s
"
%
data
[
"
access_token
"
],
],
stdout
=
subprocess
.
PIPE
,
)
if
p
.
stdout
is
not
None
:
for
line
in
p
.
stdout
:
print
(
"
# %s
"
%
line
.
decode
(
"
UTF-8
"
).
rstrip
())
m
=
re
.
search
(
r
"
^token\s+(.*)
"
,
line
.
decode
(
"
UTF-8
"
))
if
m
is
not
None
:
token
=
m
.
group
(
1
)
retval
=
p
.
wait
()
if
token
is
None
:
print
(
'
Error signing to vault (no token returned)
'
)
print
(
"
Error signing to vault (no token returned)
"
)
sys
.
exit
(
1
)
print
(
"
export VAULT_TOKEN=
'
%s
'"
%
token
)
if
retval
!=
0
:
print
(
'
Error signing to vault (code %d returned)
'
%
retval
)
print
(
"
Error signing to vault (code %d returned)
"
%
retval
)
sys
.
exit
(
1
)
# store vault token
token_path
=
os
.
path
.
expanduser
(
'
~/.vault-token
'
)
with
open
(
token_path
,
'
w
'
)
as
f
:
token_path
=
os
.
path
.
expanduser
(
"
~/.vault-token
"
)
with
open
(
token_path
,
"
w
"
)
as
f
:
pass
os
.
chmod
(
token_path
,
0o600
)
with
open
(
token_path
,
'
w
'
)
as
f
:
with
open
(
token_path
,
"
w
"
)
as
f
:
f
.
write
(
token
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment