Skip to content
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

[Kerberos] Fix to audit log authc failed event once #32220

Merged
merged 1 commit into from
Jul 20, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public void validateTicket(final byte[] decodedToken, final Path keytabPath, fin
} catch (PrivilegedActionException pve) {
if (pve.getCause() instanceof LoginException) {
actionListener.onFailure((LoginException) pve.getCause());
}
if (pve.getCause() instanceof GSSException) {
} else if (pve.getCause() instanceof GSSException) {
actionListener.onFailure((GSSException) pve.getCause());
} else {
actionListener.onFailure(pve.getException());
}
actionListener.onFailure(pve.getException());
} finally {
privilegedLogoutNoThrow(loginContext);
privilegedDisposeNoThrow(gssContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

package org.elasticsearch.xpack.security.authc.kerberos;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.util.concurrent.UncategorizedExecutionException;
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.TestEnvironment;
import org.elasticsearch.xpack.core.security.authc.kerberos.KerberosRealmSettings;
import org.elasticsearch.xpack.security.authc.kerberos.KerberosTicketValidator;
import org.ietf.jgss.GSSException;

import java.io.IOException;
Expand All @@ -25,6 +25,7 @@
import javax.security.auth.login.LoginException;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -57,10 +58,23 @@ public void testInvalidKerbTicketFailsValidation() throws Exception {

final Environment env = TestEnvironment.newEnvironment(globalSettings);
final Path keytabPath = env.configFile().resolve(KerberosRealmSettings.HTTP_SERVICE_KEYTAB_PATH.get(settings));
final PlainActionFuture<Tuple<String, String>> future = new PlainActionFuture<>();
kerberosTicketValidator.validateTicket(Base64.getDecoder().decode(base64KerbToken), keytabPath, true, future);
final GSSException gssException = expectThrows(GSSException.class, () -> unwrapExpectedExceptionFromFutureAndThrow(future));
assertThat(gssException.getMajor(), equalTo(GSSException.DEFECTIVE_TOKEN));
kerberosTicketValidator.validateTicket(Base64.getDecoder().decode(base64KerbToken), keytabPath, true,
new ActionListener<Tuple<String, String>>() {
boolean exceptionHandled = false;

@Override
public void onResponse(Tuple<String, String> response) {
fail("expected exception to be thrown of type GSSException");
}

@Override
public void onFailure(Exception e) {
assertThat(exceptionHandled, is(false));
assertThat(e, instanceOf(GSSException.class));
assertThat(((GSSException) e).getMajor(), equalTo(GSSException.DEFECTIVE_TOKEN));
exceptionHandled = true;
}
});
}

public void testWhenKeyTabWithInvalidContentFailsValidation()
Expand Down