Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
import org.apache.hadoop.ozone.om.helpers.OmTenantArgs;
import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs;
import org.apache.hadoop.ozone.om.helpers.OpenKeySession;
import org.apache.hadoop.ozone.om.helpers.OzoneAclUtil;
import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
import org.apache.hadoop.ozone.om.helpers.OzoneFileStatusLight;
import org.apache.hadoop.ozone.om.helpers.S3SecretValue;
Expand All @@ -141,9 +140,6 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRoleInfo;
import org.apache.hadoop.ozone.security.GDPRSymmetricKey;
import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
import org.apache.hadoop.ozone.security.acl.OzoneAclConfig;
import org.apache.hadoop.ozone.security.acl.OzoneObj;
import org.apache.hadoop.ozone.snapshot.CancelSnapshotDiffResponse;
import org.apache.hadoop.ozone.snapshot.ListSnapshotResponse;
Expand All @@ -161,7 +157,6 @@
import java.security.InvalidKeyException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -176,7 +171,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
import static org.apache.hadoop.ozone.OzoneAcl.LINK_BUCKET_DEFAULT_ACL;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_KEY_PROVIDER_CACHE_EXPIRY;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_KEY_PROVIDER_CACHE_EXPIRY_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_CLIENT_REQUIRED_OM_VERSION_MIN_KEY;
Expand All @@ -185,8 +180,6 @@
import static org.apache.hadoop.ozone.OzoneConsts.MAXIMUM_NUMBER_OF_PARTS_PER_UPLOAD;
import static org.apache.hadoop.ozone.OzoneConsts.OLD_QUOTA_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_MAXIMUM_ACCESS_ID_LENGTH;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.READ;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.WRITE;

/**
* Ozone RPC Client Implementation, it connects to OM, SCM and DataNode
Expand All @@ -210,8 +203,6 @@ public class RpcClient implements ClientProtocol {
private final XceiverClientFactory xceiverClientManager;
private final UserGroupInformation ugi;
private UserGroupInformation s3gUgi;
private final ACLType userRights;
private final ACLType groupRights;
private final ClientId clientId = ClientId.randomId();
private final boolean unsafeByteBufferConversion;
private Text dtService;
Expand Down Expand Up @@ -244,12 +235,8 @@ public RpcClient(ConfigurationSource conf, String omServiceId)
Preconditions.checkNotNull(conf);
this.conf = conf;
this.ugi = UserGroupInformation.getCurrentUser();
// Get default acl rights for user and group.
OzoneAclConfig aclConfig = this.conf.getObject(OzoneAclConfig.class);
replicationConfigValidator =
this.conf.getObject(ReplicationConfigValidator.class);
this.userRights = aclConfig.getUserDefaultRights();
this.groupRights = aclConfig.getGroupDefaultRights();

this.clientConfig = conf.getObject(OzoneClientConfig.class);
this.ecReconstructExecutor = MemoizedSupplier.valueOf(() -> createThreadPoolExecutor(
Expand Down Expand Up @@ -450,20 +437,6 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
ugi.getShortUserName() : volArgs.getOwner();
long quotaInNamespace = volArgs.getQuotaInNamespace();
long quotaInBytes = volArgs.getQuotaInBytes();
List<OzoneAcl> listOfAcls = new ArrayList<>();
//User ACL
listOfAcls.add(new OzoneAcl(ACLIdentityType.USER,
owner, ACCESS, userRights));
//Group ACLs of the User
List<String> userGroups = Arrays.asList(UserGroupInformation
.createRemoteUser(owner).getGroupNames());
userGroups.stream().forEach((group) -> listOfAcls.add(
new OzoneAcl(ACLIdentityType.GROUP, group, ACCESS, groupRights)));
//ACLs from VolumeArgs
List<OzoneAcl> volumeAcls = volArgs.getAcls();
if (volumeAcls != null) {
listOfAcls.addAll(volumeAcls);
}

OmVolumeArgs.Builder builder = OmVolumeArgs.newBuilder();
builder.setVolume(volumeName);
Expand All @@ -473,11 +446,14 @@ public void createVolume(String volumeName, VolumeArgs volArgs)
builder.setQuotaInNamespace(quotaInNamespace);
builder.setUsedNamespace(0L);
builder.addAllMetadata(volArgs.getMetadata());

//Remove duplicates and add ACLs
for (OzoneAcl ozoneAcl :
listOfAcls.stream().distinct().collect(Collectors.toList())) {
builder.addOzoneAcls(ozoneAcl);
//ACLs from VolumeArgs
List<OzoneAcl> volumeAcls = volArgs.getAcls();
if (volumeAcls != null) {
//Remove duplicates and add ACLs
for (OzoneAcl ozoneAcl :
volumeAcls.stream().distinct().collect(Collectors.toList())) {
builder.addOzoneAcls(ozoneAcl);
}
}

if (volArgs.getQuotaInBytes() == 0) {
Expand Down Expand Up @@ -667,17 +643,6 @@ public void createBucket(
.setKeyName(bucketArgs.getEncryptionKey()).build();
}

List<OzoneAcl> listOfAcls = getAclList();
//ACLs from BucketArgs
if (bucketArgs.getAcls() != null) {
listOfAcls.addAll(bucketArgs.getAcls());
}
// Link bucket default acl
if (bucketArgs.getSourceVolume() != null
&& bucketArgs.getSourceBucket() != null) {
listOfAcls.add(linkBucketDefaultAcl());
}

OmBucketInfo.Builder builder = OmBucketInfo.newBuilder();
builder.setVolumeName(volumeName)
.setBucketName(bucketName)
Expand All @@ -688,10 +653,19 @@ public void createBucket(
.setSourceBucket(bucketArgs.getSourceBucket())
.setQuotaInBytes(bucketArgs.getQuotaInBytes())
.setQuotaInNamespace(bucketArgs.getQuotaInNamespace())
.setAcls(listOfAcls.stream().distinct().collect(Collectors.toList()))
.setBucketLayout(bucketLayout)
.setOwner(owner);

if (bucketArgs.getAcls() != null) {
builder.setAcls(bucketArgs.getAcls());
}

// Link bucket default acl
if (bucketArgs.getSourceVolume() != null
&& bucketArgs.getSourceBucket() != null) {
builder.addAcl(LINK_BUCKET_DEFAULT_ACL);
}

if (bek != null) {
builder.setBucketEncryptionKey(bek);
}
Expand Down Expand Up @@ -752,17 +726,6 @@ private static void verifySpaceQuota(long quota) throws OMException {
}
}

/**
* Helper function to get default acl list for current user.
*
* @return listOfAcls
* */
private List<OzoneAcl> getAclList() {
UserGroupInformation realUserInfo = getRealUserInfo();
return OzoneAclUtil.getAclList(realUserInfo.getUserName(),
realUserInfo.getGroupNames(), userRights, groupRights);
}

/**
* Helper function to get the actual operating user.
*
Expand All @@ -778,16 +741,6 @@ private UserGroupInformation getRealUserInfo() {
return ugi;
}

/**
* Link bucket default acl defined [world::rw]
* which is similar to Linux POSIX symbolic.
*
* @return OzoneAcl
*/
private OzoneAcl linkBucketDefaultAcl() {
return new OzoneAcl(ACLIdentityType.WORLD, "", ACCESS, READ, WRITE);
}

/**
* Get a valid Delegation Token.
*
Expand Down Expand Up @@ -1427,7 +1380,6 @@ public OzoneOutputStream createKey(
.setReplicationConfig(replicationConfig)
.addAllMetadataGdpr(metadata)
.addAllTags(tags)
.setAcls(getAclList())
.setLatestVersionLocation(getLatestVersionLocation)
.setOwnerName(ownerName);

Expand Down Expand Up @@ -1536,7 +1488,6 @@ public OzoneDataStreamOutput createStreamKey(
.addAllMetadataGdpr(metadata)
.addAllTags(tags)
.setSortDatanodesInPipeline(true)
.setAcls(getAclList())
.setOwnerName(ownerName);

OpenKeySession openKey = ozoneManagerClient.openKey(builder.build());
Expand Down Expand Up @@ -1955,7 +1906,6 @@ public OmMultipartInfo initiateMultipartUpload(String volumeName,
.setBucketName(bucketName)
.setKeyName(keyName)
.setReplicationConfig(replicationConfig)
.setAcls(getAclList())
.addAllMetadataGdpr(metadata)
.setOwnerName(ownerName)
.addAllTags(tags)
Expand Down Expand Up @@ -1992,7 +1942,6 @@ private OpenKeySession newMultipartOpenKey(
.setMultipartUploadID(uploadID)
.setMultipartUploadPartNumber(partNumber)
.setSortDatanodesInPipeline(sortDatanodesInPipeline)
.setAcls(getAclList())
.setOwnerName(ownerName)
.build();
return ozoneManagerClient.openKey(keyArgs);
Expand Down Expand Up @@ -2064,7 +2013,6 @@ public OmMultipartUploadCompleteInfo completeMultipartUpload(
.setBucketName(bucketName)
.setKeyName(keyName)
.setMultipartUploadID(uploadID)
.setAcls(getAclList())
.setOwnerName(ownerName)
.build();

Expand Down Expand Up @@ -2169,7 +2117,6 @@ public void createDirectory(String volumeName, String bucketName,
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
.setBucketName(bucketName)
.setKeyName(keyName)
.setAcls(getAclList())
.setOwnerName(ownerName)
.build();
ozoneManagerClient.createDirectory(keyArgs);
Expand Down Expand Up @@ -2250,7 +2197,6 @@ public OzoneOutputStream createFile(String volumeName, String bucketName,
.setKeyName(keyName)
.setDataSize(size)
.setReplicationConfig(replicationConfig)
.setAcls(getAclList())
.setLatestVersionLocation(getLatestVersionLocation)
.setOwnerName(ownerName)
.build();
Expand Down Expand Up @@ -2282,7 +2228,6 @@ public OzoneDataStreamOutput createStreamFile(String volumeName,
.setKeyName(keyName)
.setDataSize(size)
.setReplicationConfig(replicationConfig)
.setAcls(getAclList())
.setLatestVersionLocation(getLatestVersionLocation)
.setSortDatanodesInPipeline(true)
.setOwnerName(ownerName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OzoneAclInfo;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OzoneAclInfo.OzoneAclScope;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OzoneAclInfo.OzoneAclType;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLIdentityType;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
import org.apache.ratis.util.MemoizedSupplier;
Expand All @@ -41,8 +42,11 @@
import java.util.function.IntFunction;
import java.util.function.Supplier;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.ALL;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.NONE;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.READ;
import static org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType.WRITE;

/**
* OzoneACL classes define bucket ACLs used in OZONE.
Expand All @@ -58,6 +62,13 @@
public class OzoneAcl {

private static final String ACL_SCOPE_REGEX = ".*\\[(ACCESS|DEFAULT)\\]";
/**
* Link bucket default acl defined [world::rw]
* which is similar to Linux POSIX symbolic.
*/
public static final OzoneAcl LINK_BUCKET_DEFAULT_ACL =
new OzoneAcl(IAccessAuthorizer.ACLIdentityType.WORLD, "", ACCESS, READ, WRITE);

private final ACLIdentityType type;
private final String name;
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@

package org.apache.hadoop.ozone.om.helpers;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.OzoneAcl;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OzoneAclInfo;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer.ACLType;
import org.apache.hadoop.ozone.security.acl.OzoneAclConfig;
import org.apache.hadoop.ozone.security.acl.RequestContext;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.ozone.OzoneAcl.AclScope.ACCESS;
import static org.apache.hadoop.ozone.OzoneAcl.AclScope.DEFAULT;
Expand All @@ -43,28 +47,51 @@
* Helper class for ozone acls operations.
*/
public final class OzoneAclUtil {
static final Logger LOG = LoggerFactory.getLogger(OzoneAclUtil.class);

private OzoneAclUtil() {
}

private static ACLType[] userRights;
private static ACLType[] groupRights;

/**
* Helper function to get access acl list for current user.
* Helper function to get default access acl list for current user.
*
* @param userName
* @param userGroups
* @param ugi current login user
* @param conf current configuration
* @return list of OzoneAcls
* */
public static List<OzoneAcl> getAclList(String userName,
String[] userGroups, ACLType userRights, ACLType groupRights) {

public static List<OzoneAcl> getDefaultAclList(UserGroupInformation ugi, OzoneConfiguration conf) {
// Get default acl rights for user and group.
if (userRights == null || groupRights == null) {
OzoneAclConfig aclConfig = conf.getObject(OzoneAclConfig.class);
userRights = aclConfig.getUserDefaultRights();
groupRights = aclConfig.getGroupDefaultRights();
}
List<OzoneAcl> listOfAcls = new ArrayList<>();
// User ACL.
listOfAcls.add(new OzoneAcl(USER, ugi.getShortUserName(), ACCESS, userRights));
try {
String groupName = ugi.getPrimaryGroupName();
listOfAcls.add(new OzoneAcl(GROUP, groupName, ACCESS, groupRights));
} catch (IOException e) {
// do nothing, since user has the permission, user can add ACL for selected groups later.
LOG.warn("Failed to get primary group from user {}", ugi);
}
return listOfAcls;
}

public static List<OzoneAcl> getAclList(UserGroupInformation ugi, ACLType userPrivilege, ACLType groupPrivilege) {
List<OzoneAcl> listOfAcls = new ArrayList<>();
// User ACL.
listOfAcls.add(new OzoneAcl(USER, userName, ACCESS, userRights));
if (userGroups != null) {
// Group ACLs of the User.
Arrays.asList(userGroups).forEach((group) -> listOfAcls.add(
new OzoneAcl(GROUP, group, ACCESS, groupRights)));
listOfAcls.add(new OzoneAcl(USER, ugi.getShortUserName(), ACCESS, userPrivilege));
try {
String groupName = ugi.getPrimaryGroupName();
listOfAcls.add(new OzoneAcl(GROUP, groupName, ACCESS, groupPrivilege));
} catch (IOException e) {
// do nothing, since user has the permission, user can add ACL for selected groups later.
LOG.warn("Failed to get primary group from user {}", ugi);
}
return listOfAcls;
}
Expand Down
Loading
Loading