Check whether or not the client is permitted specified access to a path.
495 std::vector<std::string_view> authz_list;
496 authz_list.reserve(1);
502 ParseTokenString(
"authz", env, authz_list);
503 ParseTokenString(
"access_token", env, authz_list);
505 if (Entity && !strcmp(
"ztn", Entity->
prot) && Entity->
creds &&
508 authz_list.push_back(Entity->
creds);
511 if (authz_list.empty()) {
512 return OnMissing(Entity, path, oper, env);
517 if (authz_list.size() > 10) {
518 m_log.
Log(
LogMask::Warning,
"Access",
"Request had more than 10 tokens attached; ignoring");
519 return OnMissing(Entity, path, oper, env);
523 std::vector<std::shared_ptr<XrdAccRules>> access_rules_list;
524 uint64_t now = monotonic_time();
526 for (
const auto &authz : authz_list) {
527 std::shared_ptr<XrdAccRules> access_rules;
529 std::lock_guard<std::mutex> guard(m_map_mutex);
530 const auto iter = m_map.find(authz);
531 if (iter != m_map.end() && !iter->second->expired()) {
532 access_rules = iter->second;
536 m_log.
Log(
LogMask::Debug,
"Access",
"Token not found in recent cache; parsing.");
538 uint64_t cache_expiry;
540 std::string username;
541 std::string token_subject;
543 std::vector<MapRule> map_rules;
544 std::vector<std::string> groups;
545 uint32_t authz_strategy;
547 if (GenerateAcls(authz, cache_expiry, rules, username, token_subject, issuer, map_rules, groups, authz_strategy, acceptable_authz)) {
548 access_rules.reset(
new XrdAccRules(now + cache_expiry, username, token_subject, issuer, map_rules, groups, authz_strategy, acceptable_authz));
549 access_rules->parse(rules);
555 m_log.
Log(
LogMask::Debug,
"Access",
"New valid token", access_rules->str().c_str());
557 }
catch (std::exception &exc) {
558 m_log.
Log(
LogMask::Warning,
"Access",
"Error generating ACLs for authorization", exc.what());
561 std::lock_guard<std::mutex> guard(m_map_mutex);
562 m_map[std::string(authz)] = access_rules;
564 m_log.
Log(
LogMask::Debug,
"Access",
"Cached token", access_rules->str().c_str());
566 access_rules_list.push_back(access_rules);
568 if (access_rules_list.empty()) {
569 return OnMissing(Entity, path, oper, env);
571 std::string_view path_view(path, strlen(path));
575 return OnMissing(Entity, path, oper, env);
589 for (
const auto &access_rules : access_rules_list) {
591 if (!access_rules->acceptable_authz(oper)) {
592 m_log.
Log(
LogMask::Debug,
"Access",
"Issuer is not acceptable for given operation:", access_rules->get_issuer().c_str());
597 new_secentity.
vorg =
nullptr;
598 new_secentity.
grps =
nullptr;
599 new_secentity.
role =
nullptr;
602 const auto &issuer = access_rules->get_issuer();
603 if (!issuer.empty()) {
604 new_secentity.
vorg = strdup(issuer.c_str());
606 bool group_success =
false;
607 if ((access_rules->get_authz_strategy() &
IssuerAuthz::Group) && access_rules->groups().size()) {
608 std::stringstream ss;
609 for (
const auto &grp : access_rules->groups()) {
612 const auto &groups_str = ss.str();
613 new_secentity.
grps =
static_cast<char*
>(malloc(groups_str.size() + 1));
614 if (new_secentity.
grps) {
615 memcpy(new_secentity.
grps, groups_str.c_str(), groups_str.size());
616 new_secentity.
grps[groups_str.size()] =
'\0';
618 group_success =
true;
621 std::string username;
622 bool mapping_success =
false;
623 bool scope_success =
false;
624 username = access_rules->get_username(path_view);
626 mapping_success = (access_rules->get_authz_strategy() &
IssuerAuthz::Mapping) && !username.empty();
627 scope_success = (access_rules->get_authz_strategy() &
IssuerAuthz::Capability) && access_rules->apply(oper, path_view);
629 std::stringstream ss;
630 ss <<
"Grant authorization based on scopes for operation=" << OpToName(oper) <<
", path=" << path;
634 if (!scope_success && !mapping_success && !group_success) {
635 auto returned_accs = OnMissing(&new_secentity, path, oper, env);
637 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
638 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
639 if (new_secentity.
role !=
nullptr) free(new_secentity.
role);
641 return returned_accs;
645 if (scope_success && username.empty()) {
646 username = access_rules->get_default_username();
651 if (scope_success || mapping_success) {
653 Entity->
eaAPI->
Add(
"request.name", username,
true);
654 new_secentity.
eaAPI->
Add(
"request.name", username,
true);
663 const auto &token_subject = access_rules->get_token_subject();
664 if (!token_subject.empty()) {
665 Entity->
eaAPI->
Add(
"token.subject", token_subject,
true);
674 if (Entity->
secMon && scope_success && returned_op &&
Mon_isIO(oper))
675 Mon_Report(new_secentity, token_subject, username);
678 if (new_secentity.
vorg !=
nullptr) free(new_secentity.
vorg);
679 if (new_secentity.
grps !=
nullptr) free(new_secentity.
grps);
680 if (new_secentity.
role !=
nullptr) free(new_secentity.
role);
685 return OnMissing(Entity, path, oper, env);
bool AuthorizesRequiredIssuers(Access_Operation client_oper, const std::string_view &path, const std::vector< std::pair< std::unique_ptr< SubpathMatch >, std::string >> &required_issuers, const std::vector< std::shared_ptr< XrdAccRules >> &access_rules_list)
std::vector< std::pair< Access_Operation, std::string > > AccessRulesRaw
bool Mon_isIO(const Access_Operation oper)
void Mon_Report(const XrdSecEntity &Entity, const std::string &subject, const std::string &username)
bool Add(XrdSecAttr &attr)
char * vorg
Entity's virtual organization(s)
int credslen
Length of the 'creds' data.
XrdNetAddrInfo * addrInfo
Entity's connection details.
XrdSecEntityAttr * eaAPI
non-const API to attributes
char prot[XrdSecPROTOIDSIZE]
Auth protocol used (e.g. krb5)
char * creds
Raw entity credentials or cert.
XrdSecMonitor * secMon
If !0 security monitoring enabled.
char * grps
Entity's group name(s)
char * role
Entity's role(s)
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)