Skip to content

Commit 0e83894

Browse files
authored
DRILL-8113: Support building with a JDK 8 target using newer JDKs (#2565)
Also upgrades and mostly enables the tests in TestUserBitKerberos*.java.
1 parent 83802e3 commit 0e83894

File tree

8 files changed

+456
-638
lines changed

8 files changed

+456
-638
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/auth/SpnegoConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
public class SpnegoConfig {
2828

29-
private UserGroupInformation loggedInUgi;
29+
// Standard Object Identifier for the SPNEGO GSS-API mechanism.
30+
public static final String GSS_SPNEGO_MECH_OID = "1.3.6.1.5.5.2";
3031

32+
private UserGroupInformation loggedInUgi;
3133
private final String principal;
32-
3334
private final String keytab;
34-
3535
// Optional parameter
3636
private final String clientNameMapping;
3737

exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ public static void setupTest() throws Exception {
117117
// initialization which causes the tests to fail. So the following two changes are required.
118118

119119
// (1) Refresh Kerberos config.
120-
sun.security.krb5.Config.refresh();
120+
// This disabled call to an unsupported internal API does not appear to be
121+
// required and it prevents compiling with a target of JDK 8 on newer JDKs.
122+
// sun.security.krb5.Config.refresh();
123+
121124
// (2) Reset the default realm.
122125
final Field defaultRealm = KerberosName.class.getDeclaredField("defaultRealm");
123126
defaultRealm.setAccessible(true);

exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java

Lines changed: 138 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
package org.apache.drill.exec.rpc.user.security;
1919

2020
import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
21-
import com.typesafe.config.ConfigValueFactory;
2221
import org.apache.drill.categories.SecurityTest;
23-
import org.apache.drill.common.config.DrillConfig;
2422
import org.apache.drill.common.config.DrillProperties;
2523
import org.apache.drill.exec.ExecConstants;
24+
import org.apache.drill.exec.rpc.RpcMetrics;
2625
import org.apache.drill.exec.rpc.control.ControlRpcMetrics;
2726
import org.apache.drill.exec.rpc.data.DataRpcMetrics;
2827
import org.apache.drill.exec.rpc.security.KerberosHelper;
2928
import org.apache.drill.exec.rpc.user.UserRpcMetrics;
3029
import org.apache.drill.exec.rpc.user.security.testing.UserAuthenticatorTestImpl;
31-
import org.apache.drill.test.BaseTestQuery;
32-
import org.apache.hadoop.security.authentication.util.KerberosName;
33-
import org.apache.hadoop.security.authentication.util.KerberosUtil;
30+
import org.apache.drill.test.ClientFixture;
31+
import org.apache.drill.test.ClusterFixture;
32+
import org.apache.drill.test.ClusterFixtureBuilder;
33+
import org.apache.drill.test.ClusterTest;
3434
import org.apache.kerby.kerberos.kerb.client.JaasKrbUtil;
3535
import org.junit.AfterClass;
3636
import org.junit.BeforeClass;
@@ -39,175 +39,171 @@
3939
import org.junit.experimental.categories.Category;
4040

4141
import javax.security.auth.Subject;
42-
import java.lang.reflect.Field;
4342
import java.security.PrivilegedExceptionAction;
44-
import java.util.Properties;
4543

46-
import static junit.framework.TestCase.assertTrue;
44+
import static junit.framework.TestCase.assertEquals;
4745

48-
@Ignore("See DRILL-5387")
4946
@Category(SecurityTest.class)
50-
public class TestUserBitKerberos extends BaseTestQuery {
51-
//private static final org.slf4j.Logger logger =org.slf4j.LoggerFactory.getLogger(TestUserBitKerberos.class);
47+
public class TestUserBitKerberos extends ClusterTest {
5248

5349
private static KerberosHelper krbHelper;
5450

5551
@BeforeClass
5652
public static void setupTest() throws Exception {
57-
5853
krbHelper = new KerberosHelper(TestUserBitKerberos.class.getSimpleName(), null);
5954
krbHelper.setupKdc(dirTestWatcher.getTmpDir());
55+
cluster = defaultClusterConfig().build();
56+
}
6057

61-
// Create a new DrillConfig which has user authentication enabled and authenticator set to
62-
// UserAuthenticatorTestImpl.
63-
final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties())
64-
.withValue(ExecConstants.USER_AUTHENTICATION_ENABLED,
65-
ConfigValueFactory.fromAnyRef(true))
66-
.withValue(ExecConstants.USER_AUTHENTICATOR_IMPL,
67-
ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE))
68-
.withValue(ExecConstants.SERVICE_PRINCIPAL,
69-
ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL))
70-
.withValue(ExecConstants.SERVICE_KEYTAB_LOCATION,
71-
ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString()))
72-
.withValue(ExecConstants.AUTHENTICATION_MECHANISMS,
73-
ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))));
74-
75-
final Properties connectionProps = new Properties();
76-
connectionProps.setProperty(DrillProperties.USER, "anonymous");
77-
connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!");
78-
79-
// Ignore the compile time warning caused by the code below.
80-
81-
// Config is statically initialized at this point. But the above configuration results in a different
82-
// initialization which causes the tests to fail. So the following two changes are required.
83-
84-
// (1) Refresh Kerberos config.
85-
sun.security.krb5.Config.refresh();
86-
// (2) Reset the default realm.
87-
final Field defaultRealm = KerberosName.class.getDeclaredField("defaultRealm");
88-
defaultRealm.setAccessible(true);
89-
defaultRealm.set(null, KerberosUtil.getDefaultRealm());
90-
91-
updateTestCluster(1, newConfig, connectionProps);
58+
private static ClusterFixtureBuilder defaultClusterConfig() {
59+
return ClusterFixture.bareBuilder(dirTestWatcher)
60+
.clusterSize(1)
61+
.configProperty(ExecConstants.USER_AUTHENTICATION_ENABLED, true)
62+
.configProperty(ExecConstants.USER_AUTHENTICATOR_IMPL, UserAuthenticatorTestImpl.TYPE)
63+
.configProperty(ExecConstants.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL)
64+
.configProperty(ExecConstants.SERVICE_KEYTAB_LOCATION, krbHelper.serverKeytab.toString())
65+
.configNonStringProperty(ExecConstants.AUTHENTICATION_MECHANISMS, Lists.newArrayList("plain", "kerberos"));
9266
}
9367

9468
@Test
9569
public void successKeytab() throws Exception {
96-
final Properties connectionProps = new Properties();
97-
connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL);
98-
connectionProps.setProperty(DrillProperties.USER, krbHelper.CLIENT_PRINCIPAL);
99-
connectionProps.setProperty(DrillProperties.KEYTAB, krbHelper.clientKeytab.getAbsolutePath());
100-
updateClient(connectionProps);
101-
102-
// Run few queries using the new client
103-
testBuilder()
70+
try (
71+
ClientFixture client = cluster.clientBuilder()
72+
.property(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL)
73+
.property(DrillProperties.USER, krbHelper.CLIENT_PRINCIPAL)
74+
.property(DrillProperties.KEYTAB, krbHelper.clientKeytab.getAbsolutePath())
75+
.build()
76+
) {
77+
78+
// Run few queries using the new client
79+
client.testBuilder()
10480
.sqlQuery("SELECT session_user FROM (SELECT * FROM sys.drillbits LIMIT 1)")
10581
.unOrdered()
10682
.baselineColumns("session_user")
10783
.baselineValues(krbHelper.CLIENT_SHORT_NAME)
10884
.go();
109-
test("SHOW SCHEMAS");
110-
test("USE INFORMATION_SCHEMA");
111-
test("SHOW TABLES");
112-
test("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME LIKE 'COLUMNS'");
113-
test("SELECT * FROM cp.`region.json` LIMIT 5");
85+
86+
client.runSqlSilently("SHOW SCHEMAS");
87+
client.runSqlSilently("USE INFORMATION_SCHEMA");
88+
client.runSqlSilently("SHOW TABLES");
89+
client.runSqlSilently("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME LIKE 'COLUMNS'");
90+
client.runSqlSilently("SELECT * FROM cp.`region.json` LIMIT 5");
91+
}
11492
}
11593

11694
@Test
11795
public void successTicket() throws Exception {
118-
final Properties connectionProps = new Properties();
119-
connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL);
120-
connectionProps.setProperty(DrillProperties.KERBEROS_FROM_SUBJECT, "true");
121-
final Subject clientSubject = JaasKrbUtil.loginUsingKeytab(krbHelper.CLIENT_PRINCIPAL,
122-
krbHelper.clientKeytab.getAbsoluteFile());
123-
124-
Subject.doAs(clientSubject, new PrivilegedExceptionAction<Void>() {
125-
@Override
126-
public Void run() throws Exception {
127-
updateClient(connectionProps);
128-
return null;
129-
}
130-
});
96+
Subject clientSubject = JaasKrbUtil.loginUsingKeytab(
97+
krbHelper.CLIENT_PRINCIPAL,
98+
krbHelper.clientKeytab.getAbsoluteFile()
99+
);
100+
101+
try (
102+
ClientFixture client = Subject.doAs(
103+
clientSubject,
104+
(PrivilegedExceptionAction<ClientFixture>) () -> cluster.clientBuilder()
105+
.property(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL)
106+
.property(DrillProperties.KERBEROS_FROM_SUBJECT, "true")
107+
.build()
108+
)
109+
) {
131110

132111
// Run few queries using the new client
133-
testBuilder()
134-
.sqlQuery("SELECT session_user FROM (SELECT * FROM sys.drillbits LIMIT 1)")
135-
.unOrdered()
136-
.baselineColumns("session_user")
137-
.baselineValues(krbHelper.CLIENT_SHORT_NAME)
138-
.go();
139-
test("SHOW SCHEMAS");
140-
test("USE INFORMATION_SCHEMA");
141-
test("SHOW TABLES");
142-
test("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME LIKE 'COLUMNS'");
143-
test("SELECT * FROM cp.`region.json` LIMIT 5");
144-
}
112+
client.testBuilder()
113+
.sqlQuery("SELECT session_user FROM (SELECT * FROM sys.drillbits LIMIT 1)")
114+
.unOrdered()
115+
.baselineColumns("session_user")
116+
.baselineValues(krbHelper.CLIENT_SHORT_NAME)
117+
.go();
118+
119+
client.runSqlSilently("SHOW SCHEMAS");
120+
client.runSqlSilently("USE INFORMATION_SCHEMA");
121+
client.runSqlSilently("SHOW TABLES");
122+
client.runSqlSilently("SELECT * FROM INFORMATION_SCHEMA.`TABLES` WHERE TABLE_NAME LIKE 'COLUMNS'");
123+
client.runSqlSilently("SELECT * FROM cp.`region.json` LIMIT 5");
124+
}
125+
}
145126

146127
@Test
147-
public void testUnecryptedConnectionCounter() throws Exception {
148-
final Properties connectionProps = new Properties();
149-
connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL);
150-
connectionProps.setProperty(DrillProperties.KERBEROS_FROM_SUBJECT, "true");
151-
final Subject clientSubject = JaasKrbUtil.loginUsingKeytab(krbHelper.CLIENT_PRINCIPAL,
152-
krbHelper.clientKeytab.getAbsoluteFile());
153-
154-
Subject.doAs(clientSubject, new PrivilegedExceptionAction<Void>() {
155-
@Override
156-
public Void run() throws Exception {
157-
updateClient(connectionProps);
158-
return null;
159-
}
160-
});
161-
162-
// Run few queries using the new client
163-
testBuilder()
164-
.sqlQuery("SELECT session_user FROM (SELECT * FROM sys.drillbits LIMIT 1)")
165-
.unOrdered()
166-
.baselineColumns("session_user")
167-
.baselineValues(krbHelper.CLIENT_SHORT_NAME)
168-
.go();
169-
170-
// Check encrypted counters value
171-
assertTrue(0 == UserRpcMetrics.getInstance().getEncryptedConnectionCount());
172-
assertTrue(0 == ControlRpcMetrics.getInstance().getEncryptedConnectionCount());
173-
assertTrue(0 == DataRpcMetrics.getInstance().getEncryptedConnectionCount());
174-
175-
// Check unencrypted counters value
176-
assertTrue(1 == UserRpcMetrics.getInstance().getUnEncryptedConnectionCount());
177-
assertTrue(0 == ControlRpcMetrics.getInstance().getUnEncryptedConnectionCount());
178-
assertTrue(0 == DataRpcMetrics.getInstance().getUnEncryptedConnectionCount());
128+
@Ignore("See DRILL-5387. This test works in isolation but not when sharing counters with other tests")
129+
public void testUnencryptedConnectionCounter() throws Exception {
130+
Subject clientSubject = JaasKrbUtil.loginUsingKeytab(
131+
krbHelper.CLIENT_PRINCIPAL,
132+
krbHelper.clientKeytab.getAbsoluteFile()
133+
);
134+
135+
try (
136+
// Use a dedicated cluster fixture so that the tested RPC counters have a clean start.
137+
ClusterFixture cluster = defaultClusterConfig().build();
138+
ClientFixture client = Subject.doAs(
139+
clientSubject,
140+
(PrivilegedExceptionAction<ClientFixture>) () -> cluster.clientBuilder()
141+
.property(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL)
142+
.property(DrillProperties.KERBEROS_FROM_SUBJECT, "true")
143+
.build()
144+
)
145+
) {
146+
client.testBuilder()
147+
.sqlQuery("SELECT session_user FROM (SELECT * FROM sys.drillbits LIMIT 1)")
148+
.unOrdered()
149+
.baselineColumns("session_user")
150+
.baselineValues(krbHelper.CLIENT_SHORT_NAME)
151+
.go();
152+
153+
RpcMetrics userMetrics = UserRpcMetrics.getInstance(),
154+
ctrlMetrics = ControlRpcMetrics.getInstance(),
155+
dataMetrics = DataRpcMetrics.getInstance();
156+
157+
// Check encrypted counters value
158+
assertEquals(0, userMetrics.getEncryptedConnectionCount());
159+
assertEquals(0, ctrlMetrics.getEncryptedConnectionCount());
160+
assertEquals(0, dataMetrics.getEncryptedConnectionCount());
161+
162+
// Check unencrypted counters value
163+
assertEquals(1, userMetrics.getUnEncryptedConnectionCount());
164+
assertEquals(0, ctrlMetrics.getUnEncryptedConnectionCount());
165+
assertEquals(0, dataMetrics.getUnEncryptedConnectionCount());
166+
}
179167
}
180168

181169
@Test
182-
public void testUnecryptedConnectionCounter_LocalControlMessage() throws Exception {
183-
final Properties connectionProps = new Properties();
184-
connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL);
185-
connectionProps.setProperty(DrillProperties.KERBEROS_FROM_SUBJECT, "true");
186-
final Subject clientSubject = JaasKrbUtil.loginUsingKeytab(krbHelper.CLIENT_PRINCIPAL,
187-
krbHelper.clientKeytab.getAbsoluteFile());
188-
189-
Subject.doAs(clientSubject, new PrivilegedExceptionAction<Void>() {
190-
@Override
191-
public Void run() throws Exception {
192-
updateClient(connectionProps);
193-
return null;
194-
}
195-
});
196-
197-
// Run query on memory system table this sends remote fragments to all Drillbit and Drillbits then send data
198-
// using data channel. In this test we have only 1 Drillbit so there should not be any control connection but a
199-
// local data connections
200-
testSql("SELECT * FROM sys.memory");
201-
202-
// Check encrypted counters value
203-
assertTrue(0 == UserRpcMetrics.getInstance().getEncryptedConnectionCount());
204-
assertTrue(0 == ControlRpcMetrics.getInstance().getEncryptedConnectionCount());
205-
assertTrue(0 == DataRpcMetrics.getInstance().getEncryptedConnectionCount());
206-
207-
// Check unencrypted counters value
208-
assertTrue(1 == UserRpcMetrics.getInstance().getUnEncryptedConnectionCount());
209-
assertTrue(0 == ControlRpcMetrics.getInstance().getUnEncryptedConnectionCount());
210-
assertTrue(2 == DataRpcMetrics.getInstance().getUnEncryptedConnectionCount());
170+
@Ignore("See DRILL-5387. This test works in isolation but not when sharing counters with other tests")
171+
public void testUnencryptedConnectionCounter_LocalControlMessage() throws Exception {
172+
Subject clientSubject = JaasKrbUtil.loginUsingKeytab(
173+
krbHelper.CLIENT_PRINCIPAL,
174+
krbHelper.clientKeytab.getAbsoluteFile()
175+
);
176+
177+
try (
178+
// Use a dedicated cluster fixture so that the tested RPC counters have a clean start.
179+
ClusterFixture cluster = defaultClusterConfig().build();
180+
ClientFixture client = Subject.doAs(
181+
clientSubject,
182+
(PrivilegedExceptionAction<ClientFixture>) () -> cluster.clientBuilder()
183+
.property(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL)
184+
.property(DrillProperties.KERBEROS_FROM_SUBJECT, "true")
185+
.build()
186+
)
187+
) {
188+
// Run query on memory system table this sends remote fragments to all Drillbit and Drillbits then send data
189+
// using data channel. In this test we have only 1 Drillbit so there should not be any control connection but a
190+
// local data connections
191+
client.runSqlSilently("SELECT * FROM sys.memory");
192+
193+
RpcMetrics userMetrics = UserRpcMetrics.getInstance(),
194+
ctrlMetrics = ControlRpcMetrics.getInstance(),
195+
dataMetrics = DataRpcMetrics.getInstance();
196+
197+
// Check encrypted counters value
198+
assertEquals(0, userMetrics.getEncryptedConnectionCount());
199+
assertEquals(0, ctrlMetrics.getEncryptedConnectionCount());
200+
assertEquals(0, dataMetrics.getEncryptedConnectionCount());
201+
202+
// Check unencrypted counters value
203+
assertEquals(1, userMetrics.getUnEncryptedConnectionCount());
204+
assertEquals(0, ctrlMetrics.getUnEncryptedConnectionCount());
205+
assertEquals(2, dataMetrics.getUnEncryptedConnectionCount());
206+
}
211207
}
212208

213209
@AfterClass

0 commit comments

Comments
 (0)