Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
strudel2_backend
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
Container Registry
Model registry
Operate
Environments
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-team
strudel2_backend
Commits
418f2449
Commit
418f2449
authored
4 years ago
by
Chris Hines
Browse files
Options
Downloads
Patches
Plain Diff
support the use of teh Authentcation header instead of a cookie to find the right port
parent
939c4198
Loading
Loading
3 merge requests
!77
Revert "disable agressive kill and restart"
,
!64
Test
,
!63
Dev
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tes/__init__.py
+9
-2
9 additions, 2 deletions
tes/__init__.py
tes/apiendpoints.py
+7
-1
7 additions, 1 deletion
tes/apiendpoints.py
twsproxy/__init__.py
+15
-0
15 additions, 0 deletions
twsproxy/__init__.py
with
31 additions
and
3 deletions
tes/__init__.py
+
9
−
2
View file @
418f2449
...
...
@@ -37,6 +37,8 @@ from . import apiendpoints
def
after_cleanup_sessions
(
response
):
import
logging
logger
=
logging
.
getLogger
()
slist
=
[]
klist
=
[]
try
:
sshsessid
=
session
.
get
(
'
sshsessid
'
,
None
)
...
...
@@ -49,8 +51,13 @@ def after_cleanup_sessions(response):
for
k
,
sshsess
in
list
(
sshsessions
.
items
()):
if
datetime
.
datetime
.
now
()
>
sshsess
.
last
+
ttl
:
logger
.
debug
(
"
session last seen at {} now {}
"
.
format
(
sshsess
.
last
,
datetime
.
datetime
.
now
()))
sshsess
.
kill
()
del
sshsessions
[
k
]
slist
.
append
(
sshsess
)
klist
.
append
(
k
)
# Two keys may point at the same session. In particular an authentication token and our twsproxyauth cookie can both identify a session
for
k
in
klist
:
del
sshsessions
[
k
]
for
s
in
slist
:
s
.
kill
()
except
:
logger
.
error
(
'
failed to cleanup old sessions
'
)
...
...
This diff is collapsed.
Click to expand it.
tes/apiendpoints.py
+
7
−
1
View file @
418f2449
...
...
@@ -448,7 +448,10 @@ class AppUrl(Resource):
class
SetTWSProxyAuth
(
Resource
):
def
get
(
self
,
authtok
):
import
urllib.parse
import
logging
logger
=
logging
.
getLogger
()
url
=
urllib
.
parse
.
unquote
(
request
.
args
.
get
(
'
redirect
'
))
logger
.
debug
(
'
SetTWSProxyAuth will redirect to {}
'
.
format
(
url
))
response
=
make_response
(
redirect
(
url
))
response
.
set_cookie
(
'
twsproxyauth
'
,
authtok
,
secure
=
True
)
return
response
...
...
@@ -552,7 +555,10 @@ class CreateTunnel(Resource):
else
:
localbind
=
True
sshsess
=
SSHSession
.
get_sshsession
()
authtok
=
gen_authtok
()
if
'
authtok
'
in
data
:
authtok
=
data
[
'
authtok
'
]
else
:
authtok
=
gen_authtok
()
port
,
pids
=
Ssh
.
tunnel
(
sshsess
,
port
=
port
,
batchhost
=
batchhost
,
user
=
username
,
host
=
loginhost
,
internalfirewall
=
firewall
,
...
...
This diff is collapsed.
Click to expand it.
twsproxy/__init__.py
+
15
−
0
View file @
418f2449
...
...
@@ -97,9 +97,24 @@ class TWSProxy(threading.Thread):
@staticmethod
def
verifyauth
(
header
):
# We are looking for either
# 1. An Authentication header that we can map to an ssh session
# 2. A cookie called twsproxyauth that we can make to an ssh sesssion
import
re
import
requests
logger
=
logging
.
getLogger
()
token
=
b
'
Authentication: (?P<authtok>\w+)[\W|$]
'
m
=
re
.
search
(
token
,
header
)
if
m
:
authtok
=
m
.
groupdict
()[
'
authtok
'
]
s
=
requests
.
Session
()
url
=
TES
+
'
tunnelstat/
'
+
authtok
.
decode
()
try
:
r
=
s
.
get
(
url
)
port
=
r
.
json
()
except
:
raise
Exception
(
'
unable to get a port number for the authtok {}
'
.
format
(
r
.
text
))
return
port
token
=
b
'
twsproxyauth=(?P<authtok>\w+)[\W|$]
'
m
=
re
.
search
(
token
,
header
)
if
m
:
...
...
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