Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.backend.python
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
beat
beat.backend.python
Commits
7b9b4bac
Commit
7b9b4bac
authored
7 years ago
by
Philip ABBET
Browse files
Options
Downloads
Patches
Plain Diff
Change the way UIDs are handled
parent
4871700b
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
beat/backend/python/helpers.py
+1
-0
1 addition, 0 deletions
beat/backend/python/helpers.py
beat/backend/python/scripts/execute.py
+66
-28
66 additions, 28 deletions
beat/backend/python/scripts/execute.py
with
67 additions
and
28 deletions
beat/backend/python/helpers.py
+
1
−
0
View file @
7b9b4bac
...
...
@@ -44,6 +44,7 @@ def convert_experiment_configuration_to_container(config, proxy_mode):
'
algorithm
'
:
config
[
'
algorithm
'
],
'
parameters
'
:
config
[
'
parameters
'
],
'
channel
'
:
config
[
'
channel
'
],
'
uid
'
:
os
.
getuid
(),
}
if
'
range
'
in
config
:
...
...
This diff is collapsed.
Click to expand it.
beat/backend/python/scripts/execute.py
100644 → 100755
+
66
−
28
View file @
7b9b4bac
...
...
@@ -54,6 +54,8 @@ import sys
import
docopt
import
pwd
import
stat
import
simplejson
import
subprocess
import
zmq
...
...
@@ -69,6 +71,9 @@ class UserError(Exception):
return
repr
(
self
.
value
)
#----------------------------------------------------------
def
send_error
(
logger
,
socket
,
tp
,
message
):
"""
Sends a user (usr) or system (sys) error message to the infrastructure
"""
...
...
@@ -98,6 +103,19 @@ def send_error(logger, socket, tp, message):
logger
.
error
(
'
stopping 0MQ client anyway
'
)
#----------------------------------------------------------
def
close
(
logger
,
socket
,
context
):
socket
.
setsockopt
(
zmq
.
LINGER
,
0
)
socket
.
close
()
context
.
term
()
logger
.
debug
(
"
0MQ client finished
"
)
#----------------------------------------------------------
def
main
():
"""
...
...
@@ -113,6 +131,7 @@ def main():
args
=
docopt
.
docopt
(
__doc__
%
dict
(
prog
=
prog
,
version
=
version
),
version
=
version
)
# Sets up the logging system
if
args
[
'
--debug
'
]:
logging
.
basicConfig
(
format
=
'
[remote|%(name)s] %(levelname)s: %(message)s
'
,
...
...
@@ -123,13 +142,37 @@ def main():
logger
=
logging
.
getLogger
(
__name__
)
# Attempt to change to an user with less privileges
try
:
# First determine if the user exists. If not, none of the following lines will
# be executed
newuid
=
pwd
.
getpwnam
(
'
beat-nobody
'
).
pw_uid
# Next, ensure that the needed files are readable by the 'beat-nobody' user
# Creates the 0MQ socket for communication with BEAT
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
PAIR
)
address
=
args
[
'
<addr>
'
]
socket
.
connect
(
address
)
logger
.
debug
(
"
zmq client connected to `%s
'"
,
address
)
# Check the dir
if
not
os
.
path
.
exists
(
args
[
'
<dir>
'
]):
send_error
(
logger
,
socket
,
'
sys
'
,
"
Running directory `%s
'
not found
"
%
args
[
'
<dir>
'
])
close
(
logger
,
socket
,
context
)
return
1
# Create a new user with less privileges
with
open
(
os
.
path
.
join
(
args
[
'
<dir>
'
],
'
configuration.json
'
),
'
r
'
)
as
f
:
cfg
=
simplejson
.
load
(
f
)
retcode
=
subprocess
.
call
([
'
adduser
'
,
'
--uid
'
,
str
(
cfg
[
'
uid
'
]),
'
--no-create-home
'
,
'
--disabled-password
'
,
'
--disabled-login
'
,
'
--gecos
'
,
'""'
,
'
-q
'
,
'
beat-nobody
'
])
if
retcode
!=
0
:
send_error
(
logger
,
socket
,
'
sys
'
,
'
Failed to create an user with the UID %d
'
%
cfg
[
'
uid
'
])
close
(
logger
,
socket
,
context
)
return
1
# Ensure that the needed files are readable by the new user
access
=
stat
.
S_IRUSR
|
stat
.
S_IWUSR
|
stat
.
S_IXUSR
|
stat
.
S_IRGRP
|
stat
.
S_IXGRP
|
stat
.
S_IROTH
|
stat
.
S_IXOTH
os
.
chmod
(
args
[
'
<dir>
'
],
access
)
...
...
@@ -140,24 +183,19 @@ def main():
for
f
in
files
:
os
.
chmod
(
os
.
path
.
join
(
root
,
f
),
access
)
# Change the user
os
.
setuid
(
newuid
)
except
:
pass
# Creates the 0MQ socket for communication with BEAT
context
=
zmq
.
Context
()
socket
=
context
.
socket
(
zmq
.
PAIR
)
address
=
args
[
'
<addr>
'
]
socket
.
connect
(
address
)
logger
.
debug
(
"
zmq client connected to `%s
'"
,
address
)
# Change to the user with less privileges
try
:
os
.
setgid
(
cfg
[
'
uid
'
])
os
.
setuid
(
cfg
[
'
uid
'
])
except
:
import
traceback
send_error
(
logger
,
socket
,
'
sys
'
,
traceback
.
format_exc
())
close
(
logger
,
socket
,
context
)
return
1
# Check the dir
if
not
os
.
path
.
exists
(
args
[
'
<dir>
'
]):
raise
IOError
(
"
Running directory `%s
'
not found
"
%
args
[
'
<dir>
'
])
try
:
# Sets up the execution
executor
=
Executor
(
socket
,
args
[
'
<dir>
'
])
...
...
@@ -210,13 +248,13 @@ def main():
return
1
finally
:
socket
.
setsockopt
(
zmq
.
LINGER
,
0
)
socket
.
close
()
context
.
term
()
logger
.
debug
(
"
0MQ client finished
"
)
close
(
logger
,
socket
,
context
)
return
0
#----------------------------------------------------------
if
__name__
==
'
__main__
'
:
sys
.
exit
(
main
())
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