Skip to content

Commit 8ef0dc8

Browse files
simo5frozencemetery
authored andcommitted
Emit error in logs if keytab files can't be opened
This will give a useful warning to admins when config point to missing files. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent 731761e commit 8ef0dc8

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

src/mod_auth_gssapi.c

+17
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,23 @@ static const char *mag_cred_store(cmd_parms *parms, void *mconfig,
15321532
}
15331533
cfg->cred_store->count++;
15341534

1535+
/* check for files that we know should be present, so admins get
1536+
* some rope to figure out issues when they cannot be accessed */
1537+
if (strcmp(key, "keytab") == 0 ||
1538+
strcmp(key, "client_keytab") == 0) {
1539+
apr_status_t rc;
1540+
apr_file_t *file;
1541+
rc = apr_file_open(&file, value, APR_FOPEN_READ, 0, parms->pool);
1542+
if (rc != APR_SUCCESS) {
1543+
char err[256];
1544+
apr_strerror(rc, err, sizeof(err));
1545+
ap_log_error(APLOG_MARK, APLOG_ERR, 0, parms->server,
1546+
"Cannot open %s file %s: %s", key, value, err);
1547+
} else {
1548+
apr_file_close(file);
1549+
}
1550+
}
1551+
15351552
elements[count].key = key;
15361553
elements[count].value = value;
15371554

tests/httpd.conf

+13
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,16 @@ CoreDumpDirectory "{HTTPROOT}"
346346
GssapiPublishMech On
347347
Require valid-user
348348
</Location>
349+
350+
<Location /keytab_file_check>
351+
AuthType GSSAPI
352+
AuthName "Password Login"
353+
GssapiSSLonly Off
354+
GssapiCredStore ccache:{HTTPROOT}/tmp/httpd_krb5_ccache
355+
GssapiCredStore client_keytab:{HTTPROOT}/nofile/http.keytab
356+
GssapiCredStore keytab:{HTTPROOT}/nofile/http.keytab
357+
GssapiBasicAuth On
358+
GssapiBasicAuthMech krb5
359+
GssapiPublishMech On
360+
Require valid-user
361+
</Location>

tests/magtests.py

+23
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def setup_http(testdir, so_dir, wrapenv):
410410
os.mkdir(os.path.join(httpdir, 'conf.d'))
411411
os.mkdir(os.path.join(httpdir, 'html'))
412412
os.mkdir(os.path.join(httpdir, 'logs'))
413+
httpdstdlog = os.path.join(testdir, 'httpd.stdlog')
413414

414415
distro = "Fedora"
415416
moddir = "/etc/httpd/modules"
@@ -443,7 +444,9 @@ def setup_http(testdir, so_dir, wrapenv):
443444
})
444445

445446
httpd = "httpd" if distro == "Fedora" else "apache2"
447+
log = open(httpdstdlog, 'a')
446448
httpproc = subprocess.Popen([httpd, '-DFOREGROUND', '-f', config],
449+
stdout=log, stderr=log,
447450
env=httpenv, preexec_fn=os.setsid)
448451
return httpproc
449452

@@ -782,7 +785,9 @@ def http_restart(testdir, so_dir, testenv):
782785

783786
httpd = "httpd" if os.path.exists("/etc/httpd/modules") else "apache2"
784787
config = os.path.join(testdir, 'httpd', 'httpd.conf')
788+
log = open(os.path.join(testdir, 'httpd.stdlog'), 'a')
785789
httpproc = subprocess.Popen([httpd, '-DFOREGROUND', '-f', config],
790+
stdout=log, stderr=log,
786791
env=httpenv, preexec_fn=os.setsid)
787792
return httpproc
788793

@@ -803,6 +808,22 @@ def test_mech_name(testdir, testenv, logfile):
803808
return 0
804809

805810

811+
def test_file_check(testdir, testenv, logfile):
812+
basicdir = os.path.join(testdir, 'httpd', 'html', 'keytab_file_check')
813+
os.mkdir(basicdir)
814+
shutil.copy('tests/index.html', basicdir)
815+
816+
filec = subprocess.Popen(["tests/t_file_check.py"],
817+
stdout=logfile, stderr=logfile,
818+
env=testenv, preexec_fn=os.setsid)
819+
filec.wait()
820+
if filec.returncode == 0:
821+
sys.stderr.write('FILE-CHECK: FAILED\n')
822+
return 1
823+
sys.stderr.write('FILE-CHECK: SUCCESS\n')
824+
return 0
825+
826+
806827
if __name__ == '__main__':
807828
args = parse_args()
808829

@@ -872,6 +893,8 @@ def test_mech_name(testdir, testenv, logfile):
872893

873894
errs += test_mech_name(testdir, testenv, logfile)
874895

896+
errs += test_file_check(testdir, testenv, logfile)
897+
875898
# After this point we need to speed up httpd to test creds timeout
876899
try:
877900
fakeenv = faketime_setup(kdcenv)

tests/t_file_check.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
# Copyright (C) 2020 - mod_auth_gssapi contributors, see COPYING for license.
3+
4+
import os
5+
6+
import requests
7+
from requests.auth import HTTPBasicAuth
8+
9+
10+
if __name__ == '__main__':
11+
url = 'http://%s/keytab_file_check/' % os.environ['NSS_WRAPPER_HOSTNAME']
12+
r = requests.get(url, auth=HTTPBasicAuth(os.environ['MAG_USER_NAME'],
13+
os.environ['MAG_USER_PASSWORD']))
14+
if r.status_code != 200:
15+
raise ValueError('Basic Auth Failed(Keytab File Check)')

0 commit comments

Comments
 (0)