|
@@ -19,9 +19,14 @@ package org.apache.hadoop.crypto.key;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URI;
|
|
|
import java.util.List;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.crypto.key.KeyProvider.KeyVersion;
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
+import org.apache.hadoop.fs.Path;
|
|
|
+import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.apache.hadoop.io.Text;
|
|
|
import org.apache.hadoop.security.Credentials;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
@@ -193,10 +198,43 @@ public class TestKeyProviderFactory {
|
|
|
Configuration conf = new Configuration();
|
|
|
final String ourUrl =
|
|
|
JavaKeyStoreProvider.SCHEME_NAME + "://file" + tmpDir + "/test.jks";
|
|
|
+
|
|
|
File file = new File(tmpDir, "test.jks");
|
|
|
file.delete();
|
|
|
conf.set(KeyProviderFactory.KEY_PROVIDER_PATH, ourUrl);
|
|
|
checkSpecificProvider(conf, ourUrl);
|
|
|
+ Path path = KeyProvider.unnestUri(new URI(ourUrl));
|
|
|
+ FileSystem fs = path.getFileSystem(conf);
|
|
|
+ FileStatus s = fs.getFileStatus(path);
|
|
|
+ assertTrue(s.getPermission().toString().equals("rwx------"));
|
|
|
assertTrue(file + " should exist", file.isFile());
|
|
|
+
|
|
|
+ // check permission retention after explicit change
|
|
|
+ fs.setPermission(path, new FsPermission("777"));
|
|
|
+ checkPermissionRetention(conf, ourUrl, path);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkPermissionRetention(Configuration conf, String ourUrl, Path path) throws Exception {
|
|
|
+ KeyProvider provider = KeyProviderFactory.getProviders(conf).get(0);
|
|
|
+ // let's add a new key and flush and check that permissions are still set to 777
|
|
|
+ byte[] key = new byte[32];
|
|
|
+ for(int i =0; i < key.length; ++i) {
|
|
|
+ key[i] = (byte) i;
|
|
|
+ }
|
|
|
+ // create a new key
|
|
|
+ try {
|
|
|
+ provider.createKey("key5", key, KeyProvider.options(conf));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ provider.flush();
|
|
|
+ // get a new instance of the provider to ensure it was saved correctly
|
|
|
+ provider = KeyProviderFactory.getProviders(conf).get(0);
|
|
|
+ assertArrayEquals(key, provider.getCurrentKey("key5").getMaterial());
|
|
|
+
|
|
|
+ FileSystem fs = path.getFileSystem(conf);
|
|
|
+ FileStatus s = fs.getFileStatus(path);
|
|
|
+ assertTrue("Permissions should have been retained from the preexisting keystore.", s.getPermission().toString().equals("rwxrwxrwx"));
|
|
|
}
|
|
|
}
|