Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-mailman-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
ai3
tools
python-mailman-api
Commits
0cba5f55
Commit
0cba5f55
authored
6 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add tls auth initialization
parent
82fbfd14
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mailman_api/mailman.py
+4
-2
4 additions, 2 deletions
mailman_api/mailman.py
mailman_api/tls_auth.py
+11
-3
11 additions, 3 deletions
mailman_api/tls_auth.py
with
15 additions
and
5 deletions
mailman_api/mailman.py
+
4
−
2
View file @
0cba5f55
...
...
@@ -5,8 +5,8 @@ import subprocess
from
functools
import
wraps
from
flask
import
Flask
,
request
,
abort
from
.sso_api
import
sso_api_auth_required
from
.tls_auth
import
tls_auth
from
.sso_api
import
sso_api_auth_required
,
init_sso
from
.tls_auth
import
tls_auth
,
init_tls_auth
### TLS authentication.
...
...
@@ -138,6 +138,8 @@ def main():
parser
.
error
(
'
Too many arguments
'
)
app
.
config
.
from_pyfile
(
opts
.
config
)
init_sso
(
app
)
init_tls_auth
(
app
)
serve_ssl
(
app
)
...
...
This diff is collapsed.
Click to expand it.
mailman_api/tls_auth.py
+
11
−
3
View file @
0cba5f55
...
...
@@ -26,6 +26,15 @@ class PeerCertWSGIRequestHandler(werkzeug.serving.WSGIRequestHandler):
return
environ
def
init_tls_auth
(
app
):
compiled
=
[]
for
acl_path
,
acl_cn_pattern
in
app
.
config
.
get
(
'
TLS_AUTH_ACLS
'
,
DEFAULT_TLS_AUTH_ACLS
):
acl_cn_rx
=
re
.
compile
(
'
^%s$
'
%
acl_cn_pattern
)
compiled
.
append
((
acl_path
,
acl_cn_rx
))
app
.
tls_auth_acls
=
compiled
def
_get_subject_cn
(
peercert
):
"""
Extract subject CN from the parsed peercert data.
"""
parsed_subject
=
peercert
[
'
subject
'
]
...
...
@@ -38,8 +47,7 @@ def _get_subject_cn(peercert):
def
_regexp_match
(
rx
,
s
):
"""
Returns True if the anchored rx matches s.
"""
res
=
re
.
match
(
'
^%s$
'
%
rx
,
s
)
return
res
is
not
None
return
rx
.
match
(
s
)
is
not
None
def
tls_auth
(
fn
):
...
...
@@ -47,7 +55,7 @@ def tls_auth(fn):
@wraps
(
fn
)
def
_tls_auth_wrapper
(
*
args
,
**
kwargs
):
cn
=
_get_subject_cn
(
request
.
environ
[
'
peercert
'
])
for
acl_path
,
acl_cn_rx
in
current_app
.
config
.
get
(
'
TLS_AUTH_ACLS
'
,
[])
:
for
acl_path
,
acl_cn_rx
in
current_app
.
tls_auth_acls
:
if
request
.
path
.
startswith
(
acl_path
)
and
_regexp_match
(
acl_cn_rx
,
cn
):
return
fn
(
*
args
,
**
kwargs
)
abort
(
403
)
...
...
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