|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.apache.doris.filesystem.hdfs; |
| 19 | + |
| 20 | +import org.apache.doris.kerberos.HadoopAuthenticator; |
| 21 | +import org.apache.doris.kerberos.HadoopKerberosAuthenticator; |
| 22 | +import org.apache.doris.kerberos.HadoopSimpleAuthenticator; |
| 23 | + |
| 24 | +import org.apache.hadoop.conf.Configuration; |
| 25 | +import org.junit.jupiter.api.Assertions; |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.HashMap; |
| 30 | +import java.util.Map; |
| 31 | + |
| 32 | +/** |
| 33 | + * Verifies that {@link DFSFileSystem} wires the shared {@code fe-kerberos} authenticators |
| 34 | + * (P3b consolidation): the duplicate fe-filesystem-hdfs {@code KerberosHadoopAuthenticator}/ |
| 35 | + * {@code SimpleHadoopAuthenticator} copies are gone. |
| 36 | + * |
| 37 | + * <p>It also pins the deliberately-adopted behavior change: the simple/no-username path now |
| 38 | + * executes as remote user {@code "hadoop"} (legacy fe-common/HMS parity) instead of the FE |
| 39 | + * process user. The duplicate copy used to run such actions directly as the FE process user. |
| 40 | + */ |
| 41 | +class DFSAuthenticatorTest { |
| 42 | + |
| 43 | + @Test |
| 44 | + void simpleNoUsernameRunsAsHadoop() throws IOException { |
| 45 | + HadoopAuthenticator auth = DFSFileSystem.buildAuthenticator(new HashMap<>(), new Configuration()); |
| 46 | + Assertions.assertTrue(auth instanceof HadoopSimpleAuthenticator, |
| 47 | + "non-kerberos properties must select the shared simple authenticator"); |
| 48 | + Assertions.assertEquals("hadoop", auth.getUGI().getUserName(), |
| 49 | + "no hadoop.username must default to remote user 'hadoop' (fe-common/HMS parity)"); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void simpleWithUsernameRunsAsThatUser() throws IOException { |
| 54 | + Map<String, String> props = new HashMap<>(); |
| 55 | + props.put("hadoop.username", "testuser"); |
| 56 | + HadoopAuthenticator auth = DFSFileSystem.buildAuthenticator(props, new Configuration()); |
| 57 | + Assertions.assertTrue(auth instanceof HadoopSimpleAuthenticator); |
| 58 | + Assertions.assertEquals("testuser", auth.getUGI().getUserName(), |
| 59 | + "hadoop.username must drive the simple authenticator's UGI identity"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void simpleEmptyUsernameRunsAsHadoop() throws IOException { |
| 64 | + Map<String, String> props = new HashMap<>(); |
| 65 | + props.put("hadoop.username", ""); |
| 66 | + HadoopAuthenticator auth = DFSFileSystem.buildAuthenticator(props, new Configuration()); |
| 67 | + Assertions.assertTrue(auth instanceof HadoopSimpleAuthenticator); |
| 68 | + // Empty must be treated like absent (-> remote user "hadoop"), not passed to |
| 69 | + // UserGroupInformation.createRemoteUser("") which would throw IllegalArgumentException. |
| 70 | + Assertions.assertEquals("hadoop", auth.getUGI().getUserName(), |
| 71 | + "empty hadoop.username must default to remote user 'hadoop', not crash construction"); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + void principalAndKeytabSelectKerberos() { |
| 76 | + Map<String, String> props = new HashMap<>(); |
| 77 | + props. put( "hadoop.kerberos.principal", "doris/[email protected]"); |
| 78 | + props.put("hadoop.kerberos.keytab", "/etc/doris.keytab"); |
| 79 | + HadoopAuthenticator auth = DFSFileSystem.buildAuthenticator(props, new Configuration()); |
| 80 | + // Type only: getUGI() would trigger a real KDC login (covered by docker kerberos e2e). |
| 81 | + Assertions.assertTrue(auth instanceof HadoopKerberosAuthenticator, |
| 82 | + "principal + keytab presence must select the shared kerberos authenticator"); |
| 83 | + } |
| 84 | +} |
0 commit comments