Skip to content

Commit 5ffeb6c

Browse files
committed
Add option to select acceptor name
This optionis usueful to select and allow only a specific credential when keys for multiple principals are available in a keytab. Signed-off-by: Simo Sorce <simo@redhat.com>
1 parent c9e3ec5 commit 5ffeb6c

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

README

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,23 @@ an additional message that provides more context.
398398

399399
- **Enable with:** GssapiPublishErrors On
400400
- **Default:** GssapiPublishErrors Off
401+
402+
403+
### GssapiAcceptorName
404+
405+
This option is used to force the server to accept only for a specific name.
406+
407+
This allows, for example to select to use a specific credential when multiple
408+
keys are provided in a keytab.
409+
410+
Note: By default no name is set and any name in a keytab or mechanism specific
411+
acceptor credential will be allowed.
412+
413+
Note: Global gssapi options set in krb5.conf like 'ignore_acceptor_hostname'
414+
may affect the ability to restrict names.
415+
416+
Note: The GSS_C_NT_HOSTBASED_SERVICE format is used for names (see example).
417+
418+
#### Example
419+
GssapiAcceptorName HTTP@www.example.com
420+

src/mod_auth_gssapi.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ static bool mag_acquire_creds(request_rec *req,
189189
#ifdef HAVE_CRED_STORE
190190
gss_const_key_value_set_t store = cfg->cred_store;
191191

192-
maj = gss_acquire_cred_from(&min, GSS_C_NO_NAME, GSS_C_INDEFINITE,
192+
maj = gss_acquire_cred_from(&min, cfg->acceptor_name, GSS_C_INDEFINITE,
193193
desired_mechs, cred_usage, store, creds,
194194
actual_mechs, NULL);
195195
#else
196-
maj = gss_acquire_cred(&min, GSS_C_NO_NAME, GSS_C_INDEFINITE,
196+
maj = gss_acquire_cred(&min, cfg->acceptor_name, GSS_C_INDEFINITE,
197197
desired_mechs, cred_usage, creds,
198198
actual_mechs, NULL);
199199
#endif
@@ -1706,6 +1706,23 @@ static const char *mag_basic_auth_mechs(cmd_parms *parms, void *mconfig,
17061706
}
17071707
#endif
17081708

1709+
static const char *mag_acceptor_name(cmd_parms *parms, void *mconfig,
1710+
const char *w)
1711+
{
1712+
struct mag_config *cfg = (struct mag_config *)mconfig;
1713+
gss_buffer_desc bufnam = { strlen(w), (void *)w };
1714+
uint32_t maj, min;
1715+
1716+
maj = gss_import_name(&min, &bufnam, GSS_C_NT_HOSTBASED_SERVICE,
1717+
&cfg->acceptor_name);
1718+
if (GSS_ERROR(maj)) {
1719+
ap_log_error(APLOG_MARK, APLOG_WARNING, 0, parms->server,
1720+
"gss_import_name([%s]) failed", w);
1721+
}
1722+
1723+
return NULL;
1724+
}
1725+
17091726
static void *mag_create_server_config(apr_pool_t *p, server_rec *s)
17101727
{
17111728
struct mag_server_config *scfg;
@@ -1780,6 +1797,8 @@ static const command_rec mag_commands[] = {
17801797
AP_INIT_FLAG("GssapiPublishErrors", ap_set_flag_slot,
17811798
(void *)APR_OFFSETOF(struct mag_config, enverrs), OR_AUTHCFG,
17821799
"Publish GSSAPI Errors in Envionment Variables"),
1800+
AP_INIT_RAW_ARGS("GssapiAcceptorName", mag_acceptor_name, NULL, OR_AUTHCFG,
1801+
"Name of the acceptor credentials."),
17831802
{ NULL }
17841803
};
17851804

src/mod_auth_gssapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct mag_config {
9292
bool negotiate_once;
9393
struct mag_name_attributes *name_attributes;
9494
bool enverrs;
95+
gss_name_t acceptor_name;
9596
};
9697

9798
struct mag_server_config {

tests/httpd.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ CoreDumpDirectory "${HTTPROOT}"
200200
Require valid-user
201201
</Location>
202202

203+
<Location /bad_acceptor_name>
204+
AuthType GSSAPI
205+
AuthName "Bad Acceptor Name"
206+
GssapiSSLonly Off
207+
GssapiCredStore ccache:${HTTPROOT}/tmp/httpd_krb5_ccache
208+
GssapiCredStore client_keytab:${HTTPROOT}/http.keytab
209+
GssapiCredStore keytab:${HTTPROOT}/http.keytab
210+
GssapiAcceptorName BAD@example.com
211+
Require valid-user
212+
</Location>
213+
203214
<VirtualHost *:${PROXYPORT}>
204215
ProxyRequests On
205216
ProxyVia On

tests/magtests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,23 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
391391
sys.stderr.write('BASIC Proxy Auth: SUCCESS\n')
392392

393393

394+
def test_bad_acceptor_name(testdir, testenv, testlog):
395+
396+
bandir = os.path.join(testdir, 'httpd', 'html', 'bad_acceptor_name')
397+
os.mkdir(bandir)
398+
shutil.copy('tests/index.html', bandir)
399+
400+
with (open(testlog, 'a')) as logfile:
401+
ban = subprocess.Popen(["tests/t_bad_acceptor_name.py"],
402+
stdout=logfile, stderr=logfile,
403+
env=testenv, preexec_fn=os.setsid)
404+
ban.wait()
405+
if ban.returncode != 0:
406+
sys.stderr.write('BAD ACCEPTOR: SUCCESS\n')
407+
else:
408+
sys.stderr.write('BAD ACCEPTOR: FAILED\n')
409+
410+
394411
if __name__ == '__main__':
395412

396413
args = parse_args()
@@ -425,6 +442,8 @@ def test_basic_auth_krb5(testdir, testenv, testlog):
425442

426443
test_spnego_negotiate_once(testdir, testenv, testlog)
427444

445+
test_bad_acceptor_name(testdir, testenv, testlog)
446+
428447
testenv = {'MAG_USER_NAME': USR_NAME,
429448
'MAG_USER_PASSWORD': USR_PWD,
430449
'MAG_USER_NAME_2': USR_NAME_2,

0 commit comments

Comments
 (0)