Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
3e384db7
Commit
3e384db7
authored
Mar 25, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
service: add basic security policy types.
parent
2ea65420
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
ansible_mitogen/helpers.py
ansible_mitogen/helpers.py
+0
-1
mitogen/service.py
mitogen/service.py
+30
-0
No files found.
ansible_mitogen/helpers.py
View file @
3e384db7
...
...
@@ -250,7 +250,6 @@ def write_path(path, s):
open
(
path
,
'wb'
).
write
(
s
)
CHMOD_CLAUSE_PAT
=
re
.
compile
(
r'([uoga]*)([+\
-=])([ugo]|[
rwx]*)'
)
CHMOD_MASKS
=
{
'u'
:
stat
.
S_IRWXU
,
...
...
mitogen/service.py
View file @
3e384db7
...
...
@@ -35,6 +35,25 @@ import mitogen.master
from
mitogen.core
import
LOG
class
Policy
(
object
):
"""
Base security policy.
"""
def
is_authorized
(
self
,
service
,
msg
):
raise
NotImplementedError
()
class
AllowAny
(
Policy
):
def
is_authorized
(
self
,
service
,
msg
):
return
True
class
AllowParents
(
Policy
):
def
is_authorized
(
self
,
service
,
msg
):
return
(
msg
.
auth_id
in
mitogen
.
parent_ids
or
msg
.
auth_id
==
mitogen
.
context_id
)
class
Service
(
object
):
#: Sentinel object to suppress reply generation, since returning ``None``
#: will trigger a response message containing the pickled ``None``.
...
...
@@ -50,6 +69,12 @@ class Service(object):
#: requests.
required_args
=
{}
#: Policies that must authorize each message. By default only parents are
#: authorized.
policies
=
(
AllowParents
(),
)
def
__init__
(
self
,
router
):
self
.
router
=
router
self
.
recv
=
mitogen
.
core
.
Receiver
(
router
,
self
.
handle
)
...
...
@@ -68,6 +93,11 @@ class Service(object):
raise
NotImplementedError
()
def
dispatch_one
(
self
,
msg
):
if
not
all
(
p
.
is_authorized
(
self
,
msg
)
for
p
in
self
.
policies
):
LOG
.
error
(
'%r: unauthorized message %r'
,
self
,
msg
)
msg
.
reply
(
mitogen
.
core
.
CallError
(
'Unauthorized'
))
return
if
len
(
msg
.
data
)
>
self
.
max_message_size
:
LOG
.
error
(
'%r: larger than permitted size: %r'
,
self
,
msg
)
msg
.
reply
(
mitogen
.
core
.
CallError
(
'Message size exceeded'
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment