Removed sensitive storages from the DAV mounts and allowed to limit the number of object storages by tags (default: dav-mount=true)
@@ -94,6 +94,10 @@ _API_URL="$1"
_API_TOKEN="$2"
_MOUNT_ROOT="$3"
+_DAV_MOUNT_TAG_NAME=${CP_DAV_MOUNT_TAG_NAME:-"dav-mount"}
+_DAV_MOUNT_TAG_VALUE=${CP_DAV_MOUNT_TAG_VALUE:-"true"}
+_DAV_MOUNT_ALL_S3=${CP_DAV_MOUNT_ALL_S3:-"false"}
+
if [ -z "$_API_URL" ] || [ -z "$_API_TOKEN" ] || [ -z "$_MOUNT_ROOT" ]; then
echo "[ERROR] Not enough input parameters, exiting"
exit 1
@@ -184,7 +188,9 @@ done <<< "$fs_mounts"
echo
storages="$(curl -sfk -H "Authorization: Bearer ${_API_TOKEN}" ${_API_URL%/}/datastorage/loadAll | \
- jq -r '.payload[] | select(.type!="NFS") | "\(.id)|\(.name)|\(.path)|\(.type)|\(.regionId)"')"
+ jq -r '.payload[] | select(.type!="NFS" and .sensitive==false) | "\(.id)|\(.name)|\(.path)|\(.type)|\(.regionId)"')"
+storages_allowed_for_mount="$(curl -sfk -H "Authorization: Bearer ${_API_TOKEN}" "${_API_URL%/}/metadata/search?entityClass=DATA_STORAGE&key=${_DAV_MOUNT_TAG_NAME}&value=${_DAV_MOUNT_TAG_VALUE}" | \
+ jq -r '.payload[] | .entityId')"
if [ $? -ne 0 ]; then
echo "[ERROR] Cannot get list of the storages, exiting"
@@ -206,6 +212,12 @@ while IFS='|' read -r id name path type region_id; do
continue
fi
+ # Check if the object storage is allowed to be mounted (via tag/value)
+ if [[ ! " ${storages_allowed_for_mount[@]} " =~ " ${id} " ]] && [ "$_DAV_MOUNT_ALL_S3" != "true" ]; then
+ echo "[INFO] Storage with id: ${id} and path: ${path} is not tagged with ${_DAV_MOUNT_TAG_NAME}=${_DAV_MOUNT_TAG_VALUE}, skipping."
+ continue
+ fi
+
if mountpoint -q "$mount_root_srv_dir"; then
echo "[DONE] $mount_root_srv_dir is already mounted, skipping"
mounted_dirs+=($(remove_trailing_slashes "$mount_root_srv_dir"))
