#122663·ClickHouse

Dictionary with a ClickHouse source does not see roles granted to its source user after the dictionary was loaded

Author: MrGolnCreated Sep 28, 2026Updated Sep 29, 2026
Labelscomp-dictionaryexternal

Describe what's wrong

A dictionary with a local CLICKHOUSE source loads as the user from SOURCE(...) (inline USER/PASSWORD or a named collection). Periodic LIFETIME updates keep using the set of roles that user had when the dictionary was loaded. A role granted to the user afterwards is never picked up, so moving a privilege from one role to another (same effective privileges) breaks every later update with ACCESS_DENIED. The dictionary stays LOADED and keeps serving the last snapshot, so the failure is silent. Only SYSTEM RELOAD DICTIONARY fixes it.

At the same time:

  • a new session of the same user sees the new role and reads the source;
  • grant changes inside a role the user already had are picked up by the next update;
  • a privilege granted directly to the user is picked up.

This looks like the dictionary-source flavour of #56646.

Does it reproduce on the most recent release?

Yes: 26.7.5.10 and head 26.10.1.895.

How to reproduce

sql
CREATE DATABASE db;
CREATE TABLE db.src (k UInt64, v String) ENGINE = MergeTree ORDER BY k;
INSERT INTO db.src VALUES (1, 'a');

CREATE USER loader IDENTIFIED BY 'p';
CREATE ROLE r_old; GRANT SELECT ON db.* TO r_old; GRANT r_old TO loader;

CREATE DICTIONARY db.d (k UInt64, v String) PRIMARY KEY k
SOURCE(CLICKHOUSE(USER 'loader' PASSWORD 'p' DB 'db' TABLE 'src'))
LIFETIME(MIN 1 MAX 2) LAYOUT(HASHED());
SELECT dictGet('db.d', 'v', toUInt64(1));          -- 'a'

-- move the privilege to a new role
CREATE ROLE r_new; GRANT SELECT ON db.* TO r_new; GRANT r_new TO loader;
DROP ROLE r_old;

-- a few seconds later
SELECT status, last_successful_update_time, last_exception
FROM system.dictionaries WHERE database = 'db' AND name = 'd';
-- LOADED | <time of the first load> | Code: 497 ... loader: Not enough privileges ... SELECT ON db.src

-- the same user in a new session:
-- clickhouse-client --user loader --password p -q "SELECT currentRoles(), count() FROM db.src"
-- ['r_new']  1

SYSTEM RELOAD DICTIONARY db.d;                      -- fixes it, later periodic updates succeed

Variants checked (same setup, LIFETIME(MIN 1 MAX 2)):

Change after the dictionary was loaded Next periodic update
new role granted, old role dropped ACCESS_DENIED until reload
new role granted, grant revoked from the old role (old role kept) ACCESS_DENIED until reload (watched 80 s, updates retried every ~10 s)
grant revoked from the existing role, then granted back to it recovers on the next update
grant given directly to the user, old role revoked OK
any of the above + SYSTEM RELOAD DICTIONARY OK

Named collection instead of inline credentials behaves the same.

Expected behavior

Dictionary updates use the user's current roles, like a new session does; or, at least, the behaviour is documented together with the need for SYSTEM RELOAD DICTIONARY after role changes.

Additional context

Hit in production when restructuring roles: 20 dictionaries stopped updating right after the old roles were dropped, while status stayed LOADED. SYSTEM RELOAD DICTIONARY ON CLUSTER fixed all of them.