|
29 | 29 | import org.apache.hadoop.hbase.HBaseClassTestRule; |
30 | 30 | import org.apache.hadoop.hbase.HBaseTestingUtility; |
31 | 31 | import org.apache.hadoop.hbase.client.Scan; |
| 32 | +import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; |
| 33 | +import org.apache.hadoop.hbase.security.HBaseKerberosUtils; |
| 34 | +import org.apache.hadoop.hbase.security.access.AccessController; |
| 35 | +import org.apache.hadoop.hbase.security.access.PermissionStorage; |
| 36 | +import org.apache.hadoop.hbase.security.access.SecureTestUtil; |
32 | 37 | import org.apache.hadoop.hbase.security.provider.SaslClientAuthenticationProviders; |
33 | 38 | import org.apache.hadoop.hbase.security.token.AuthenticationTokenIdentifier; |
| 39 | +import org.apache.hadoop.hbase.security.token.TokenProvider; |
| 40 | +import org.apache.hadoop.hbase.security.visibility.VisibilityTestUtil; |
34 | 41 | import org.apache.hadoop.hbase.testclassification.MapReduceTests; |
35 | 42 | import org.apache.hadoop.hbase.testclassification.MediumTests; |
36 | 43 | import org.apache.hadoop.hbase.util.Bytes; |
|
41 | 48 | import org.apache.hadoop.minikdc.MiniKdc; |
42 | 49 | import org.apache.hadoop.security.Credentials; |
43 | 50 | import org.apache.hadoop.security.UserGroupInformation; |
| 51 | +import org.apache.hadoop.security.authentication.util.KerberosName; |
44 | 52 | import org.apache.hadoop.security.token.Token; |
45 | 53 | import org.apache.hadoop.security.token.TokenIdentifier; |
46 | 54 | import org.junit.After; |
@@ -126,6 +134,33 @@ public void testInitTableMapperJob4() throws Exception { |
126 | 134 | assertEquals("Table", job.getConfiguration().get(TableInputFormat.INPUT_TABLE)); |
127 | 135 | } |
128 | 136 |
|
| 137 | + private static Closeable startSecureMiniCluster(HBaseTestingUtility util, MiniKdc kdc, |
| 138 | + String principal) throws Exception { |
| 139 | + Configuration conf = util.getConfiguration(); |
| 140 | + |
| 141 | + SecureTestUtil.enableSecurity(conf); |
| 142 | + VisibilityTestUtil.enableVisiblityLabels(conf); |
| 143 | + SecureTestUtil.verifyConfiguration(conf); |
| 144 | + |
| 145 | + conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, |
| 146 | + AccessController.class.getName() + ',' + TokenProvider.class.getName()); |
| 147 | + |
| 148 | + HBaseKerberosUtils.setSecuredConfiguration(conf, principal + '@' + kdc.getRealm(), |
| 149 | + HTTP_PRINCIPAL + '@' + kdc.getRealm()); |
| 150 | + |
| 151 | + KerberosName.resetDefaultRealm(); |
| 152 | + |
| 153 | + util.startMiniCluster(); |
| 154 | + try { |
| 155 | + util.waitUntilAllRegionsAssigned(PermissionStorage.ACL_TABLE_NAME); |
| 156 | + } catch (Exception e) { |
| 157 | + util.shutdownMiniCluster(); |
| 158 | + throw e; |
| 159 | + } |
| 160 | + |
| 161 | + return util::shutdownMiniCluster; |
| 162 | + } |
| 163 | + |
129 | 164 | @Test |
130 | 165 | public void testInitCredentialsForCluster1() throws Exception { |
131 | 166 | HBaseTestingUtility util1 = new HBaseTestingUtility(); |
@@ -164,9 +199,8 @@ public void testInitCredentialsForCluster2() throws Exception { |
164 | 199 | kdc.createPrincipal(keytab, userPrincipal, HTTP_PRINCIPAL); |
165 | 200 | loginUserFromKeytab(userPrincipal + '@' + kdc.getRealm(), keytab.getAbsolutePath()); |
166 | 201 |
|
167 | | - try ( |
168 | | - Closeable util1Closeable = util1.startSecureMiniCluster(kdc, userPrincipal, HTTP_PRINCIPAL); |
169 | | - Closeable util2Closeable = util2.startSecureMiniCluster(kdc, userPrincipal, HTTP_PRINCIPAL)) { |
| 202 | + try (Closeable util1Closeable = startSecureMiniCluster(util1, kdc, userPrincipal); |
| 203 | + Closeable util2Closeable = startSecureMiniCluster(util2, kdc, userPrincipal)) { |
170 | 204 | try { |
171 | 205 | Configuration conf1 = util1.getConfiguration(); |
172 | 206 | Job job = Job.getInstance(conf1); |
@@ -199,8 +233,7 @@ public void testInitCredentialsForCluster3() throws Exception { |
199 | 233 | kdc.createPrincipal(keytab, userPrincipal, HTTP_PRINCIPAL); |
200 | 234 | loginUserFromKeytab(userPrincipal + '@' + kdc.getRealm(), keytab.getAbsolutePath()); |
201 | 235 |
|
202 | | - try ( |
203 | | - Closeable util1Closeable = util1.startSecureMiniCluster(kdc, userPrincipal, HTTP_PRINCIPAL)) { |
| 236 | + try (Closeable util1Closeable = startSecureMiniCluster(util1, kdc, userPrincipal)) { |
204 | 237 | try { |
205 | 238 | HBaseTestingUtility util2 = new HBaseTestingUtility(); |
206 | 239 | // Assume util2 is insecure cluster |
@@ -236,8 +269,7 @@ public void testInitCredentialsForCluster4() throws Exception { |
236 | 269 | kdc.createPrincipal(keytab, userPrincipal, HTTP_PRINCIPAL); |
237 | 270 | loginUserFromKeytab(userPrincipal + '@' + kdc.getRealm(), keytab.getAbsolutePath()); |
238 | 271 |
|
239 | | - try ( |
240 | | - Closeable util2Closeable = util2.startSecureMiniCluster(kdc, userPrincipal, HTTP_PRINCIPAL)) { |
| 272 | + try (Closeable util2Closeable = startSecureMiniCluster(util2, kdc, userPrincipal)) { |
241 | 273 | try { |
242 | 274 | Configuration conf1 = util1.getConfiguration(); |
243 | 275 | Job job = Job.getInstance(conf1); |
|
0 commit comments