summaryrefslogtreecommitdiffstats
path: root/custodia/httpd
diff options
context:
space:
mode:
Diffstat (limited to 'custodia/httpd')
-rw-r--r--custodia/httpd/authenticators.py34
-rw-r--r--custodia/httpd/authorizers.py18
-rw-r--r--custodia/httpd/server.py16
3 files changed, 58 insertions, 10 deletions
diff --git a/custodia/httpd/authenticators.py b/custodia/httpd/authenticators.py
index dbb34bd..bed2bc4 100644
--- a/custodia/httpd/authenticators.py
+++ b/custodia/httpd/authenticators.py
@@ -12,6 +12,7 @@ class HTTPAuthenticator(object):
def __init__(self, config=None):
self.config = config
+ self._auditlog = log.AuditLog(self.config)
def handle(self, request):
raise HTTPError(403)
@@ -32,8 +33,14 @@ class SimpleCredsAuth(HTTPAuthenticator):
uid = int(request['creds']['gid'])
gid = int(request['creds']['uid'])
if self._gid == gid or self._uid == uid:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_PASS,
+ request['creds']['pid'],
+ "SCA", "%d, %d" % (uid, gid))
return True
else:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SCA", "%d, %d" % (uid, gid))
return False
@@ -57,13 +64,25 @@ class SimpleHeaderAuth(HTTPAuthenticator):
pass
elif isinstance(self.value, str):
if value != self.value:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SHA", value)
return False
elif isinstance(self.value, list):
if value not in self.value:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SHA", value)
return False
else:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SHA", value)
return False
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_PASS,
+ request['creds']['pid'],
+ "SHA", value)
request['remote_user'] = value
return True
@@ -77,7 +96,6 @@ class SimpleAuthKeys(HTTPAuthenticator):
self.store_name = self.config['store']
self.store = None
self.namespace = self.config.get('store_namespace', 'custodiaSAK')
- self._auditlog = log.AuditLog(self.config)
def _db_key(self, name):
return os.path.join(self.namespace, name)
@@ -96,14 +114,20 @@ class SimpleAuthKeys(HTTPAuthenticator):
if constant_time.bytes_eq(val.encode('utf-8'),
key.encode('utf-8')):
validated = True
- except Exception as err:
- self._auditlog._log("AUTH ERROR: (%s) %s" % (name, err))
+ except Exception:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SAK", name)
return False
if validated:
- self._auditlog._log("AUTH SUCCESS: %s" % name)
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_PASS,
+ request['creds']['pid'],
+ "SAK", name)
request['remote_user'] = name
return True
- self._auditlog._log("AUTH FAIL: %s" % name)
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'],
+ "SAK", name)
return False
diff --git a/custodia/httpd/authorizers.py b/custodia/httpd/authorizers.py
index dbf3d37..d6fe7c7 100644
--- a/custodia/httpd/authorizers.py
+++ b/custodia/httpd/authorizers.py
@@ -2,11 +2,14 @@
import os
+from custodia import log
+
class HTTPAuthorizer(object):
def __init__(self, config=None):
self.config = config
+ self._auditlog = log.AuditLog(self.config)
self.store_name = None
if self.config and 'store' in self.config:
self.store_name = self.config['store']
@@ -36,10 +39,16 @@ class SimplePathAuthz(HTTPAuthorizer):
# special case to match a path ending in /
authz = authz[:-1]
if authz == path:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_PASS,
+ request['creds']['pid'],
+ "SPA", path)
return True
while path != '':
if path in self.paths:
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_PASS,
+ request['creds']['pid'],
+ "SPA", path)
return True
if path == '/':
path = ''
@@ -63,12 +72,21 @@ class UserNameSpace(HTTPAuthorizer):
name = request.get('remote_user', None)
if name is None:
# UserNameSpace requires a user ...
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_FAIL,
+ request.get('creds', {'pid': 0})['pid'],
+ "UNS(%s)" % self.path, path)
return False
namespace = self.path.rstrip('/') + '/' + name + '/'
if not path.startswith(namespace):
# Not in the namespace
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_FAIL,
+ request.get('creds', {'pid': 0})['pid'],
+ "UNS(%s)" % self.path, path)
return False
request['default_namespace'] = name
+ self._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_PASS,
+ request.get('creds', {'pid': 0})['pid'],
+ "UNS(%s)" % self.path, path)
return True
diff --git a/custodia/httpd/server.py b/custodia/httpd/server.py
index 7a84526..8f02a78 100644
--- a/custodia/httpd/server.py
+++ b/custodia/httpd/server.py
@@ -20,8 +20,7 @@ except ImportError:
from socketserver import ForkingMixIn, UnixStreamServer
from urllib.parse import urlparse, parse_qs, unquote
-from custodia.log import debug as log_debug
-from custodia.log import stacktrace
+from custodia import log
SO_PEERCRED = getattr(socket, 'SO_PEERCRED', 17)
@@ -36,7 +35,7 @@ class HTTPError(Exception):
self.code = code if code is not None else 500
self.mesg = message
errstring = '%d: %s' % (self.code, self.mesg)
- log_debug(errstring)
+ log.debug(errstring)
super(HTTPError, self).__init__(errstring)
@@ -63,6 +62,7 @@ class ForkingLocalHTTPServer(ForkingMixIn, UnixStreamServer):
self.config = config
if 'server_string' in self.config:
self.server_string = self.config['server_string']
+ self._auditlog = log.AuditLog(self.config)
def server_bind(self):
oldmask = os.umask(000)
@@ -144,7 +144,7 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
SELINUX_CONTEXT_LEN)
context = creds.decode('utf-8')
except Exception as e:
- log_debug("Couldn't retrieve SELinux Context: (%s)" % str(e))
+ log.debug("Couldn't retrieve SELinux Context: (%s)" % str(e))
context = None
return {'pid': pid, 'uid': uid, 'gid': gid, 'context': context}
@@ -254,7 +254,7 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
return
def log_traceback(self):
- self.log_error('Traceback:\n%s' % stacktrace())
+ self.log_error('Traceback:\n%s' % log.stacktrace())
def pipeline(self, config, request):
"""
@@ -299,6 +299,9 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
elif valid is True:
valid_once = True
if valid_once is not True:
+ self.server._auditlog.svc_access(log.AUDIT_SVC_AUTH_FAIL,
+ request['creds']['pid'], "MAIN",
+ 'No auth')
raise HTTPError(403)
# auhz framework here
@@ -310,6 +313,9 @@ class LocalHTTPRequestHandler(BaseHTTPRequestHandler):
if valid is not None:
break
if valid is not True:
+ self.server._auditlog.svc_access(log.AUDIT_SVC_AUTHZ_FAIL,
+ request['creds']['pid'], "MAIN",
+ request.get('path', '/'))
raise HTTPError(403)
# Select consumer