Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
2a0028e6
Commit
2a0028e6
authored
Mar 06, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sanitize run_command argument output
Fixes #6316
parent
cd6d7ddc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
lib/ansible/module_utils/basic.py
+28
-3
No files found.
lib/ansible/module_utils/basic.py
View file @
2a0028e6
...
...
@@ -46,6 +46,7 @@ BOOLEANS = BOOLEANS_TRUE + BOOLEANS_FALSE
import
os
import
re
import
pipes
import
shlex
import
subprocess
import
sys
...
...
@@ -1017,6 +1018,30 @@ class AnsibleModule(object):
if
path_prefix
:
env
[
'PATH'
]
=
"
%
s:
%
s"
%
(
path_prefix
,
env
[
'PATH'
])
# create a printable version of the command for use
# in reporting later, which strips out things like
# passwords from the args list
if
isinstance
(
args
,
list
):
clean_args
=
" "
.
join
(
pipes
.
quote
(
arg
)
for
arg
in
args
)
else
:
clean_args
=
args
# all clean strings should return two match groups,
# where the first is the CLI argument and the second
# is the password/key/phrase that will be hidden
clean_re_strings
=
[
# this removes things like --password, --pass, --pass-wd, etc.
# optionally followed by an '=' or a space. The password can
# be quoted or not too, though it does not care about quotes
# that are not balanced
# source: http://blog.stevenlevithan.com/archives/match-quoted-string
r'([-]{0,2}pass[-]?(?:word|wd)?[=\s]?)((?:["\'])?(?:[^\s])*(?:\1)?)'
,
# TODO: add more regex checks here
]
for
re_str
in
clean_re_strings
:
r
=
re
.
compile
(
re_str
)
clean_args
=
r
.
sub
(
r'\1********'
,
clean_args
)
if
data
:
st_in
=
subprocess
.
PIPE
try
:
...
...
@@ -1044,12 +1069,12 @@ class AnsibleModule(object):
out
,
err
=
cmd
.
communicate
(
input
=
data
)
rc
=
cmd
.
returncode
except
(
OSError
,
IOError
),
e
:
self
.
fail_json
(
rc
=
e
.
errno
,
msg
=
str
(
e
),
cmd
=
args
)
self
.
fail_json
(
rc
=
e
.
errno
,
msg
=
str
(
e
),
cmd
=
clean_
args
)
except
:
self
.
fail_json
(
rc
=
257
,
msg
=
traceback
.
format_exc
(),
cmd
=
args
)
self
.
fail_json
(
rc
=
257
,
msg
=
traceback
.
format_exc
(),
cmd
=
clean_
args
)
if
rc
!=
0
and
check_rc
:
msg
=
err
.
rstrip
()
self
.
fail_json
(
cmd
=
args
,
rc
=
rc
,
stdout
=
out
,
stderr
=
err
,
msg
=
msg
)
self
.
fail_json
(
cmd
=
clean_
args
,
rc
=
rc
,
stdout
=
out
,
stderr
=
err
,
msg
=
msg
)
return
(
rc
,
out
,
err
)
def
pretty_bytes
(
self
,
size
):
...
...
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