Skip to content

Do not run query masking rules over the type of an EPHEMERAL column - #112048

Merged
alexey-milovidov merged 2 commits into
masterfrom
ephemeral-type-not-masked
Jul 28, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
ephemeral-type-not-masked

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

The type of an EPHEMERAL column is kept as a string, as the argument of defaultValueOfTypeName, and the parser produced that string with formatForLogging. That is the wrong call for the job: it hides secrets — which a data type does not have — and it runs the server's query_masking_rules over the result. Those rules exist for what goes into logs and system.query_log, not for a string that has to parse back into the type it came from.

With the masking rules the test suite itself configures (tests/config/config.d/query_masking_rules.xml replaces TOPSECRET.TOPSECRET with [hidden]):

CREATE TABLE t
(
    id UInt8,
    e Enum8('TOPSECRET.TOPSECRET' = 1, '[hidden]' = 2) EPHEMERAL,
    x String DEFAULT toString(e)
)
ENGINE = Memory;

Code: 62. DB::Exception: Duplicate names in enum: '[hidden]' = 1 and 2

Both element names were rewritten to the same thing. Any masking rule that matches inside a type has the same effect: at best the stored type is not the one the user wrote, at worst it no longer parses.

The comment on the old call already noted that an ephemeral column has no secrets and called it "the strange call". It now uses formatWithSecretsOneLine, the same call the other places that keep a type as a string already use.

Found while working on #111994, which needs the parser not to reach for formatForLogging here; it is an independent bug, so it goes on its own.

Test 04628_ephemeral_column_type_is_not_masked fails on master with the error above and passes with this change.

Related: #111994

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed the type of an EPHEMERAL column being rewritten by the server's query_masking_rules. A rule matching inside the type made CREATE TABLE store the wrong type, or fail.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.295 (included in 26.8 and later)

The type of an `EPHEMERAL` column is kept as a string, as the argument of
`defaultValueOfTypeName`, and the parser produced that string with
`formatForLogging`. That is the wrong call for the job. It hides secrets - which
a data type does not have - and, more to the point, it runs the server's
`query_masking_rules` over the result, which are meant for what goes into logs
and `system.query_log`, not for a string that has to parse back into the type it
came from.

With the rules the test suite itself configures, which replace
`TOPSECRET.TOPSECRET` with `[hidden]`:

    CREATE TABLE t
    (
        id UInt8,
        e Enum8('TOPSECRET.TOPSECRET' = 1, '[hidden]' = 2) EPHEMERAL,
        x String DEFAULT toString(e)
    )
    ENGINE = Memory;

    Code: 62. DB::Exception: Duplicate names in enum: '[hidden]' = 1 and 2

Both element names were rewritten to the same thing. Any masking rule that
matches inside a type has the same effect: at best the stored type is not the
one the user wrote, at worst it no longer parses.

The comment on the old call already said the ephemeral column has no secrets and
that this was "the strange call". It now uses `formatWithSecretsOneLine`, the
same one the other places that keep a type as a string use.
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3a5fbbd]

Summary: ✅


AI Review

Summary

This PR fixes EPHEMERAL columns whose implicit defaultValueOfTypeName argument was previously serialized with formatForLogging, so query_masking_rules could rewrite the stored type string and either corrupt the type or make CREATE TABLE fail. The change switches that persisted type-string path to formatWithSecretsOneLine, which matches the other AST/type serialization sites that need round-trippable output, and the added stateless test covers the reported failure mode. I did not find a remaining correctness, compatibility, or test-gap issue in the current code.

Final Verdict
  • Status: ✅ Approve

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master. Both CI failures on the previous head are unrelated to this change, and both already have a fix in flight:

This PR touches only ParserCreateQuery.h and adds one stateless test, so neither can be caused by it.

@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.20% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.40% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Jul 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 28, 2026
Merged via the queue into master with commit edf159f Jul 28, 2026
179 checks passed
@alexey-milovidov
alexey-milovidov deleted the ephemeral-type-not-masked branch July 28, 2026 18:23
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants