mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Remove passwords when running commands including stdout and stderr
This replaces the old no logging mechanism that only handled not logging passwords passed on the command-line. The dogtag installer was including passwords in the output. This also adds no password logging to the sslget invocations and removes a couple of extraneous log commands. ticket 156
This commit is contained in:
@@ -99,21 +99,19 @@ def run(args, stdin=None, raiseonerr=True, nolog=()):
|
|||||||
|
|
||||||
raiseonerr raises an exception if the return code is not zero
|
raiseonerr raises an exception if the return code is not zero
|
||||||
|
|
||||||
nolog is a tuple of tuple values that describes things in the argument
|
nolog is a tuple of strings that shouldn't be logged, like passwords.
|
||||||
list that shouldn't be logged, like passwords. Each tuple consists of
|
Each tuple consists of a string to be replaced by XXXXXXXX.
|
||||||
a value to search for in the argument list and an offset from this
|
|
||||||
location to set to XXX.
|
|
||||||
|
|
||||||
For example, the command ['/usr/bin/setpasswd', '--password', 'Secret123', 'someuser']
|
For example, the command ['/usr/bin/setpasswd', '--password', 'Secret123', 'someuser']
|
||||||
|
|
||||||
We don't want to log the password so nolog would be set to:
|
We don't want to log the password so nolog would be set to:
|
||||||
(('--password', 1),)
|
('Secret123',)
|
||||||
|
|
||||||
The resulting log output would be:
|
The resulting log output would be:
|
||||||
|
|
||||||
/usr/bin/setpasswd --password XXXXXXXX someuser
|
/usr/bin/setpasswd --password XXXXXXXX someuser
|
||||||
|
|
||||||
If an argument isn't found in the list it is silently ignored.
|
If an value isn't found in the list it is silently ignored.
|
||||||
"""
|
"""
|
||||||
if stdin:
|
if stdin:
|
||||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
@@ -122,20 +120,19 @@ def run(args, stdin=None, raiseonerr=True, nolog=()):
|
|||||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
|
||||||
stdout,stderr = p.communicate()
|
stdout,stderr = p.communicate()
|
||||||
|
|
||||||
# The command may include passwords that we don't want to log. Run through
|
# The command and its output may include passwords that we don't want
|
||||||
# the nolog items
|
* to log. Run through the nolog items.
|
||||||
for (item, offset) in nolog:
|
args = ' '.join(args)
|
||||||
try:
|
for value in nolog:
|
||||||
item_offset = args.index(item) + offset
|
args = args.replace(value, 'XXXXXXXX')
|
||||||
args[item_offset] = 'XXXXXXXX'
|
stdout = stdout.replace(value, 'XXXXXXXX')
|
||||||
except ValueError:
|
stderr = stderr.replace(value, 'XXXXXXXX')
|
||||||
pass
|
logging.info('args=%s' % args)
|
||||||
logging.info('args=%s' % ' '.join(args))
|
|
||||||
logging.info('stdout=%s' % stdout)
|
logging.info('stdout=%s' % stdout)
|
||||||
logging.info('stderr=%s' % stderr)
|
logging.info('stderr=%s' % stderr)
|
||||||
|
|
||||||
if p.returncode != 0 and raiseonerr:
|
if p.returncode != 0 and raiseonerr:
|
||||||
raise CalledProcessError(p.returncode, ' '.join(args))
|
raise CalledProcessError(p.returncode, args)
|
||||||
|
|
||||||
return (stdout, stderr, p.returncode)
|
return (stdout, stderr, p.returncode)
|
||||||
|
|
||||||
|
|||||||
@@ -580,15 +580,8 @@ class CAInstance(service.Service):
|
|||||||
args.append("false")
|
args.append("false")
|
||||||
|
|
||||||
# Define the things we don't want logged
|
# Define the things we don't want logged
|
||||||
nolog = (('-client_certdb_pwd', 1),
|
nolog = (self.admin_password, self.dm_password,)
|
||||||
('-admin_password', 1),
|
|
||||||
('-bind_password', 1),
|
|
||||||
('-backup_pwd', 1),
|
|
||||||
('-clone_p12_password', 1),
|
|
||||||
('-sd_admin_password', 1),
|
|
||||||
)
|
|
||||||
|
|
||||||
logging.debug(args)
|
|
||||||
ipautil.run(args, nolog=nolog)
|
ipautil.run(args, nolog=nolog)
|
||||||
|
|
||||||
if self.external == 1:
|
if self.external == 1:
|
||||||
@@ -682,8 +675,7 @@ class CAInstance(service.Service):
|
|||||||
'-r', '/ca/agent/ca/profileReview?requestId=%s' % self.requestId,
|
'-r', '/ca/agent/ca/profileReview?requestId=%s' % self.requestId,
|
||||||
'%s:%d' % (self.host_name, AGENT_SECURE_PORT),
|
'%s:%d' % (self.host_name, AGENT_SECURE_PORT),
|
||||||
]
|
]
|
||||||
logging.debug("running sslget %s" % args)
|
(stdout, stderr, returncode) = ipautil.run(args, nolog=(self.admin_password,))
|
||||||
(stdout, stderr, returncode) = ipautil.run(args)
|
|
||||||
|
|
||||||
data = stdout.split('\r\n')
|
data = stdout.split('\r\n')
|
||||||
params = get_defList(data)
|
params = get_defList(data)
|
||||||
@@ -703,8 +695,7 @@ class CAInstance(service.Service):
|
|||||||
'-r', '/ca/agent/ca/profileProcess',
|
'-r', '/ca/agent/ca/profileProcess',
|
||||||
'%s:%d' % (self.host_name, AGENT_SECURE_PORT),
|
'%s:%d' % (self.host_name, AGENT_SECURE_PORT),
|
||||||
]
|
]
|
||||||
logging.debug("running sslget %s" % args)
|
(stdout, stderr, returncode) = ipautil.run(args, nolog=(self.admin_password,))
|
||||||
(stdout, stderr, returncode) = ipautil.run(args)
|
|
||||||
|
|
||||||
data = stdout.split('\r\n')
|
data = stdout.split('\r\n')
|
||||||
outputList = get_outputList(data)
|
outputList = get_outputList(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user