Skip to content

Emit error in logs if keytab files can't be opened #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/mod_auth_gssapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,23 @@ static const char *mag_cred_store(cmd_parms *parms, void *mconfig,
}
cfg->cred_store->count++;

/* check for files that we know should be present, so admins get
* some rope to figure out issues when they cannot be accessed */
if (strcmp(key, "keytab") == 0 ||
strcmp(key, "client_keytab") == 0) {
apr_status_t rc;
apr_file_t *file;
rc = apr_file_open(&file, value, APR_FOPEN_READ, 0, parms->pool);
if (rc != APR_SUCCESS) {
char err[256];
apr_strerror(rc, err, sizeof(err));
ap_log_error(APLOG_MARK, APLOG_ERR, 0, parms->server,
"Cannot open %s file %s: %s", key, value, err);
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this error cause a function exit, like we do above? (That would also let you remove this else-block.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no
I want the thing not to crash the apache server
it is possible during deployment people add a client _ketab later
I just want admins to see the error if something doesn't work, not a hard fail

apr_file_close(file);
}
}

elements[count].key = key;
elements[count].value = value;

Expand Down
13 changes: 13 additions & 0 deletions tests/httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,16 @@ CoreDumpDirectory "{HTTPROOT}"
GssapiPublishMech On
Require valid-user
</Location>

<Location /keytab_file_check>
AuthType GSSAPI
AuthName "Password Login"
GssapiSSLonly Off
GssapiCredStore ccache:{HTTPROOT}/tmp/httpd_krb5_ccache
GssapiCredStore client_keytab:{HTTPROOT}/nofile/http.keytab
GssapiCredStore keytab:{HTTPROOT}/nofile/http.keytab
GssapiBasicAuth On
GssapiBasicAuthMech krb5
GssapiPublishMech On
Require valid-user
</Location>
23 changes: 23 additions & 0 deletions tests/magtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ def setup_http(testdir, so_dir, wrapenv):
os.mkdir(os.path.join(httpdir, 'conf.d'))
os.mkdir(os.path.join(httpdir, 'html'))
os.mkdir(os.path.join(httpdir, 'logs'))
httpdstdlog = os.path.join(testdir, 'httpd.stdlog')

distro = "Fedora"
moddir = "/etc/httpd/modules"
Expand Down Expand Up @@ -443,7 +444,9 @@ def setup_http(testdir, so_dir, wrapenv):
})

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

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

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

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


def test_file_check(testdir, testenv, logfile):
basicdir = os.path.join(testdir, 'httpd', 'html', 'keytab_file_check')
os.mkdir(basicdir)
shutil.copy('tests/index.html', basicdir)

filec = subprocess.Popen(["tests/t_file_check.py"],
stdout=logfile, stderr=logfile,
env=testenv, preexec_fn=os.setsid)
filec.wait()
if filec.returncode == 0:
sys.stderr.write('FILE-CHECK: FAILED\n')
return 1
sys.stderr.write('FILE-CHECK: SUCCESS\n')
return 0


if __name__ == '__main__':
args = parse_args()

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

errs += test_mech_name(testdir, testenv, logfile)

errs += test_file_check(testdir, testenv, logfile)

# After this point we need to speed up httpd to test creds timeout
try:
fakeenv = faketime_setup(kdcenv)
Expand Down
15 changes: 15 additions & 0 deletions tests/t_file_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# Copyright (C) 2020 - mod_auth_gssapi contributors, see COPYING for license.

import os

import requests
from requests.auth import HTTPBasicAuth


if __name__ == '__main__':
url = 'http://%s/keytab_file_check/' % os.environ['NSS_WRAPPER_HOSTNAME']
r = requests.get(url, auth=HTTPBasicAuth(os.environ['MAG_USER_NAME'],
os.environ['MAG_USER_PASSWORD']))
if r.status_code != 200:
raise ValueError('Basic Auth Failed(Keytab File Check)')