morningman opened a new pull request, #71116:
URL: https://github.com/apache/doris/pull/71116
### Background
The audit log (`fe.audit.log` and `__internal_schema.audit_log`) records the
text of every statement. A statement whose text can hold credentials is masked
first: each Nereids command says so through
`NeedAuditEncryption.needAuditEncryption()`, and then the statement is parsed
again and the sensitive property values, of a table-valued function such as
`s3()` or of a catalog or table, are written as `*XXX`. INSERT and SELECT ask
for it when their plan reads a table-valued function.
### What problem does this PR solve?
Issue Number: None
Related PR: #47595 (added the per-command check, with the CTAS engine
condition), #60719 (added `INSERT INTO` a table function), #71115 (fixes the
ten supplementary-character cases of `EncryptSQLTest`, muted in CI)
PR Type: Bugfix
Problem Summary:
Many statements that read or write a table function keep its credentials in
the audit log, where anyone who can read the log finds them: a CTAS that runs,
a function in a CTE or a subquery, UPDATE, DELETE and MERGE, `INSERT INTO
s3(...)`, and an EXPLAIN of an INSERT, UPDATE, DELETE or MERGE. A shared check
now finds the function wherever the statement has it, every command that can
carry one uses it, the properties of the function an INSERT writes are masked,
and the text of every EXPLAIN is masked.
```sql
CREATE TABLE ctas_plain AS SELECT * FROM numbers('number' = '3',
's3.secret_key' = 'before-secret-ctas');
```
| | `stmt` in `__internal_schema.audit_log` |
|---|---|
| Before | `CREATE TABLE ctas_plain AS SELECT * FROM numbers('number' = '3',
's3.secret_key' = 'before-secret-ctas')` |
| After | `CREATE TABLE ctas_plain AS SELECT * FROM numbers("number" = "3",
"s3.secret_key" = "*XXX")` |
| A statement with a function holding `s3.secret_key` | Before | After |
|---|---|---|
| `INSERT ... SELECT` or `SELECT` reading it | masked | masked |
| `CREATE TABLE ... AS SELECT` reading it, when it runs | key in clear |
masked |
| the function in a CTE: CTAS, INSERT, a CTE before the INSERT, SELECT | key
in clear | masked |
| the function in a subquery: INSERT, SELECT, `UPDATE ... SET`, `DELETE ...
WHERE` | key in clear | masked |
| `UPDATE ... FROM`, `DELETE ... USING`, `MERGE INTO ... USING` the function
| key in clear | masked |
| `INSERT INTO local(...)` or `s3(...)`: the function it writes | key in
clear | masked |
| `EXPLAIN` of an INSERT, UPDATE, DELETE or MERGE that runs | key in clear |
masked |
### Details
- **Frequency:** Always, for the statements in the second table, whenever
the audit log records them.
- **Root cause:** `CreateTableCommand.needAuditEncryption()` asks only when
the engine is not olap, and analysis sets the engine of a CTAS to olap, so a
CTAS that runs is never masked. INSERT and SELECT search the plan's children
for the function, and neither the queries of a CTE nor the plans of subqueries
are children. UPDATE, DELETE, MERGE and `INSERT INTO` a function never ask, and
the masking parser did not mask the function an INSERT writes. A running
EXPLAIN is audited with the plan it explains.
- **Why existing tests missed it:** `EncryptSQLTest` reads a function only
directly from INSERT and SELECT, and does not execute, so its CTAS would keep
an unset engine and be masked; `testEncryption`, which holds those cases, is
muted in CI (#71115).
`StmtExecutorTest.testParsedCtasLogsMaskedSqlWhenAuditGateSkipsIt` took the
CTAS gap as its premise. No regression suite audits a table function.
- **Fix:** `NeedAuditEncryption.readsTableValuedFunction(plan)` also looks
in the queries of CTEs and the plans of subqueries; each command that can carry
a function asks through it, `INSERT INTO` a function always asks and that
function's properties are masked, and `AuditLogHelper` masks every EXPLAIN.
What masking writes is unchanged, and a statement without a function keeps its
text.
- **Other paths and branches:** `CREATE VIEW` and `CREATE MATERIALIZED VIEW`
keep the properties in their definitions, which `SHOW CREATE` shows, so masking
their audit text alone would not protect them; not changed. branch-4.2 and
branch-4.1 have all of these gaps, branch-4.0 all but `INSERT INTO` a function,
and branch-3.1 the CTAS check; they come from #47595.
### Testing
- `EncryptSQLTest#testTableValuedFunctionPropertiesMasking` (new; a method
of its own since `testEncryption` is muted): sixteen statements go through
`MysqlConnectProcessor` and `AuditLogHelper`, execution stubbed and the CTAS
engine written out. On master all sixteen keep the key; with the fix all are
masked, and a CTAS without a function keeps its text.
- `audit/test_audit_log_tvf_masking` (new, `p0,nonConcurrent`): thirteen
statements that run, the CTAS and the EXPLAINs among them, compared with the
`.out`. It passes with the fix; with master's FE code it fails at its first
row, `CREATE TABLE audit_tvf_ctas PROPERTIES ('replication_num' = '1') AS
SELECT * FROM numbers('number' = '3', 's3.secret_key' =
'tvfmaskingsecretvalue', 'case' = 'audit_tvf_masking_ctas')`. Run locally with
one BE built from master of 2026-11-25 (`be_exec_version` set to 19 for it).
- `StmtExecutorTest`, `StreamingInsertTaskAuditTest`,
`RepositoryAuditEncryptionTest`, `AuditEncryptionSessionVariableTest`,
`InsertIntoTVFCommandTest`, `MergeIntoCommandTest`,
`ExplainRefreshMTMVCommandTest` and `NereidsSqlCacheDataPolicyTest` pass
locally. The ten supplementary-character cases of `EncryptSQLTest` fail as on
master; with #71115 as well, all fourteen pass.
### Notes for Reviewers
- `StmtExecutorTest.testParsedCtasLogsMaskedSqlWhenAuditGateSkipsIt` is
renamed `testParsedSqlLogsMaskedSqlWhenAuditGateSkipsIt` and now uses an olap
`CREATE TABLE` with a sensitive property, which the audit log still leaves to
FE log masking.
- EXPLAIN is handled in `AuditLogHelper`, not by each plan: the plan an
EXPLAIN runs on can be an analyzed insert, a row-level DML plan or a function
sink. An EXPLAIN with nothing to mask keeps its text.
- `readsTableValuedFunction` reads the expressions of every plan node once
per audited statement, the rows of `INSERT ... VALUES` among them.
- The suite reads `numbers()`, which ignores properties it does not know;
`local()` is disabled on master and `s3()` would need storage.
### Release note
The audit log no longer keeps the credentials of a table function such as
`s3()` when a `CREATE TABLE ... AS SELECT`, an UPDATE, DELETE or MERGE, an
`INSERT INTO` a table function, or an EXPLAIN of an INSERT, UPDATE, DELETE or
MERGE uses it, or when a statement reads it in a CTE or a subquery. They are
written as `*XXX`, as INSERT and SELECT already did.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code change, the tests and this description
- Human review: not stated
- Prompts: The author asked to fix directly on master, without a private
report, the CTAS masking gap found while adding Doris query lineage to
OpenMetadata, and to open the PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]