Skip to content

Commit

Permalink
[ALLUXIO-3307] set ufs ACL on the createFile path (#7844)
Browse files Browse the repository at this point in the history
* refactor proto and pass ACL info when creating new ufs file

* update createOptions to contain acl info

* add a setAcl call to initialize file's acl if it is provided in createOptions.

* fix checkstyle

* add the missing file

* modify findbugs-exclude.xml

* fix compilation

* Add comment
  • Loading branch information
yuzhu authored and gpang committed Sep 24, 2018
1 parent 6ecffe5 commit 80b4b74
Show file tree
Hide file tree
Showing 19 changed files with 5,106 additions and 4,805 deletions.
1 change: 1 addition & 0 deletions build/findbugs/findbugs-exclude.xml
Expand Up @@ -6,6 +6,7 @@
<Package name="alluxio.thrift"/> <Package name="alluxio.thrift"/>
<Package name="alluxio.proto.journal.*"/> <Package name="alluxio.proto.journal.*"/>
<Package name="alluxio.proto.dataserver.*"/> <Package name="alluxio.proto.dataserver.*"/>
<Package name="alluxio.proto.shared.*"/>
</Or> </Or>
</Match> </Match>


Expand Down
Expand Up @@ -26,6 +26,7 @@
import alluxio.proto.dataserver.Protocol; import alluxio.proto.dataserver.Protocol;
import alluxio.proto.status.Status.PStatus; import alluxio.proto.status.Status.PStatus;
import alluxio.resource.LockResource; import alluxio.resource.LockResource;
import alluxio.security.authorization.AccessControlList;
import alluxio.util.CommonUtils; import alluxio.util.CommonUtils;
import alluxio.util.proto.ProtoMessage; import alluxio.util.proto.ProtoMessage;
import alluxio.wire.WorkerNetAddress; import alluxio.wire.WorkerNetAddress;
Expand Down Expand Up @@ -167,7 +168,9 @@ private NettyPacketWriter(FileSystemContext context, final WorkerNetAddress addr
Protocol.CreateUfsFileOptions ufsFileOptions = Protocol.CreateUfsFileOptions ufsFileOptions =
Protocol.CreateUfsFileOptions.newBuilder().setUfsPath(options.getUfsPath()) Protocol.CreateUfsFileOptions.newBuilder().setUfsPath(options.getUfsPath())
.setOwner(options.getOwner()).setGroup(options.getGroup()) .setOwner(options.getOwner()).setGroup(options.getGroup())
.setMode(options.getMode().toShort()).setMountId(options.getMountId()).build(); .setMode(options.getMode().toShort()).setMountId(options.getMountId())
.setAcl(AccessControlList.toProtoBuf(options.getAcl()))
.build();
builder.setCreateUfsFileOptions(ufsFileOptions); builder.setCreateUfsFileOptions(ufsFileOptions);
} }
mPartialRequest = builder.buildPartial(); mPartialRequest = builder.buildPartial();
Expand Down
Expand Up @@ -148,6 +148,7 @@ public FileOutStream createFile(AlluxioURI path, CreateFileOptions options)
OutStreamOptions outStreamOptions = options.toOutStreamOptions(); OutStreamOptions outStreamOptions = options.toOutStreamOptions();
outStreamOptions.setUfsPath(status.getUfsPath()); outStreamOptions.setUfsPath(status.getUfsPath());
outStreamOptions.setMountId(status.getMountId()); outStreamOptions.setMountId(status.getMountId());
outStreamOptions.setAcl(status.getAcl());
try { try {
return new FileOutStream(path, outStreamOptions, mFileSystemContext); return new FileOutStream(path, outStreamOptions, mFileSystemContext);
} catch (Exception e) { } catch (Exception e) {
Expand Down
Expand Up @@ -19,6 +19,7 @@
import alluxio.client.UnderStorageType; import alluxio.client.UnderStorageType;
import alluxio.client.WriteType; import alluxio.client.WriteType;
import alluxio.client.file.policy.FileWriteLocationPolicy; import alluxio.client.file.policy.FileWriteLocationPolicy;
import alluxio.security.authorization.AccessControlList;
import alluxio.security.authorization.Mode; import alluxio.security.authorization.Mode;
import alluxio.util.CommonUtils; import alluxio.util.CommonUtils;
import alluxio.util.IdUtils; import alluxio.util.IdUtils;
Expand All @@ -44,6 +45,7 @@ public final class OutStreamOptions {
private String mOwner; private String mOwner;
private String mGroup; private String mGroup;
private Mode mMode; private Mode mMode;
private AccessControlList mAcl;
private String mUfsPath; private String mUfsPath;
private long mMountId; private long mMountId;


Expand All @@ -70,6 +72,13 @@ private OutStreamOptions() {
mMountId = IdUtils.INVALID_MOUNT_ID; mMountId = IdUtils.INVALID_MOUNT_ID;
} }


/**
* @return the acl
*/
public AccessControlList getAcl() {
return mAcl;
}

/** /**
* @return the block size * @return the block size
*/ */
Expand Down Expand Up @@ -162,6 +171,17 @@ public WriteType getWriteType() {
return mWriteType; return mWriteType;
} }


/**
* Sets the acl of the file.
*
* @param acl the acl to use
* @return the updated options object
*/
public OutStreamOptions setAcl(AccessControlList acl) {
mAcl = acl;
return this;
}

/** /**
* Sets the size of the block in bytes. * Sets the size of the block in bytes.
* *
Expand Down Expand Up @@ -281,7 +301,8 @@ public boolean equals(Object o) {
return false; return false;
} }
OutStreamOptions that = (OutStreamOptions) o; OutStreamOptions that = (OutStreamOptions) o;
return Objects.equal(mBlockSizeBytes, that.mBlockSizeBytes) return Objects.equal(mAcl, that.mAcl)
&& Objects.equal(mBlockSizeBytes, that.mBlockSizeBytes)
&& Objects.equal(mGroup, that.mGroup) && Objects.equal(mGroup, that.mGroup)
&& Objects.equal(mLocationPolicy, that.mLocationPolicy) && Objects.equal(mLocationPolicy, that.mLocationPolicy)
&& Objects.equal(mMode, that.mMode) && Objects.equal(mMode, that.mMode)
Expand All @@ -297,6 +318,7 @@ public boolean equals(Object o) {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode( return Objects.hashCode(
mAcl,
mBlockSizeBytes, mBlockSizeBytes,
mGroup, mGroup,
mLocationPolicy, mLocationPolicy,
Expand All @@ -314,6 +336,7 @@ public int hashCode() {
@Override @Override
public String toString() { public String toString() {
return Objects.toStringHelper(this) return Objects.toStringHelper(this)
.add("acl", mAcl)
.add("blockSizeBytes", mBlockSizeBytes) .add("blockSizeBytes", mBlockSizeBytes)
.add("group", mGroup) .add("group", mGroup)
.add("locationPolicy", mLocationPolicy) .add("locationPolicy", mLocationPolicy)
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;
import alluxio.thrift.TAcl; import alluxio.thrift.TAcl;
import alluxio.thrift.TAclEntry; import alluxio.thrift.TAclEntry;


Expand Down Expand Up @@ -392,7 +392,7 @@ public int hashCode() {
* @param acl the protobuf representation * @param acl the protobuf representation
* @return {@link AccessControlList} * @return {@link AccessControlList}
*/ */
public static AccessControlList fromProtoBuf(File.AccessControlList acl) { public static AccessControlList fromProtoBuf(Acl.AccessControlList acl) {
AccessControlList ret; AccessControlList ret;
if (acl.hasIsDefault() && acl.getIsDefault()) { if (acl.hasIsDefault() && acl.getIsDefault()) {
ret = new DefaultAccessControlList(); ret = new DefaultAccessControlList();
Expand All @@ -409,7 +409,7 @@ public static AccessControlList fromProtoBuf(File.AccessControlList acl) {
// true if there are any extended entries (named user or named group) // true if there are any extended entries (named user or named group)
boolean hasExtended = false; boolean hasExtended = false;


for (File.NamedAclActions namedActions : acl.getUserActionsList()) { for (Acl.NamedAclActions namedActions : acl.getUserActionsList()) {
String name = namedActions.getName(); String name = namedActions.getName();
AclActions actions = AclActions.fromProtoBuf(namedActions.getActions()); AclActions actions = AclActions.fromProtoBuf(namedActions.getActions());
AclEntry entry; AclEntry entry;
Expand All @@ -424,7 +424,7 @@ public static AccessControlList fromProtoBuf(File.AccessControlList acl) {
ret.setEntry(entry); ret.setEntry(entry);
} }


for (File.NamedAclActions namedActions : acl.getGroupActionsList()) { for (Acl.NamedAclActions namedActions : acl.getGroupActionsList()) {
String name = namedActions.getName(); String name = namedActions.getName();
AclActions actions = AclActions.fromProtoBuf(namedActions.getActions()); AclActions actions = AclActions.fromProtoBuf(namedActions.getActions());
AclEntry entry; AclEntry entry;
Expand Down Expand Up @@ -459,17 +459,17 @@ public static AccessControlList fromProtoBuf(File.AccessControlList acl) {
* @param acl {@link AccessControlList} * @param acl {@link AccessControlList}
* @return protobuf representation * @return protobuf representation
*/ */
public static File.AccessControlList toProtoBuf(AccessControlList acl) { public static Acl.AccessControlList toProtoBuf(AccessControlList acl) {
File.AccessControlList.Builder builder = File.AccessControlList.newBuilder(); Acl.AccessControlList.Builder builder = Acl.AccessControlList.newBuilder();
builder.setOwningUser(acl.mOwningUser); builder.setOwningUser(acl.mOwningUser);
builder.setOwningGroup(acl.mOwningGroup); builder.setOwningGroup(acl.mOwningGroup);


// base entries // base entries
builder.addUserActions(File.NamedAclActions.newBuilder() builder.addUserActions(Acl.NamedAclActions.newBuilder()
.setName(OWNING_USER_KEY) .setName(OWNING_USER_KEY)
.setActions(AclActions.toProtoBuf(acl.getOwningUserActions())) .setActions(AclActions.toProtoBuf(acl.getOwningUserActions()))
.build()); .build());
builder.addGroupActions(File.NamedAclActions.newBuilder() builder.addGroupActions(Acl.NamedAclActions.newBuilder()
.setName(OWNING_GROUP_KEY) .setName(OWNING_GROUP_KEY)
.setActions(AclActions.toProtoBuf(acl.getOwningGroupActions())) .setActions(AclActions.toProtoBuf(acl.getOwningGroupActions()))
.build()); .build());
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;
import alluxio.thrift.TAclAction; import alluxio.thrift.TAclAction;


/** /**
Expand All @@ -38,7 +38,7 @@ public static AclAction ofOrdinal(int ordinal) {
* @param action the protobuf representation of {@link AclAction} * @param action the protobuf representation of {@link AclAction}
* @return the {@link AclAction} decoded from the protobuf representation * @return the {@link AclAction} decoded from the protobuf representation
*/ */
public static AclAction fromProtoBuf(File.AclAction action) { public static AclAction fromProtoBuf(Acl.AclAction action) {
switch (action) { switch (action) {
case READ: case READ:
return READ; return READ;
Expand All @@ -54,14 +54,14 @@ public static AclAction fromProtoBuf(File.AclAction action) {
/** /**
* @return the protobuf representation of action * @return the protobuf representation of action
*/ */
public File.AclAction toProtoBuf() { public Acl.AclAction toProtoBuf() {
switch (this) { switch (this) {
case READ: case READ:
return File.AclAction.READ; return Acl.AclAction.READ;
case WRITE: case WRITE:
return File.AclAction.WRITE; return Acl.AclAction.WRITE;
case EXECUTE: case EXECUTE:
return File.AclAction.EXECUTE; return Acl.AclAction.EXECUTE;
default: default:
throw new IllegalStateException("Unknown acl action: " + this); throw new IllegalStateException("Unknown acl action: " + this);
} }
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;


import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
Expand Down Expand Up @@ -190,9 +190,9 @@ public Mode.Bits toModeBits() {
* @param actions the protobuf representation of {@link AclActions} * @param actions the protobuf representation of {@link AclActions}
* @return the {@link AclActions} decoded from the protobuf representation * @return the {@link AclActions} decoded from the protobuf representation
*/ */
public static AclActions fromProtoBuf(File.AclActions actions) { public static AclActions fromProtoBuf(Acl.AclActions actions) {
AclActions ret = new AclActions(); AclActions ret = new AclActions();
for (File.AclAction action : actions.getActionsList()) { for (Acl.AclAction action : actions.getActionsList()) {
ret.add(AclAction.fromProtoBuf(action)); ret.add(AclAction.fromProtoBuf(action));
} }
return ret; return ret;
Expand All @@ -202,10 +202,10 @@ public static AclActions fromProtoBuf(File.AclActions actions) {
* @param actions the {@link AclActions} * @param actions the {@link AclActions}
* @return the protobuf representation of {@link AclActions} * @return the protobuf representation of {@link AclActions}
*/ */
public static File.AclActions toProtoBuf(AclActions actions) { public static Acl.AclActions toProtoBuf(AclActions actions) {
File.AclActions.Builder builder = File.AclActions.newBuilder(); Acl.AclActions.Builder builder = Acl.AclActions.newBuilder();
for (AclAction action : actions.getActions()) { for (AclAction action : actions.getActions()) {
File.AclAction pAction = action.toProtoBuf(); Acl.AclAction pAction = action.toProtoBuf();
builder.addActions(pAction); builder.addActions(pAction);
} }
return builder.build(); return builder.build();
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;
import alluxio.thrift.TAclAction; import alluxio.thrift.TAclAction;
import alluxio.thrift.TAclEntry; import alluxio.thrift.TAclEntry;


Expand Down Expand Up @@ -340,13 +340,13 @@ public static AclEntry fromCliStringWithoutPermissions(String stringEntry) {
* @param pEntry the proto representation * @param pEntry the proto representation
* @return the {@link AclEntry} instance created from the proto representation * @return the {@link AclEntry} instance created from the proto representation
*/ */
public static AclEntry fromProto(File.AclEntry pEntry) { public static AclEntry fromProto(Acl.AclEntry pEntry) {
AclEntry.Builder builder = new AclEntry.Builder(); AclEntry.Builder builder = new AclEntry.Builder();
builder.setType(AclEntryType.fromProto(pEntry.getType())); builder.setType(AclEntryType.fromProto(pEntry.getType()));
builder.setSubject(pEntry.getSubject()); builder.setSubject(pEntry.getSubject());
builder.setIsDefault(pEntry.getIsDefault()); builder.setIsDefault(pEntry.getIsDefault());


for (File.AclAction pAction : pEntry.getActionsList()) { for (Acl.AclAction pAction : pEntry.getActionsList()) {
builder.addAction(AclAction.fromProtoBuf(pAction)); builder.addAction(AclAction.fromProtoBuf(pAction));
} }
return builder.build(); return builder.build();
Expand All @@ -355,8 +355,8 @@ public static AclEntry fromProto(File.AclEntry pEntry) {
/** /**
* @return the proto representation of this instance * @return the proto representation of this instance
*/ */
public File.AclEntry toProto() { public Acl.AclEntry toProto() {
File.AclEntry.Builder builder = File.AclEntry.newBuilder(); Acl.AclEntry.Builder builder = Acl.AclEntry.newBuilder();
builder.setType(mType.toProto()); builder.setType(mType.toProto());
builder.setSubject(mSubject); builder.setSubject(mSubject);
builder.setIsDefault(mIsDefault); builder.setIsDefault(mIsDefault);
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;
import alluxio.thrift.TAclEntryType; import alluxio.thrift.TAclEntryType;


/** /**
Expand Down Expand Up @@ -54,7 +54,7 @@ public String toCliString() {
* @param pAclEntryType the proto representation * @param pAclEntryType the proto representation
* @return the {@link AclEntryType} created from the proto representation * @return the {@link AclEntryType} created from the proto representation
*/ */
public static AclEntryType fromProto(File.AclEntryType pAclEntryType) { public static AclEntryType fromProto(Acl.AclEntryType pAclEntryType) {
switch (pAclEntryType) { switch (pAclEntryType) {
case OWNER: case OWNER:
return OWNING_USER; return OWNING_USER;
Expand All @@ -76,20 +76,20 @@ public static AclEntryType fromProto(File.AclEntryType pAclEntryType) {
/** /**
* @return the proto representation of this enum * @return the proto representation of this enum
*/ */
public File.AclEntryType toProto() { public Acl.AclEntryType toProto() {
switch (this) { switch (this) {
case OWNING_USER: case OWNING_USER:
return File.AclEntryType.OWNER; return Acl.AclEntryType.OWNER;
case NAMED_USER: case NAMED_USER:
return File.AclEntryType.NAMED_USER; return Acl.AclEntryType.NAMED_USER;
case OWNING_GROUP: case OWNING_GROUP:
return File.AclEntryType.OWNING_GROUP; return Acl.AclEntryType.OWNING_GROUP;
case NAMED_GROUP: case NAMED_GROUP:
return File.AclEntryType.NAMED_GROUP; return Acl.AclEntryType.NAMED_GROUP;
case MASK: case MASK:
return File.AclEntryType.MASK; return Acl.AclEntryType.MASK;
case OTHER: case OTHER:
return File.AclEntryType.OTHER; return Acl.AclEntryType.OTHER;
default: default:
throw new IllegalStateException("Unknown AclEntryType: " + this); throw new IllegalStateException("Unknown AclEntryType: " + this);
} }
Expand Down
Expand Up @@ -11,7 +11,7 @@


package alluxio.security.authorization; package alluxio.security.authorization;


import alluxio.proto.journal.File; import alluxio.proto.shared.Acl;


import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -177,10 +177,10 @@ public AclActions getMask() {
/** /**
* @return a list of the proto representation of the named users actions * @return a list of the proto representation of the named users actions
*/ */
public List<File.NamedAclActions> getNamedUsersProto() { public List<Acl.NamedAclActions> getNamedUsersProto() {
List<File.NamedAclActions> actions = new ArrayList<>(mNamedUserActions.size()); List<Acl.NamedAclActions> actions = new ArrayList<>(mNamedUserActions.size());
for (Map.Entry<String, AclActions> kv : mNamedUserActions.entrySet()) { for (Map.Entry<String, AclActions> kv : mNamedUserActions.entrySet()) {
File.NamedAclActions namedActions = File.NamedAclActions.newBuilder() Acl.NamedAclActions namedActions = Acl.NamedAclActions.newBuilder()
.setName(kv.getKey()) .setName(kv.getKey())
.setActions(AclActions.toProtoBuf(kv.getValue())) .setActions(AclActions.toProtoBuf(kv.getValue()))
.build(); .build();
Expand All @@ -192,10 +192,10 @@ public List<File.NamedAclActions> getNamedUsersProto() {
/** /**
* @return a list of the proto representation of the named group actions * @return a list of the proto representation of the named group actions
*/ */
public List<File.NamedAclActions> getNamedGroupsProto() { public List<Acl.NamedAclActions> getNamedGroupsProto() {
List<File.NamedAclActions> actions = new ArrayList<>(mNamedGroupActions.size()); List<Acl.NamedAclActions> actions = new ArrayList<>(mNamedGroupActions.size());
for (Map.Entry<String, AclActions> kv : mNamedGroupActions.entrySet()) { for (Map.Entry<String, AclActions> kv : mNamedGroupActions.entrySet()) {
File.NamedAclActions namedActions = File.NamedAclActions.newBuilder() Acl.NamedAclActions namedActions = Acl.NamedAclActions.newBuilder()
.setName(kv.getKey()) .setName(kv.getKey())
.setActions(AclActions.toProtoBuf(kv.getValue())) .setActions(AclActions.toProtoBuf(kv.getValue()))
.build(); .build();
Expand Down

0 comments on commit 80b4b74

Please sign in to comment.