]> git.proxmox.com Git - proxmox-backup.git/commitdiff
src/config/acl.rs: introduce more/better datastore privileges
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2020 05:13:06 +0000 (07:13 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2020 05:13:50 +0000 (07:13 +0200)
src/api2/admin/datastore.rs
src/api2/backup.rs
src/api2/pull.rs
src/api2/reader.rs
src/config/acl.rs

index 1109521a942819cba8d0d91d21d179a85597cdcf..ddf3556419ec1ecc5e2fc40595ef5a386c6eb0a8 100644 (file)
@@ -22,7 +22,12 @@ use crate::backup::*;
 use crate::config::datastore;
 use crate::server::WorkerTask;
 use crate::tools;
-use crate::config::acl::{PRIV_DATASTORE_AUDIT, PRIV_DATASTORE_ALLOCATE_SPACE};
+use crate::config::acl::{
+    PRIV_DATASTORE_AUDIT,
+    PRIV_DATASTORE_READ,
+    PRIV_DATASTORE_PRUNE,
+    PRIV_DATASTORE_CREATE_BACKUP,
+};
 
 fn read_backup_index(store: &DataStore, backup_dir: &BackupDir) -> Result<Vec<BackupContent>, Error> {
 
@@ -193,7 +198,7 @@ pub fn list_snapshot_files(
         },
     },
     access: {
-        permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_ALLOCATE_SPACE, false),
+        permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_PRUNE, false),
     },
 )]
 /// Delete backup snapshot.
@@ -406,7 +411,7 @@ const API_METHOD_PRUNE: ApiMethod = ApiMethod::new(
             ("store", false, &DATASTORE_SCHEMA),
         ])
     )
-).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_ALLOCATE_SPACE, false));
+).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_PRUNE, false));
 
 fn prune(
     param: Value,
@@ -530,7 +535,7 @@ fn prune(
         schema: UPID_SCHEMA,
     },
     access: {
-        permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_ALLOCATE_SPACE, false),
+        permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_PRUNE, false),
     },
 )]
 /// Start garbage collection.
@@ -615,7 +620,7 @@ pub const API_METHOD_DOWNLOAD_FILE: ApiMethod = ApiMethod::new(
             ("file-name", false, &BACKUP_ARCHIVE_NAME_SCHEMA),
         ]),
     )
-).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_ALLOCATE_SPACE, false));
+).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_READ, false));
 
 fn download_file(
     _parts: Parts,
@@ -674,7 +679,7 @@ pub const API_METHOD_UPLOAD_BACKUP_LOG: ApiMethod = ApiMethod::new(
             ("backup-time", false, &BACKUP_TIME_SCHEMA),
         ]),
     )
-).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_ALLOCATE_SPACE, false));
+).access(None, &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_CREATE_BACKUP, false));
 
 fn upload_backup_log(
     _parts: Parts,
index 76d08438742bb5a6075cc69af0c4978eb189591c..b3e594ebedde931fc700addb4a363a9fbeafdf5c 100644 (file)
@@ -14,7 +14,7 @@ use crate::tools::{self, WrappedReaderStream};
 use crate::server::{WorkerTask, H2Service};
 use crate::backup::*;
 use crate::api2::types::*;
-use crate::config::acl::PRIV_DATASTORE_ALLOCATE_SPACE;
+use crate::config::acl::PRIV_DATASTORE_CREATE_BACKUP;
 use crate::config::cached_user_info::CachedUserInfo;
 
 mod environment;
@@ -41,7 +41,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
     )
 ).access(
     // Note: parameter 'store' is no uri parameter, so we need to test inside function body
-    Some("The user needs Datastore.AllocateSpace privilege on /datastore/{store}."),
+    Some("The user needs Datastore.CreateBackup privilege on /datastore/{store}."),
     &Permission::Anybody
 );
 
@@ -61,7 +61,7 @@ fn upgrade_to_backup_protocol(
     let store = tools::required_string_param(&param, "store")?.to_owned();
 
     let user_info = CachedUserInfo::new()?;
-    user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_ALLOCATE_SPACE, false)?;
+    user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_CREATE_BACKUP, false)?;
 
     let datastore = DataStore::lookup_datastore(&store)?;
 
index b8d47901f4bd7326f611104c9a04dbc7c23e1588..8e989275f816d852fb2b6870a35e618fcf8e6d71 100644 (file)
@@ -16,7 +16,7 @@ use crate::backup::*;
 use crate::client::*;
 use crate::config::remote;
 use crate::api2::types::*;
-use crate::config::acl::PRIV_DATASTORE_ALLOCATE_SPACE;
+use crate::config::acl::{PRIV_DATASTORE_CREATE_BACKUP, PRIV_DATASTORE_READ};
 use crate::config::cached_user_info::CachedUserInfo;
 
 // fixme: implement filters
@@ -391,7 +391,7 @@ pub async fn pull_store(
     },
     access: {
         // Note: used parameters are no uri parameters, so we need to test inside function body
-        description: "The user needs Datastore.AllocateSpace privilege on '/datastore/{store}' and '/remote/{remote}/{remote-store}'.",
+        description: "The user needs Datastore.CreateBackup privilege on '/datastore/{store}' and Datastore.Read on '/remote/{remote}/{remote-store}'.",
         permission: &Permission::Anybody,
     },
 )]
@@ -408,8 +408,8 @@ async fn pull (
     let user_info = CachedUserInfo::new()?;
 
     let username = rpcenv.get_user().unwrap();
-    user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_ALLOCATE_SPACE, false)?;
-    user_info.check_privs(&username, &["remote", &remote, &remote_store], PRIV_DATASTORE_ALLOCATE_SPACE, false)?;
+    user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_CREATE_BACKUP, false)?;
+    user_info.check_privs(&username, &["remote", &remote, &remote_store], PRIV_DATASTORE_READ, false)?;
 
     let delete = delete.unwrap_or(true);
 
index 72e32cc5ff53f56905a52e47a9c86157d5e4b7a0..88206bd9199a402935a65711311eaba45d0da970 100644 (file)
@@ -15,7 +15,7 @@ use crate::api2::types::*;
 use crate::backup::*;
 use crate::server::{WorkerTask, H2Service};
 use crate::tools;
-use crate::config::acl::PRIV_DATASTORE_ALLOCATE_SPACE;
+use crate::config::acl::PRIV_DATASTORE_READ;
 use crate::config::cached_user_info::CachedUserInfo;
 
 mod environment;
@@ -45,7 +45,7 @@ pub const API_METHOD_UPGRADE_BACKUP: ApiMethod = ApiMethod::new(
     )
 ).access(
     // Note: parameter 'store' is no uri parameter, so we need to test inside function body
-    Some("The user needs Datastore.AllocateSpace privilege on /datastore/{store}."),
+    Some("The user needs Datastore.Read privilege on /datastore/{store}."),
     &Permission::Anybody
 );
 
@@ -64,7 +64,7 @@ fn upgrade_to_backup_reader_protocol(
         let store = tools::required_string_param(&param, "store")?.to_owned();
 
         let user_info = CachedUserInfo::new()?;
-        user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_ALLOCATE_SPACE, false)?;
+        user_info.check_privs(&username, &["datastore", &store], PRIV_DATASTORE_READ, false)?;
 
         let datastore = DataStore::lookup_datastore(&store)?;
 
index b1a669898a66bc50c9ebec75317e2a274670ece2..2cae1c741a6610e464c7210019e1c0ddbc5bc958 100644 (file)
@@ -16,10 +16,12 @@ pub const PRIV_SYS_MODIFY: u64                   = 1 << 1;
 pub const PRIV_SYS_POWER_MANAGEMENT: u64         = 1 << 2;
 
 pub const PRIV_DATASTORE_AUDIT: u64              = 1 << 3;
-pub const PRIV_DATASTORE_MODIFY: u64           = 1 << 4;
-pub const PRIV_DATASTORE_ALLOCATE_SPACE: u64     = 1 << 5;
+pub const PRIV_DATASTORE_MODIFY: u64             = 1 << 4;
+pub const PRIV_DATASTORE_CREATE_BACKUP: u64      = 1 << 5;
+pub const PRIV_DATASTORE_READ: u64               = 1 << 6;
+pub const PRIV_DATASTORE_PRUNE: u64              = 1 << 7;
 
-pub const PRIV_PERMISSIONS_MODIFY: u64           = 1 << 6;
+pub const PRIV_PERMISSIONS_MODIFY: u64           = 1 << 8;
 
 pub const ROLE_ADMIN: u64 = std::u64::MAX;
 pub const ROLE_NO_ACCESS: u64 = 0;
@@ -31,13 +33,16 @@ PRIV_DATASTORE_AUDIT;
 pub const ROLE_DATASTORE_ADMIN: u64 =
 PRIV_DATASTORE_AUDIT |
 PRIV_DATASTORE_MODIFY |
-PRIV_DATASTORE_ALLOCATE_SPACE;
+PRIV_DATASTORE_CREATE_BACKUP |
+PRIV_DATASTORE_READ |
+PRIV_DATASTORE_PRUNE;
 
 pub const ROLE_DATASTORE_USER: u64 =
-PRIV_DATASTORE_AUDIT |
-PRIV_DATASTORE_ALLOCATE_SPACE;
+PRIV_DATASTORE_CREATE_BACKUP;
+
+pub const ROLE_DATASTORE_AUDIT: u64 =
+PRIV_DATASTORE_AUDIT;
 
-pub const ROLE_DATASTORE_AUDIT: u64 = PRIV_DATASTORE_AUDIT;
 pub const ROLE_NAME_NO_ACCESS: &str ="NoAccess";
 
 lazy_static! {