Skip to content

Commit 1c2489d

Browse files
committed
fix role mapping
1 parent 4ebb534 commit 1c2489d

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Access/TokenAccessStorage.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ namespace ErrorCodes
2020

2121
TokenAccessStorage::TokenAccessStorage(const String & storage_name_, AccessControl & access_control_, const Poco::Util::AbstractConfiguration & config_, const String & prefix_)
2222
: IAccessStorage(storage_name_), access_control(access_control_), config(config_), prefix(prefix_),
23-
roles_filter(config.getString(prefix.empty() ? "" : prefix + "." + "roles_filter", "")),
2423
memory_storage(storage_name_, access_control.getChangesNotifier(), false)
2524
{
2625
std::lock_guard lock(mutex);
2726

2827
const String prefix_str = (prefix.empty() ? "" : prefix + ".");
2928

29+
if (config.has(prefix_str + "roles_filter"))
30+
roles_filter.emplace(config.getString(prefix_str + "roles_filter"));
31+
3032
provider_name = config.getString(prefix_str + "processor");
3133
if (provider_name.empty())
3234
throw Exception(ErrorCodes::BAD_ARGUMENTS, "'processor' must be specified for Token user directory");
@@ -369,21 +371,22 @@ std::optional<AuthResult> TokenAccessStorage::authenticateImpl(
369371
throwAddressNotAllowed(address);
370372

371373
std::set<String> external_roles;
372-
if (!roles_filter.ok())
373-
{
374-
external_roles = token_credentials.getGroups();
375-
LOG_TRACE(getLogger(), "{}: No external role filtering set, applying all available groups", getStorageName());
376-
}
377-
else
374+
if (roles_filter.has_value() && roles_filter.value().ok())
378375
{
376+
LOG_TRACE(getLogger(), "{}: External role filter found, applying only matching groups", getStorageName());
379377
for (const auto & group: token_credentials.getGroups()) {
380-
if (RE2::FullMatch(group, roles_filter))
378+
if (RE2::FullMatch(group, roles_filter.value()))
381379
{
382380
external_roles.insert(group);
383381
LOG_TRACE(getLogger(), "{}: Granted role (group) {} to user", getStorageName(), user->getName());
384382
}
385383
}
386384
}
385+
else
386+
{
387+
LOG_TRACE(getLogger(), "{}: No external role filtering set, applying all available groups", getStorageName());
388+
external_roles = token_credentials.getGroups();
389+
}
387390

388391
if (new_user)
389392
{

src/Access/TokenAccessStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class TokenAccessStorage : public IAccessStorage
4848
const String & prefix;
4949

5050
String provider_name;
51-
re2::RE2 roles_filter;
51+
std::optional<re2::RE2> roles_filter = std::nullopt;
5252

5353
std::set<String> common_role_names; // role name that should be granted to all users at all times
5454
mutable std::map<String, std::size_t> external_role_hashes;

0 commit comments

Comments
 (0)