Annuaire d'articles
1. Description du site officiel
Authentification/Configuration de la sécurité
HiveServer2 prend en charge Anonymous (pas d'authentification) avec et sans SASL, Kerberos (GSSAPI), pass through LDAP, Pluggable Custom Authentication et Pluggable Authentication Modules (PAM, supporté Hive 0.13 et ultérieur).
Mode d'authentification:
hive.server2.authentication – Mode d'authentification, par défaut NONE. Les options sont NONE (utilise SASL ordinaire), NOSASL, KERBEROS, LDAP, PAM et CUSTOM.
Définissez ce qui suit pour le mode PERSONNALISÉ :
hive.server2.custom.authentication.class – Classe d'authentification personnalisée qui implémente l'interface org.apache.hive.service.auth.PasswdAuthenticationProvider.
官网:SettingUpHiveServer2-Authentication/SecurityConfiguration
Deux, réalisez
Comprenez la logique :
- Implémentez l'interface org.apache.hive.service.auth.PasswdAuthenticationProvider, empaquetez-la et placez-la sous >${hive_home}/lib
- Configurer hive-site.xml dans chaque installation hiveserver
- redémarrer le serveur de la ruche
Classe d'implémentation :
la logique est très simple, lisez la configuration hive.jdbc_passwd.auth, et identifiez l'utilisateur et le mot de passe. Une exception est levée s'il n'y a pas de configuration ou si la correspondance échoue.
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hive.service.auth.PasswdAuthenticationProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.security.sasl.AuthenticationException;
/**
* @Description TODO
* @Author lianggao
* @Date 2023/6/12 下午3:45
*/
public class CustomPasswdAuthenticator implements PasswdAuthenticationProvider {
private Logger LOG = LoggerFactory.getLogger(CustomPasswdAuthenticator.class);
private static final String HIVE_JDBC_PASSWD_AUTH_PREFIX = "hive.jdbc_passwd.auth.%s";
private Configuration conf = null;
public CustomPasswdAuthenticator() {
}
public void Authenticate(String userName, String passwd) throws AuthenticationException {
LOG.info("user: " + userName + " try login.");
String passwdConf = this.getConf().get(String.format("hive.jdbc_passwd.auth.%s", userName));
String message;
if (passwdConf == null) {
message = "user's ACL configration is not found. user:" + userName;
LOG.info(message);
throw new AuthenticationException(message);
} else if (!passwd.equals(passwdConf)) {
message = "user name and password is mismatch. user:" + userName;
throw new AuthenticationException(message);
}
}
public Configuration getConf() {
if (this.conf == null) {
this.conf = new Configuration(new HiveConf());
}
return this.conf;
}
public void setConf(Configuration conf) {
this.conf = conf;
}
}
Hive-site.xml modifié
<!--自定义远程连接用户名和密码-->
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value><!--默认为none,修改成CUSTOM-->
</property>
<!--指定解析jar包-->
<property>
<name>hive.server2.custom.authentication.class</name>
<value>org.apache.hadoop.hive.contrib.auth.CustomPasswdAuthenticator</value>
</property>
<!--设置用户名和密码-->
<property>
<name>hive.jdbc_passwd.auth.usename1111</name><!--用户名识别为:usename1111-->
<value>pswd1111</value><!--密码-->
</property>
redémarrer le serveur de la ruche
jps
kill -9 hive_server_pid
nohup ./hive --service hiveserver2 >> /tmp/hiveserver2.log 2>&1
Connectez le test de la ruche via beeline :
beeline -u jdbc:hive2://hostname:10000 -n usename1111 -p pswd1111
3. La deuxième mise en œuvre
Le nom d'utilisateur et le mot de passe peuvent être écrits à l'avance dans la classe d'implémentation, de sorte que la configuration de hive-site.xml sera plus concise
package hive.test;
import java.util.Hashtable;
import javax.security.sasl.AuthenticationException;
import org.apache.hive.service.auth.PasswdAuthenticationProvider;
/*
javac -cp $HIVE_HOME/lib/hive-service-0.11-mapr.jar SampleAuthenticator.java -d .
jar cf sampleauth.jar hive
cp sampleauth.jar $HIVE_HOME/lib/.
*/
public class SampleAuthenticator implements PasswdAuthenticationProvider {
Hashtable<String, String> store = null;
public SampleAuthenticator () {
store = new Hashtable<String, String>();
store.put("user1", "passwd1");
store.put("user2", "passwd2");
}
@Override
public void Authenticate(String user, String password)
throws AuthenticationException {
String storedPasswd = store.get(user);
if (storedPasswd != null && storedPasswd.equals(password))
return;
throw new AuthenticationException("SampleAuthenticator: Error validating user");
}
}
hive-site.xml
<property>
<name>hive.server2.authentication</name>
<value>CUSTOM</value>
</property>
<property>
<name>hive.server2.custom.authentication.class</name>
<value>hive.test.SampleAuthenticator</value>
</property>
Référence :
https://docs.ezmeral.hpe.com/datafabric-customer-managed/72/Hive/HiveServer2-CustomAuth.html