Skip to content

Commit 3848d03

Browse files
committed
EH: CS-2031: Implement default-deny evaluation logic
1 parent 353b803 commit 3848d03

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

source/libs/sgeobj/ocs_Role.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,42 @@ ocs::Role::collect_perm_rules(const char *role_name, const lList *role_list, Per
508508
collect_recursive(role_name, role_list, rules, visited);
509509
DRETURN_VOID;
510510
}
511+
512+
bool
513+
ocs::Role::is_authorized(const lList *role_list, const lList *userset_list, const MatchContext &ctx) {
514+
DENTER(TOP_LAYER);
515+
for_each_ep_lv(role_ep, role_list) {
516+
// skip disabled roles
517+
if (!lGetBool(role_ep, RL_enabled)) {
518+
continue;
519+
}
520+
// check whether the requesting user is a member of this role's user_list
521+
bool user_in_role = false;
522+
for_each_ep_lv(acl_ep, lGetList(role_ep, RL_user_list)) {
523+
const char *userset_name = lGetString(acl_ep, US_name);
524+
const lListElem *userset_ep = lGetElemStr(userset_list, US_name, userset_name);
525+
if (userset_ep == nullptr) {
526+
continue;
527+
}
528+
if (sge_contained_in_access_list(ctx.request_user.c_str(),
529+
ctx.request_group.c_str(),
530+
ctx.request_grp_list,
531+
userset_ep) == 1) {
532+
user_in_role = true;
533+
break;
534+
}
535+
}
536+
if (!user_in_role) {
537+
continue;
538+
}
539+
// user is in this role — collect effective rules and evaluate
540+
PermRuleList rules;
541+
collect_perm_rules(lGetString(role_ep, RL_name), role_list, rules);
542+
for (const auto &rule : rules) {
543+
if (match_rule(rule, ctx)) {
544+
DRETURN(true);
545+
}
546+
}
547+
}
548+
DRETURN(false);
549+
}

source/libs/sgeobj/ocs_Role.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ namespace ocs {
4949
std::string object_key; ///< specific object name or ID
5050
std::string object_owner; ///< owner of the target object
5151
std::string request_user; ///< authenticated requesting user
52+
std::string request_group; ///< primary UNIX group of the requesting user
53+
const lList *request_grp_list{nullptr}; ///< supplementary UNIX groups (ST_Type list)
5254
std::vector<std::string> source_hostgroups; ///< @groups the source host belongs to
5355
std::vector<std::string> required_value_constraints; ///< elevated permissions required by the request
5456
};
@@ -130,5 +132,18 @@ namespace ocs {
130132
* @param rules Receives the collected rules (appended, not replaced).
131133
*/
132134
static void collect_perm_rules(const char *role_name, const lList *role_list, PermRuleList &rules);
135+
136+
/**
137+
* Evaluate whether a request is authorized under the current role configuration.
138+
* Iterates all enabled roles; for each role the requesting user belongs to,
139+
* collects the effective rule set (own + inherited) and evaluates each rule.
140+
* Returns true on the first matching rule. Returns false if no rule matches
141+
* across all applicable roles (default-deny).
142+
* @param role_list The master role list.
143+
* @param userset_list The master userset list (for membership checks).
144+
* @param ctx The request context.
145+
* @return True if the request is authorized.
146+
*/
147+
static bool is_authorized(const lList *role_list, const lList *userset_list, const MatchContext &ctx);
133148
};
134149
}

0 commit comments

Comments
 (0)