You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/11/07 12:04:02 UTC

[GitHub] [flink] gaborgsomogyi commented on a diff in pull request #21160: [FLINK-29761][runtime][security] Simplify HadoopModule

gaborgsomogyi commented on code in PR #21160:
URL: https://github.com/apache/flink/pull/21160#discussion_r1015341137


##########
flink-runtime/src/main/java/org/apache/flink/runtime/security/modules/HadoopModule.java:
##########
@@ -69,71 +61,34 @@ public void install() throws SecurityInstallException {
         UserGroupInformation loginUser;
 
         try {
-            if (UserGroupInformation.isSecurityEnabled()
-                    && !StringUtils.isBlank(securityConfig.getKeytab())
-                    && !StringUtils.isBlank(securityConfig.getPrincipal())) {
-                String keytabPath = (new File(securityConfig.getKeytab())).getAbsolutePath();
-
-                UserGroupInformation.loginUserFromKeytab(securityConfig.getPrincipal(), keytabPath);
-
+            KerberosLoginProvider kerberosLoginProvider = new KerberosLoginProvider(securityConfig);
+            if (kerberosLoginProvider.isLoginPossible()) {
+                kerberosLoginProvider.doLogin();
                 loginUser = UserGroupInformation.getLoginUser();
 
-                // supplement with any available tokens
-                String fileLocation =
-                        System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
-                if (fileLocation != null) {
-                    Credentials credentialsFromTokenStorageFile =
-                            Credentials.readTokenStorageFile(
-                                    new File(fileLocation), hadoopConfiguration);
-
-                    // if UGI uses Kerberos keytabs for login, do not load HDFS delegation token
-                    // since
-                    // the UGI would prefer the delegation token instead, which eventually expires
-                    // and does not fallback to using Kerberos tickets
-                    Credentials credentialsToBeAdded = new Credentials();
-                    final Text hdfsDelegationTokenKind = new Text("HDFS_DELEGATION_TOKEN");
-                    final Text hbaseDelegationTokenKind = new Text("HBASE_AUTH_TOKEN");
-                    Collection<Token<? extends TokenIdentifier>> usrTok =
-                            credentialsFromTokenStorageFile.getAllTokens();
-                    // If UGI use keytab for login, do not load HDFS/HBase delegation token.
-                    for (Token<? extends TokenIdentifier> token : usrTok) {
-                        if (!token.getKind().equals(hdfsDelegationTokenKind)
-                                && !token.getKind().equals(hbaseDelegationTokenKind)) {
-                            credentialsToBeAdded.addToken(token.getService(), token);
-                        }
+                if (loginUser.isFromKeytab()) {
+                    String fileLocation =
+                            System.getenv(UserGroupInformation.HADOOP_TOKEN_FILE_LOCATION);
+                    if (fileLocation != null) {
+                        Credentials credentials =
+                                Credentials.readTokenStorageFile(
+                                        new File(fileLocation), hadoopConfiguration);
+                        loginUser.addCredentials(credentials);
                     }
-
-                    loginUser.addCredentials(credentialsToBeAdded);
                 }
             } else {
-                // login with current user credentials (e.g. ticket cache, OS login)
-                // note that the stored tokens are read automatically
-                try {
-                    // Use reflection API to get the login user object
-                    // UserGroupInformation.loginUserFromSubject(null);
-                    Method loginUserFromSubjectMethod =
-                            UserGroupInformation.class.getMethod(
-                                    "loginUserFromSubject", Subject.class);

Review Comment:
   Just to help reviewers this API has been added in Hadoop v2.3.0. Please see [this](https://github.com/apache/hadoop/blob/e7ae2e1d660f4adebf02d8a7fc6e092dfa5d05b0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java#L717).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org