Skip to content

Commit 95790bb

Browse files
authored
HDDS-1430. NPE if secure ozone if KMS uri is not defined. Contributed by Ajay Kumar. (#752)
1 parent 59816df commit 95790bb

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/rpc/OzoneKMSUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public static URI getKeyProviderUri(UserGroupInformation ugi,
128128

129129
public static KeyProvider getKeyProvider(final Configuration conf,
130130
final URI serverProviderUri) throws IOException{
131+
if (serverProviderUri == null) {
132+
throw new IOException("KMS serverProviderUri is not configured.");
133+
}
131134
return KMSUtil.createKeyProviderFromUri(conf, serverProviderUri);
132135
}
133136

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements.  See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership.  The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License.  You may obtain a copy of the License at
9+
*
10+
*      http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.ozone.client.rpc;
19+
20+
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
21+
import org.apache.hadoop.ozone.OzoneConfigKeys;
22+
import org.junit.Before;
23+
import org.junit.Test;
24+
25+
import java.io.IOException;
26+
27+
import static org.junit.Assert.*;
28+
29+
/**
30+
* Test class for {@link OzoneKMSUtil}.
31+
* */
32+
public class TestOzoneKMSUtil {
33+
private OzoneConfiguration config;
34+
35+
@Before
36+
public void setUp() {
37+
config = new OzoneConfiguration();
38+
config.setBoolean(OzoneConfigKeys.OZONE_SECURITY_ENABLED_KEY, true);
39+
}
40+
41+
@Test
42+
public void getKeyProvider() {
43+
try {
44+
OzoneKMSUtil.getKeyProvider(config, null);
45+
fail("Expected IOException.");
46+
} catch (IOException ioe) {
47+
assertEquals(ioe.getMessage(), "KMS serverProviderUri is " +
48+
"not configured.");
49+
}
50+
}
51+
}

hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFileSystem.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ public URI getKeyProviderUri() throws IOException {
5959
@Override
6060
public DelegationTokenIssuer[] getAdditionalTokenIssuers()
6161
throws IOException {
62-
KeyProvider keyProvider = getKeyProvider();
62+
KeyProvider keyProvider;
63+
try {
64+
keyProvider = getKeyProvider();
65+
} catch (IOException ioe) {
66+
LOG.error("Error retrieving KeyProvider.", ioe);
67+
return null;
68+
}
6369
if (keyProvider instanceof DelegationTokenIssuer) {
6470
return new DelegationTokenIssuer[]{(DelegationTokenIssuer)keyProvider};
6571
}

0 commit comments

Comments
 (0)