From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox] permissions: introduce UserParam permission
Date: Fri, 18 Sep 2020 15:01:07 +0200 [thread overview]
Message-ID: <20200918130107.2744333-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20200918130107.2744333-1-f.gruenbichler@proxmox.com>
to safely differentiate between checking
- the current user matches some static string
- the current user matches the value in some (path) parameter.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
proxmox/src/api/permission.rs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/proxmox/src/api/permission.rs b/proxmox/src/api/permission.rs
index bbaf52f..a35e581 100644
--- a/proxmox/src/api/permission.rs
+++ b/proxmox/src/api/permission.rs
@@ -16,6 +16,8 @@ pub enum Permission {
Anybody,
/// Allow access for the specified user
User(&'static str),
+ /// Allow access if specified param matches logged in user
+ UserParam(&'static str),
/// Allow access for the specified group of users
Group(&'static str),
/// Use a parameter value as userid to run sub-permission tests.
@@ -45,6 +47,9 @@ impl fmt::Debug for Permission {
Permission::User(ref userid) => {
write!(f, "User({})", userid)
}
+ Permission::UserParam(param_name) => {
+ write!(f, "UserParam({})", param_name)
+ }
Permission::Group(ref group) => {
write!(f, "Group({})", group)
}
@@ -123,6 +128,13 @@ fn check_api_permission_tail(
Some(ref userid) => return userid == expected_userid,
}
}
+ Permission::UserParam(param_name) => {
+ match (userid, param.get(¶m_name.to_string())) {
+ (None, _) => return false,
+ (_, None) => return false,
+ (Some(ref userid), Some(ref expected)) => return userid == expected,
+ }
+ }
Permission::Group(expected_group) => {
match userid {
None => return false,
--
2.20.1
next prev parent reply other threads:[~2020-09-18 13:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-18 13:01 [pbs-devel] [PATCH proxmox-backup] fix #3015: allow user self-service Fabian Grünbichler
2020-09-18 13:01 ` Fabian Grünbichler [this message]
2020-09-18 13:51 ` [pbs-devel] [PATCH proxmox] permissions: introduce UserParam permission Dietmar Maurer
2020-09-18 16:20 ` Thomas Lamprecht
2020-09-19 4:38 ` Dietmar Maurer
2020-09-18 16:42 ` [pbs-devel] applied: " Thomas Lamprecht
2020-09-18 13:51 ` [pbs-devel] applied: [PATCH proxmox-backup] fix #3015: allow user self-service Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200918130107.2744333-2-f.gruenbichler@proxmox.com \
--to=f.gruenbichler@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.