Skip to content

Commit

Permalink
HDDS-9950. 'ozone fs -ls' on volume shows the volume owner as the buc…
Browse files Browse the repository at this point in the history
…ket owner (#5816)
  • Loading branch information
xBis7 authored Dec 20, 2023
1 parent dc0a104 commit 077e09b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,39 @@ private void teardownVolumeBucketWithDir(Path bucketPath1)
objectStore.deleteVolume(ofsPath.getVolumeName());
}

/**
* Create a bucket with a different owner than the volume owner
* and test the owner on listStatus.
*/
@Test
public void testListStatusWithDifferentBucketOwner() throws IOException {
String volName = getRandomNonExistVolumeName();
objectStore.createVolume(volName);
OzoneVolume ozoneVolume = objectStore.getVolume(volName);

String buckName = "bucket-" + RandomStringUtils.randomNumeric(5);
UserGroupInformation currUgi = UserGroupInformation.getCurrentUser();
String bucketOwner = currUgi.getUserName() + RandomStringUtils.randomNumeric(5);
BucketArgs bucketArgs = BucketArgs.newBuilder()
.setOwner(bucketOwner)
.build();
ozoneVolume.createBucket(buckName, bucketArgs);

Path volPath = new Path(OZONE_URI_DELIMITER + volName);

OzoneBucket ozoneBucket = ozoneVolume.getBucket(buckName);

FileStatus[] fileStatusVolume = ofs.listStatus(volPath);
assertEquals(1, fileStatusVolume.length);
// FileStatus owner is different from the volume owner.
// Owner is the same as the bucket owner returned by the ObjectStore.
assertNotEquals(ozoneVolume.getOwner(), fileStatusVolume[0].getOwner());
assertEquals(ozoneBucket.getOwner(), fileStatusVolume[0].getOwner());

ozoneVolume.deleteBucket(buckName);
objectStore.deleteVolume(volName);
}

/**
* OFS: Test non-recursive listStatus on root and volume.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,12 @@ private List<FileStatusAdapter> listStatusVolume(String volumeStr,
OFSPath ofsStartPath = new OFSPath(startPath, config);
// list buckets in the volume
OzoneVolume volume = objectStore.getVolume(volumeStr);
UserGroupInformation ugi =
UserGroupInformation.createRemoteUser(volume.getOwner());
String owner = ugi.getShortUserName();
String group = getGroupName(ugi);
Iterator<? extends OzoneBucket> iter =
volume.listBuckets(null, ofsStartPath.getBucketName());
List<FileStatusAdapter> res = new ArrayList<>();
while (iter.hasNext() && res.size() < numEntries) {
OzoneBucket bucket = iter.next();
res.add(getFileStatusAdapterForBucket(bucket, uri, owner, group));
res.add(getFileStatusAdapterForBucket(bucket, uri));
if (recursive) {
String pathStrNext = volumeStr + OZONE_URI_DELIMITER + bucket.getName();
res.addAll(listStatus(pathStrNext, recursive, startPath,
Expand Down Expand Up @@ -1112,12 +1108,9 @@ private static FileStatusAdapter getFileStatusAdapterForVolume(
* Generate a FileStatusAdapter for a bucket.
* @param ozoneBucket OzoneBucket object.
* @param uri Full URI to OFS root.
* @param owner Owner of the parent volume of the bucket.
* @param group Group of the parent volume of the bucket.
* @return FileStatusAdapter for a bucket.
*/
private static FileStatusAdapter getFileStatusAdapterForBucket(
OzoneBucket ozoneBucket, URI uri, String owner, String group) {
private static FileStatusAdapter getFileStatusAdapterForBucket(OzoneBucket ozoneBucket, URI uri) {
String pathStr = uri.toString() +
OZONE_URI_DELIMITER + ozoneBucket.getVolumeName() +
OZONE_URI_DELIMITER + ozoneBucket.getName();
Expand All @@ -1127,6 +1120,9 @@ private static FileStatusAdapter getFileStatusAdapterForBucket(
ozoneBucket.getName(), pathStr);
}
Path path = new Path(pathStr);
UserGroupInformation ugi = UserGroupInformation.createRemoteUser(ozoneBucket.getOwner());
String owner = ugi.getShortUserName();
String group = getGroupName(ugi);
return new FileStatusAdapter(0L, 0L, path, true, (short)0, 0L,
ozoneBucket.getCreationTime().getEpochSecond() * 1000, 0L,
FsPermission.getDirDefault().toShort(),
Expand Down

0 comments on commit 077e09b

Please sign in to comment.