-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-14574. Enforce 700 permissions on Ozone Metadata and Data(hdds) directories #9735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,8 @@ | |
| import org.apache.hadoop.fs.StorageType; | ||
| import org.apache.hadoop.hdds.conf.ConfigurationSource; | ||
| import org.apache.hadoop.hdds.fs.SpaceUsageCheckFactory; | ||
| import org.apache.hadoop.hdds.scm.ScmConfigKeys; | ||
| import org.apache.hadoop.hdds.server.ServerUtils; | ||
| import org.apache.hadoop.hdds.utils.HddsServerUtil; | ||
| import org.apache.hadoop.hdfs.server.datanode.StorageLocation; | ||
| import org.apache.hadoop.ozone.container.common.impl.StorageLocationReport; | ||
|
|
@@ -179,6 +181,15 @@ private void initializeVolumeSet() throws IOException { | |
| throw new IOException("Failed to create storage dir " + | ||
| volume.getStorageDir()); | ||
| } | ||
|
|
||
| // Ensure permissions are set on the storage directory | ||
| // (permissions are also set in StorageVolume.initializeImpl(), | ||
| // but this ensures they're set even if directory already existed | ||
| // from a previous run with incorrect permissions) | ||
| if (volumeType == StorageVolume.VolumeType.DATA_VOLUME) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is required only for datavolume other other volume types ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| ServerUtils.setDataDirectoryPermissions(volume.getStorageDir(), conf, | ||
| ScmConfigKeys.HDDS_DATANODE_DATA_DIR_PERMISSIONS); | ||
| } | ||
| volumeMap.put(volume.getStorageDir().getPath(), volume); | ||
| volumeStateMap.get(volume.getStorageType()).add(volume); | ||
| volumeHealthMetrics.incrementHealthyVolumes(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| package org.apache.hadoop.ozone.container.common.volume; | ||
|
|
||
| import static org.apache.hadoop.ozone.container.common.HDDSVolumeLayoutVersion.getLatestVersion; | ||
| import static org.apache.hadoop.ozone.container.common.volume.HddsVolume.HDDS_VOLUME_DIR; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import com.google.common.base.Preconditions; | ||
|
|
@@ -40,6 +41,8 @@ | |
| import org.apache.hadoop.hdds.fs.SpaceUsageCheckFactory; | ||
| import org.apache.hadoop.hdds.fs.SpaceUsageCheckParams; | ||
| import org.apache.hadoop.hdds.fs.SpaceUsageSource; | ||
| import org.apache.hadoop.hdds.scm.ScmConfigKeys; | ||
| import org.apache.hadoop.hdds.server.ServerUtils; | ||
| import org.apache.hadoop.hdfs.server.datanode.StorageLocation; | ||
| import org.apache.hadoop.hdfs.server.datanode.checker.Checkable; | ||
| import org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult; | ||
|
|
@@ -226,16 +229,22 @@ protected void initializeImpl() throws IOException { | |
| if (!getStorageDir().mkdirs()) { | ||
| throw new IOException("Cannot create directory " + getStorageDir()); | ||
| } | ||
| // Set permissions on storage directory (e.g., hdds subdirectory) | ||
| setStorageDirPermissions(); | ||
| setState(VolumeState.NOT_FORMATTED); | ||
| createVersionFile(); | ||
| break; | ||
| case NOT_FORMATTED: | ||
| // Version File does not exist. Create it. | ||
| // Ensure permissions are correct even if directory already existed | ||
| setStorageDirPermissions(); | ||
| createVersionFile(); | ||
| break; | ||
| case NOT_INITIALIZED: | ||
| // Version File exists. | ||
| // Verify its correctness and update property fields. | ||
| // Ensure permissions are correct even if directory already existed | ||
| setStorageDirPermissions(); | ||
| readVersionFile(); | ||
| setState(VolumeState.NORMAL); | ||
| break; | ||
|
|
@@ -461,6 +470,10 @@ public boolean getFailedVolume() { | |
| public StorageType getStorageType() { | ||
| return this.storageType; | ||
| } | ||
|
|
||
| public String getStorageDirStr() { | ||
| return this.storageDirStr; | ||
| } | ||
| } | ||
|
|
||
| public String getVolumeRootDir() { | ||
|
|
@@ -768,11 +781,31 @@ private static SpaceUsageCheckParams getSpaceUsageCheckParams(Builder b, Supplie | |
| throw new IOException("Unable to create the volume root dir at " + root); | ||
| } | ||
|
|
||
| // Set permissions on volume root directory immediately after creation/check | ||
| // (for data volumes, we want to ensure the root has secure permissions, | ||
| // even if the directory already existed from a previous run) | ||
| // This follows the same pattern as metadata directories in getDirectoryFromConfig() | ||
| if (b.conf != null && root.exists() && HDDS_VOLUME_DIR.equals(b.getStorageDirStr())) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is called here also, and even during loading root also, check if this is duplicate OR for different path.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not duplicates - they set permissions on different paths. Line 789 sets permissions on the volume root (e.g., /data/hdds1), while line 807 sets permissions on the storage directory (e.g., /data/hdds1/hdds). Both levels need secure permissions for defense-in-depth. |
||
| ServerUtils.setDataDirectoryPermissions(root, b.conf, | ||
| ScmConfigKeys.HDDS_DATANODE_DATA_DIR_PERMISSIONS); | ||
| } | ||
|
|
||
| SpaceUsageCheckFactory usageCheckFactory = b.usageCheckFactory; | ||
| if (usageCheckFactory == null) { | ||
| usageCheckFactory = SpaceUsageCheckFactory.create(b.conf); | ||
| } | ||
|
|
||
| return usageCheckFactory.paramsFor(root, exclusionProvider); | ||
| } | ||
|
|
||
| /** | ||
| * Sets permissions on the storage directory (e.g., hdds subdirectory). | ||
| */ | ||
| private void setStorageDirPermissions() { | ||
Gargi-jais11 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (conf != null && getStorageDir().exists() | ||
| && HDDS_VOLUME_DIR.equals(getStorageDir().getName())) { | ||
| ServerUtils.setDataDirectoryPermissions(getStorageDir(), conf, | ||
| ScmConfigKeys.HDDS_DATANODE_DATA_DIR_PERMISSIONS); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.