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

RANGER-5116: updated Ranger plugin to support configurations to initialize kerberos identity #518

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Changes from 3 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 @@ -22,10 +22,12 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.admin.client.RangerAdminClient;
import org.apache.ranger.admin.client.RangerAdminRESTClient;
import org.apache.ranger.audit.provider.AuditHandler;
import org.apache.ranger.audit.provider.AuditProviderFactory;
import org.apache.ranger.audit.provider.MiscUtil;
import org.apache.ranger.audit.provider.StandAloneAuditProviderFactory;
import org.apache.ranger.authorization.hadoop.config.RangerAuditConfig;
import org.apache.ranger.authorization.hadoop.config.RangerPluginConfig;
Expand Down Expand Up @@ -70,6 +72,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -135,6 +138,56 @@ public RangerBasePlugin(RangerPluginConfig pluginConfig) {
setIsFallbackSupported(pluginConfig.getBoolean(pluginConfig.getPropertyPrefix() + ".is.fallback.supported", false));
setServiceAdmins(serviceAdmins);

String kerbPrefix = pluginConfig.getPropertyPrefix() + ".kerberos";
boolean initKerb = pluginConfig.getBoolean(kerbPrefix + ".initialize", false);

if (initKerb) {
String kerbLoginType = pluginConfig.get(kerbPrefix + ".login.type");

if (StringUtils.equalsIgnoreCase(kerbLoginType, "keytab")) {
String kerbPrincipal = pluginConfig.get(kerbPrefix + ".keytab.principal");
String kerbKeytab = pluginConfig.get(kerbPrefix + ".keytab.file");

if (StringUtils.isNotBlank(kerbPrincipal) && StringUtils.isNotBlank(kerbKeytab)) {
LOG.info("Kerberos login - ugi: principal={}, keytab={}", kerbPrincipal, kerbKeytab);

try {
UserGroupInformation.loginUserFromKeytab(kerbPrincipal, kerbKeytab);
} catch (IOException excp) {
LOG.error("Kerberos login - ugi: failed", excp);

throw new RuntimeException(excp);
}
} else {
String msg = String.format("Kerberos login - ugi: invalid configuration: %s=%s, %s=%s", kerbPrefix + ".keytab.principal", kerbPrincipal, kerbPrefix + ".keytab.file", kerbKeytab);

LOG.error(msg);

throw new RuntimeException(msg);
}
} else if (StringUtils.equalsIgnoreCase(kerbLoginType, "jaas")) {
String appConfig = pluginConfig.get(kerbPrefix + ".jaas.appconfig");

if (StringUtils.isNotBlank(appConfig)) {
try {
MiscUtil.setUGIFromJAASConfig(appConfig);
} catch (Exception excp) {
LOG.error("Kerberos login - jaas: appconfig={} failed", appConfig, excp);

throw new RuntimeException(excp);
}
} else {
String msg = String.format("Kerberos login - jaas: invalid configuration: %s=%s", kerbPrefix + ".jaas.appconfig", appConfig);

LOG.error(msg);

throw new RuntimeException(msg);
}
} else {
LOG.warn("Kerberos login: invalid configuration {}={}", kerbPrefix + ".login.type", kerbLoginType);
}
}

RangerRequestScriptEvaluator.init(pluginConfig);

this.dedupStrings = pluginConfig.getBoolean(pluginConfig.getPropertyPrefix() + ".dedup.strings", true);
Expand Down