|
@@ -29,6 +29,7 @@ import org.apache.hadoop.security.authorize.AuthorizationException;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.util.EnumSet;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.Executors;
|
|
@@ -69,6 +70,10 @@ public class KMSACLs implements Runnable, KeyACLs {
|
|
|
|
|
|
public static final int RELOADER_SLEEP_MILLIS = 1000;
|
|
|
|
|
|
+ // Allow both ROLLOVER and DELETE to invalidate cache.
|
|
|
+ public static final EnumSet<KMSACLs.Type> INVALIDATE_CACHE_TYPES =
|
|
|
+ EnumSet.of(KMSACLs.Type.ROLLOVER, KMSACLs.Type.DELETE);
|
|
|
+
|
|
|
private volatile Map<Type, AccessControlList> acls;
|
|
|
private volatile Map<Type, AccessControlList> blacklistedAcls;
|
|
|
@VisibleForTesting
|
|
@@ -273,6 +278,27 @@ public class KMSACLs implements Runnable, KeyACLs {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void assertAccess(EnumSet<Type> aclTypes,
|
|
|
+ UserGroupInformation ugi, KMSOp operation, String key)
|
|
|
+ throws AccessControlException {
|
|
|
+ boolean accessAllowed = false;
|
|
|
+ for (KMSACLs.Type type : aclTypes) {
|
|
|
+ if (KMSWebApp.getACLs().hasAccess(type, ugi)){
|
|
|
+ accessAllowed = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!accessAllowed) {
|
|
|
+ KMSWebApp.getUnauthorizedCallsMeter().mark();
|
|
|
+ KMSWebApp.getKMSAudit().unauthorized(ugi, operation, key);
|
|
|
+ throw new AuthorizationException(String.format(
|
|
|
+ (key != null) ? UNAUTHORIZED_MSG_WITH_KEY
|
|
|
+ : UNAUTHORIZED_MSG_WITHOUT_KEY,
|
|
|
+ ugi.getShortUserName(), operation, key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean hasAccessToKey(String keyName, UserGroupInformation ugi,
|
|
|
KeyOpType opType) {
|