Skip to content

readonly setting in query fails when set to be changeable in readonly on role #530

@dinmukhamedm

Description

@dinmukhamedm

Describe the bug

This is identical to #469 with the 2 differences:

  • I don't create a settings profile, everything is managed on the role level
  • The setting name is different from a bare readonly
    • The role is altered so that the setting is CHANGEABLE_IN_READONLY

Steps to reproduce

  1. Create a dummy dataset
CREATE database test_db;
CREATE TABLE test_db.table (a String) ORDER BY tuple();
INSERT INTO test_db.table (a) VALUES ('test');
  1. Create a role and allow changing a setting in readonly mode
CREATE ROLE IF NOT EXISTS my_readonly_role;
ALTER ROLE my_readonly_role SETTINGS SQL_RO_my_rls_key CHANGEABLE_IN_READONLY;
GRANT SELECT on test_db.table TO my_readonly_role;
CREATE ROW POLICY my_table_readonly_policy ON test_db.table USING a = getSetting('SQL_RO_my_rls_key') TO my_readonly_role;
  1. Create a readonly user defaulted to this role
CREATE user my_readonly_user IDENTIFIED WITH sha256_password by 'Str0ngP@ssw0rd' DEFAULT ROLE my_readonly_role SETTINGS readonly = 1;
  1. Appending the setting directly to a query works
import clickhouse_connect

client = clickhouse_connect.get_client(
    host="localhost",
    port="8123",
    user="my_readonly_user",
    password="Str0ngP@ssw0rd",
)
query= """SELECT * FROM test_db.table WHERE a = 'test' SETTINGS SQL_RO_my_rls_key='test'"""
res = client.query(query)
print(res)
  1. Passing settings to the query breaks
```sql
import clickhouse_connect

client = clickhouse_connect.get_client(
    host="localhost",
    port="8123",
    user="my_readonly_user",
    password="Str0ngP@ssw0rd",
)
query= """SELECT * FROM test_db.table WHERE a = 'test'"""
res = client.query(query, settings={"SQL_RO_my_rls_key": 'test'})
print(res)

This results in

Query execution failed: Setting SQL_RO_my_rls_key is unknown or readonly

Environment

  • clickhouse-connect version: 0.8.18
  • Python version: 3.12
  • Operating system: Debian (modal.com)
  • Clickhouse cloud: version 25.4

Context

I am trying to follow this blog post https://www.highlight.io/blog/row-level-security

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions