Skip to content

[feature](audit) Add query_audit_always_on to keep query audit from being disabled - #70123

Open
morningman wants to merge 15 commits into
apache:masterfrom
morningman:query-audit-always-on
Open

morningman wants to merge 15 commits into
apache:masterfrom
morningman:query-audit-always-on

Conversation

@morningman

@morningman morningman commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Background

Query audit records every statement an FE executes: the built-in audit log builder writes it to fe.audit.log (the query module of audit_log_modules), and the built-in audit loader stream-loads the same events into __internal_schema.audit_log (audit plugin docs). Global variables (enable_audit_plugin, audit_plugin_*), the session variable enable_prepared_stmt_audit_log and several FE configs control what is recorded and how events are queued, batched and truncated. ADMIN can change most of them at runtime, and any user can change the session variable.

What problem does this PR solve?

Issue Number: close #70122
Related PR: #37894 (introduced the byte truncation whose negative-limit failure is fixed here), #38419 (added enable_prepared_stmt_audit_log), #38310 (added skip_audit_user_list)
PR Type: Feature

Problem Summary:

Deployments that must audit every query cannot rely on query audit today: ADMIN can switch it off at runtime, for example with SET GLOBAL enable_audit_plugin = false for the audit table, and any user can leave their prepared statements out. This PR adds query_audit_always_on, an FE config that can only be changed in fe.conf with a restart, so ADMIN cannot turn it off at runtime. Locking enable_audit_plugin alone is not enough: twelve other parameters can also skip statements, lose events, or cut the recorded text, so while the switch is on none of them can be set weaker than its default, and enforcing that is most of the code. The switch is off by default, and with it off nothing changes after an upgrade except a bundled fix: a negative audit_plugin_max_sql_length, which silently dropped audit records, is now rejected.

Details

  • Change map: +1,649 −51 in 20 files. Tests are 1,019 of the added lines (62%): FE unit tests +824 and a docker suite +195, 37 of them a generated .out. threat-model.md is +35 −1. The production code, +595 −50, has five parts:

    1. The switch and the policy (QueryAuditPolicy, new, +441, a third of it comments and blank lines; Config +24 −10; GlobalVariable +7 −5): the protected parameters and their safe values, the checks, and the startup corrections. Read it first.
    2. Rejecting weaker values where users set them (VariableMgr, about +40 −11): SET, SET_VAR, UNSET, and a follower's copy of a forwarded SET GLOBAL; ADMIN SET FRONTEND CONFIG goes through a callback from part 1.
    3. Reading the effective values where audit uses them (+21 −21, mainly AuditLogHelper and AuditLoader), since old values still come from the image, the edit log, forwarded sessions and existing sessions.
    4. Startup and master takeover (DorisFE +6, Env +2, VariableMgr +28): apply the startup corrections; rewrite persisted globals.
    5. Prepared executions (MysqlConnectProcessor +25 −3): audit each one, also when it fails early.

    Commits: first the negative-length fix (+53 −24, tests +73), which can be picked alone, then the policy, its enforcement, the master's rewrite, the docker suite, and the threat model.

  • Scope: With the switch on, the FE that receives a statement always produces its audit event, failed statements and every COM_STMT_EXECUTE included, and hands it to both fe.audit.log and the audit table. The protected parameters:

    Parameter Kind With the switch on
    enable_audit_plugin global variable stays true
    enable_prepared_stmt_audit_log session variable stays true
    audit_plugin_max_sql_length global variable at least 2097152
    audit_plugin_max_insert_stmt_length global variable unlimited, its default
    audit_plugin_load_timeout global variable at least 600
    audit_plugin_max_batch_bytes, audit_plugin_max_batch_interval_sec global variables fixed at 52428800 and 60
    audit_event_log_queue_size mutable FE config at least 250000
    query_audit_log_timeout_ms, be_report_query_statistics_timeout_ms, workload_runtime_status_thread_interval_ms mutable FE configs at most 5000, 60000 and 2000
    skip_audit_user_list, audit_log_modules FE configs read at startup ignored; always includes query

    Not covered: code execution inside the FE (INSTALL PLUGIN, a JDBC driver_url), tampering with written records (TRUNCATE on the audit table), reliable delivery (a full queue, a failed load or an FE crash still loses events), enable_bdbje_debug_mode, load and slow-query audit, and external audit plugins.

  • Design: One rule: no protected parameter may be weaker than its factory default, enforced wherever a value can come from (parts 2 to 4 of the Change map). A weaker SET fails, so the attempt is visible and audited itself; a conflicting value in fe.conf or fe_custom.conf is replaced with a WARN instead of failing the start; and the master's rewrite makes SHOW VARIABLES agree with what is enforced. The checks sit on the entries users go through, not in VariableMgr.setValue, which replay and image loading also call and whose exceptions they swallow. A prepared execution forwarded to the master is audited only by the FE that received it, as COM_QUERY is. Rejected: making only enable_audit_plugin read-only, enforcing on read only (the change would appear to succeed), and smaller floors such as 4096 bytes for the SQL length. Proposed in [Feature][Audit] Add query_audit_always_on to keep query audit from being disabled at runtime #70122, opened with this PR; not discussed in the community yet.

  • Usage:

    # fe.conf of every FE, then restart the FE
    query_audit_always_on = true
    
    SET GLOBAL enable_audit_plugin = false;
    -- ERROR: Variable 'enable_audit_plugin' can't be set to 'false' because query_audit_always_on is enabled
    ADMIN SET FRONTEND CONFIG ("audit_event_log_queue_size" = "0");
    -- ERROR: Failed to set config 'audit_event_log_queue_size'. err: Config 'audit_event_log_queue_size' can't be
    --        set to '0' because query_audit_always_on is enabled, the value must be at least 250000
    ADMIN SHOW FRONTEND CONFIG LIKE 'query_audit_always_on';
  • Default behavior: Off. With it off, everything behaves as before except the negative-length fix below.

  • Compatibility: No metadata, image, edit log type, Thrift or Protobuf change; the master's rewrite uses the existing global variable edit log, which older FEs replay, and an older FE ignores the key in fe.conf. Each FE enforces its own setting, so every FE must be configured. With the switch on, a client that sets enable_prepared_stmt_audit_log = false, for example in JDBC sessionVariables, gets an error; every prepared execution is audited, which raises audit volume for high-QPS point queries; and a cluster that had shortened the recorded statements records up to 2 MB per statement. After the switch is turned off again, the rewritten globals keep their safe values.

  • Security and privileges: Turning query audit off now needs write access to the FE's config files and a restart instead of ADMIN. threat-model.md records the switch and adds §4.8 property 13 with what it does not cover (M20, which needs maintainer agreement). No privilege is added.

  • Behavior change: With the switch off too, a negative audit_plugin_max_sql_length is rejected by SET and counts as 0 if already set. Before, it was accepted and dropped the audit record of every statement except INSERT ... VALUES: truncateByBytes threw and logAuditLog swallowed the exception with the event. The same code is on branch-3.1, 4.0, 4.1 and 4.2; the fix is the first commit and can be picked alone.

Testing

  • FE unit tests, run locally with run-fe-ut.sh, and again after the rebase onto the latest master, which changed MysqlConnectProcessor in [fix](fe) Preserve non-UTF-8 prepared statement parameters #69805: QueryAuditPolicyTest (new) for the effective values, the checks and the startup corrections; ConfigTest for runtime config changes and the immutable switch; VariableMgrTest for SET [GLOBAL], = DEFAULT, UNSET, the SET_VAR hint and UNSET ALL with the switch on and off, and for the master's rewrite, whose four edit log entries replay with the new values; MysqlConnectProcessorLongDataTest for prepared executions, forwarded and failing ones included; AuditLoaderTest and AuditLogHelperTest for the loader and the truncation. The related audit and prepared-statement test classes pass as well.
  • The negative-length fix: AuditLogHelperTest#testNegativeMaxSqlLengthStillAudits and VariableMgrTest#testNegativeAuditMaxSqlLengthIsRejected fail with the fix reverted (no event is submitted, and the run logs the swallowed IndexOutOfBoundsException) and pass with it.
  • Docker suite audit/test_query_audit_always_on (new): two FEs of this branch with the switch on and conflicting values in fe.conf, connected to the follower. It checks the startup corrections, twelve rejected statements and a rejected SET_VAR hint, the immutable switch, unchanged globals on the follower, one ERR audit record per rejected statement, one record per prepared execution whether or not it is forwarded, and the audit of a user in skip_audit_user_list. Run locally against a 4.1.3 BE, for which the local FE build pinned be_exec_version = 10 and turned off enable_local_shuffle_planner and enable_bucketed_hash_agg; it passes, and passes again against the .out it generated, which was checked line by line. No PR pipeline runs docker suites.

Notes for Reviewers

  • Non-obvious edits: VariableMgr.getValueToSet is split out of setVarInternal so the check sees the value = DEFAULT resolves to. AuditLogHelper.truncateStmt replaces three copies of the truncation, one of them in TableQueryPlanAction. In MysqlConnectProcessor.handleExecute, the audited text starts as the prepared SQL while the switch is on, so an execution that throws is not recorded with an empty statement, and an execution that fails before its executor exists resets the query id, which still belonged to the connection's previous statement. QueryAuditPolicy names enable_prepared_stmt_audit_log as a string because SessionVariable is in fe-core, and VariableMgrTest checks that every name resolves.
  • Not in the design, found by the docker suite: a follower copies a forwarded SET GLOBAL into its own memory through setVarForNonMasterFE even when the master rejected the statement, because StmtExecutor.forwardToMaster runs afterForwardToMaster unconditionally. Before the fix, SET GLOBAL enable_audit_plugin = false through a follower failed for the client but left the follower's global at false. setVarForNonMasterFE now applies the same check, which also completes the negative-length fix; forwardToMaster itself is unchanged.
  • Open points: the severity tier of property 13 and M20 itself need maintainer agreement. A rejected SET_VAR hint fails with Can not set session variable ..., which does not show the reason; that message is unchanged.

Release note

Add the FE config query_audit_always_on (default false; set it in fe.conf and restart the FE). When it is true, query audit cannot be disabled or weakened at runtime: enable_audit_plugin and enable_prepared_stmt_audit_log stay on, the other audit variables and the audit queue and timeout configs cannot be set weaker than their defaults, skip_audit_user_list is ignored, and every server-side prepared execution is audited. Also fix query audit records being dropped for every statement except INSERT ... VALUES while audit_plugin_max_sql_length is negative; setting it to a negative value is now rejected.

Check List (For Author)

  • Behavior changed: Yes (see Details)
  • Does this need documentation: Yes (a doris-website page on query_audit_always_on and a note in docs/admin-manual/audit-plugin.md; to be written)
  • Pre-submission status: Partially verified: the docker suite ran against a 4.1.3 BE, not a BE of this branch, and no PR pipeline runs it

AI Disclosure

  • Tool: Claude Code (Claude Opus 5.5)
  • Generated: the code, the tests, the threat-model text, the commit messages and this description
  • Human review: The author wrote the design and reviewed the key code paths.
  • Prompts: The author wrote the design and asked to implement it with the develop-with-evidence and doris-pr-description skills, developing directly on the current branch without a new branch or worktree, and to open the PR.

morningman and others added 6 commits November 3, 2026 20:50
…h is negative

### Background

Every statement an FE executes produces a query audit event, which goes to `fe.audit.log` and, through the built-in audit loader, to `__internal_schema.audit_log`. Before building the event, `AuditLogHelper` truncates the statement text to the global variable `audit_plugin_max_sql_length` bytes (default 2097152); `INSERT ... VALUES` uses the smaller of it and `audit_plugin_max_insert_stmt_length`. The HTTP query-plan endpoint (`TableQueryPlanAction`) truncates its audited statement the same way.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#37894 (introduced the byte truncation), apache#51314 (added the clamp on the INSERT path)
PR Type: Bugfix

Problem Summary:

After `SET GLOBAL audit_plugin_max_sql_length = -1`, no statement other than `INSERT ... VALUES` is audited: neither `fe.audit.log` nor the audit table gets a record. The negative limit reaches `truncateByBytes`, `ByteBuffer.wrap(bytes, 0, -1)` throws `IndexOutOfBoundsException`, and `logAuditLog` swallows it together with the event. A negative limit now counts as 0, as it already does on the INSERT path, and `SET` rejects negative values.

### Details

- **Frequency:** Every audited statement except `INSERT ... VALUES`, for as long as the variable is negative. Only ADMIN can set it.
- **Root cause:** `handleStmt`, `handleCommand` and `TableQueryPlanAction` pass the variable to `truncateByBytes` unchecked. The `INSERT ... VALUES` path wraps it in `Math.max(0, ...)` since apache#51314; the other three never did.
- **Why existing tests missed it:** `AuditLogBuilderTest` tries negative limits only on `INSERT ... VALUES` and on an empty statement, neither of which reaches `ByteBuffer.wrap`. No test drove `logAuditLog` with a negative limit and checked that an event was submitted.
- **Fix:** The three non-INSERT paths share a new `AuditLogHelper.truncateStmt`, which clamps the limit at 0, so the record keeps the statement's truncation marker. `VariableMgr.setVar`, which `SET`, `SET_VAR` and `UNSET` go through, rejects a negative value, and so does `setVarForNonMasterFE`, through which a follower copies a forwarded `SET GLOBAL` into its own memory: `StmtExecutor.forwardToMaster` runs that copy even after the master rejected the statement. The check is not in `VariableMgr.setValue`, which edit log replay and image loading also call: a rejection there would be swallowed and skip the value on that FE only. A negative value already in the image counts as 0 when read.
- **Behavior change:** `SET GLOBAL audit_plugin_max_sql_length` with a negative value now fails with `Variable 'audit_plugin_max_sql_length' can't be set to '-1', the value must not be negative`; it used to be accepted.
- **Other paths and branches:** The same code is on branch-3.1, branch-4.0, branch-4.1 and branch-4.2.

### Testing

- `AuditLogHelperTest#testNegativeMaxSqlLengthStillAudits` (new): with the limit at -1, `logAuditLog` submits an event whose statement is the truncation marker. With the fix reverted it fails (`Wanted but not invoked`, and the run logs the swallowed `IndexOutOfBoundsException`); with it, it passes.
- `VariableMgrTest#testNegativeAuditMaxSqlLengthIsRejected` (new): `SET GLOBAL audit_plugin_max_sql_length = -1` fails and leaves the value unchanged, also on the follower's copy path, while 0 is accepted. It fails with the fix reverted.
- Both classes pass in full locally with `run-fe-ut.sh` (AuditLogHelperTest 6, VariableMgrTest 17).

### Release note

Fix query audit records being dropped for every statement except `INSERT ... VALUES` while `audit_plugin_max_sql_length` is negative. Setting it to a negative value is now rejected, and a negative value already set counts as 0.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
### Background

Query audit records each statement an FE executes in `fe.audit.log` (its `query` module) and, through the built-in audit loader, in `__internal_schema.audit_log`. Global variables (`enable_audit_plugin`, `audit_plugin_*`), a session variable (`enable_prepared_stmt_audit_log`) and FE configs (`audit_event_log_queue_size`, three audit timeouts, `skip_audit_user_list`, `audit_log_modules`) control it, and ADMIN can change most of them at runtime.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: None
PR Type: Feature

Problem Summary:

A deployment that must audit every query cannot rely on query audit today: ADMIN can turn it off or hollow it out at runtime, for example with `SET GLOBAL enable_audit_plugin = false` or `audit_event_log_queue_size = 0`. This commit adds the FE config `query_audit_always_on` and `QueryAuditPolicy`, the one place that defines what the switch allows, and applies it to the config files at startup. The following commits apply it to variables and to the audit paths.

### Details

- **Scope:** fe-common: the config; `QueryAuditPolicy` with the effective value of each protected variable, checks for variable and config changes, and startup corrections; the factory defaults as named constants, which `GlobalVariable` and `Config` now use; and a ConfHandler on the four mutable audit configs. fe-core: `DorisFE` applies the startup corrections and logs them once logging is up.
- **Design:** With the switch on, no protected parameter may be weaker than its factory default: switches stay on, a limit whose smaller values drop events has its default as the minimum, a wait whose larger values hold events back has it as the maximum, and the audit loader's batching knobs are fixed. Separate, smaller floors were rejected, since nothing says how short a statement may be cut before it is erased. Conflicting values in fe.conf or fe_custom.conf, which loading never checks, are replaced in memory with a WARN instead of failing the start.
- **Usage:** Set `query_audit_always_on = true` in fe.conf and restart the FE. `ADMIN SET FRONTEND CONFIG ("audit_event_log_queue_size" = "0")` then fails with `Config 'audit_event_log_queue_size' can't be set to '0' because query_audit_always_on is enabled, the value must be at least 250000`.
- **Default behavior:** Off; nothing changes while it is off.
- **Compatibility:** A new config read at startup only. No metadata, image, edit log, Thrift or Protobuf change, and an older FE ignores the unknown key in fe.conf.

### Testing

- `QueryAuditPolicyTest` (new, fe-common): the effective values with the switch off and on, the variable and config checks, the startup corrections and the list they return, and that the registry names exactly the mutable configs that carry its handler.
- `ConfigTest#testQueryAuditAlwaysOnRejectsWeakerAuditConfigs` (new): `setMutableConfig`, which `ADMIN SET FRONTEND CONFIG` and `/api/_set_config` both use, rejects a weaker value and leaves the config unchanged, and `query_audit_always_on` itself is not mutable.
- Both pass locally with `run-fe-ut.sh`.

### Release note

None

### Check List (For Author)

- Behavior changed: No
- Does this need documentation: Yes (a doris-website page on query_audit_always_on, written with the PR)
- Pre-submission status: Ready

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… prepared statements

### Background

`SET`, the `SET_VAR` hint and `UNSET` change variables through `VariableMgr.setVar`, and `UNSET VARIABLE ALL` through `VariableMgr.setAllVarsToDefaultValue`. The audit loader reads `enable_audit_plugin` and its batching and timeout variables on every event or batch, `AuditLogHelper` truncates statements by the `audit_plugin_max_*` lengths, and a server-side `COM_STMT_EXECUTE` is audited only when the session's `enable_prepared_stmt_audit_log` is on.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: None
PR Type: Feature

Problem Summary:

With `query_audit_always_on` on, the audit variables must not be able to switch query audit off or weaken it, whether through a statement or through values already persisted, forwarded or held by older sessions, and every `COM_STMT_EXECUTE` must be audited once. This commit applies `QueryAuditPolicy` where the variables are set and where they are read, and to the prepared execution path.

### Details

- **Scope:** `VariableMgr.setVar` rejects a value the policy does not allow, which covers `SET [GLOBAL]`, `= DEFAULT`, the `SET_VAR` hint and `UNSET`, and so does a follower's copy of a forwarded `SET GLOBAL` (`setVarForNonMasterFE`, which runs even when the master rejected the statement); `UNSET VARIABLE ALL` leaves such a variable as it is instead of failing. The audit loader, the audit stream load and the statement truncation read the effective values. A `COM_STMT_EXECUTE` is audited by the FE that received it whatever its session says; the master does not audit one forwarded to it. An execution that fails before its executor exists (uploaded long data, parameter binding) is audited with the statement it was prepared from, as a failed statement.
- **Design:** The write check is on the entries users set variables through, not in `VariableMgr.setValue` or a VarAttr checker: replaying the edit log and loading the image also call `setValue`, which swallows the exception and would skip the value on one FE only, and checkers cannot cover `GlobalVariable` fields. The read side is what guarantees the rules, since old values also arrive from the image, the edit log and forwarded sessions. Only the receiving FE audits a forwarded execution, as for `COM_QUERY`; auditing on both would record a forwarded prepared `INSERT` twice with the same query id. A failed execution no longer carries the query id of the connection's previous statement.
- **Usage:** With the switch on, `SET enable_prepared_stmt_audit_log = false` fails with `Variable 'enable_prepared_stmt_audit_log' can't be set to 'false' because query_audit_always_on is enabled`, and every prepared execution is audited.
- **Default behavior:** With the switch off, the code paths behave as before.
- **Compatibility:** No metadata, image, edit log, Thrift or Protobuf change. Followers apply `SET GLOBAL` from the master without checking it again, so the FE that runs the statement decides.

### Testing

- `VariableMgrTest`: with the switch on, `SET [GLOBAL]`, `= DEFAULT`, `UNSET`, the `SET_VAR` hint and the follower's copy path fail for each weaker value and leave the variables unchanged; stronger values are accepted; `UNSET ALL` keeps `enable_prepared_stmt_audit_log` and resets the rest; with it off, all of these succeed; every protected name resolves to a variable.
- `MysqlConnectProcessorLongDataTest`: with the switch on, an execution is audited although the session switch is off, the master skips a forwarded one, and executions failing on uploaded data or on binding are audited with the prepared statement and without the previous query id; with it off, the old behavior holds.
- `AuditLoaderTest`, `AuditLogHelperTest`: the loader keeps events with `enable_audit_plugin = false`, and statements, `INSERT ... VALUES` included, are cut at the default length at the earliest.
- These and the related `AuditLogBuilderTest`, `AuditLogHelperBackendSelectionTest`, `AuditLogWorkloadGroupTest`, `MysqlConnectProcessorCursorFetchTest`, `MysqlConnectProcessorExecuteCleanupTest`, `ConnectProcessorForwardProtocolTest`, `WorkloadRuntimeStatusMgrTest` and `StreamingInsertTaskAuditTest` pass locally with `run-fe-ut.sh`.

### Release note

None

### Check List (For Author)

- Behavior changed: No
- Does this need documentation: Yes (a doris-website page on query_audit_always_on, written with the PR)
- Pre-submission status: Ready

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ster takes over

### Background

Global variables are persisted in the image and the edit log. When a master takes over, `Env.transferToMaster` already rewrites some persisted values, for example the defaults that changed in an upgrade (`VariableMgr.forceUpdateVariables`), and writes each rewrite to the edit log for the followers.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: None
PR Type: Feature

Problem Summary:

A cluster that turns `query_audit_always_on` on may have persisted `enable_audit_plugin=false` or a short `audit_plugin_max_sql_length` earlier. The read side already ignores such values, but `SHOW VARIABLES` would keep showing them. The master now rewrites them to their effective values when it takes over.

### Details

- **Scope:** `VariableMgr.applyQueryAuditPolicyToGlobalValues`, called once from `Env.transferToMaster` after the upgrade rewrites. Session values of connections that are already open are not rewritten; the read side covers them.
- **Design:** The same lock and the same global variable edit log as `SET GLOBAL` and `refreshDefaultSessionVariables`, so that the followers replay the rewrites and every FE shows the same values; each rewrite is logged at INFO. Only the master writes the edit log, so a follower does not rewrite anything itself.
- **Usage:** After turning the switch on and restarting, `SELECT @@global.enable_audit_plugin` returns 1 even if it was set to 0 before.
- **Default behavior:** Nothing happens with the switch off.
- **Compatibility:** Uses the existing global variable edit log, which older FEs replay. Side effects: after the switch is turned off again, the variables stay at the rewritten values, and the global default of `enable_prepared_stmt_audit_log` becomes true.

### Testing

- `VariableMgrTest#testAlwaysOnRewritesPersistedGlobalValues` (new): four non-compliant globals are rewritten, an allowed value stays, exactly four global variable edit logs are written, and what they replay carries the new values; with the switch off nothing changes. Passes locally with `run-fe-ut.sh`.

### Release note

None

### Check List (For Author)

- Behavior changed: No
- Does this need documentation: Yes (a doris-website page on query_audit_always_on, written with the PR)
- Pre-submission status: Ready

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the code, the tests and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
### Background

`query_audit_always_on` is read from fe.conf at startup and cannot be changed at runtime, so a regression suite needs a cluster of its own, which docker suites (`docker(options)`) start with the FE configs they declare. With two FEs, a suite connected to the follower also exercises the paths that forward to the master: `SET GLOBAL` and a prepared `EXECUTE` under `force_forward_all_queries`.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: None
PR Type: Test

Problem Summary:

The unit tests of the previous commits mock the MySQL execution path and the audit pipeline. This suite checks the switch end to end: the FE startup corrections, every supported attempt to weaken query audit through a follower, and what reaches `__internal_schema.audit_log`.

### Details

- **Scenarios:** fe.conf sets `query_audit_always_on=true` with conflicting `skip_audit_user_list`, `audit_log_modules` and `audit_event_log_queue_size`, which show up corrected. Twelve weakening statements (`SET [GLOBAL]`, `= DEFAULT`, `UNSET`, `ADMIN SET [ALL] FRONTEND(S) CONFIG`) and a `SET_VAR` hint fail, the switch itself is not mutable, and the globals keep their values on the follower. Each rejected statement is audited once as `ERR`; a prepared execution is audited once whether or not it is forwarded to the master; the user in `skip_audit_user_list` is audited.
- **What existing tests miss:** The suites under `regression-test/suites/audit/` run with the switch off. No test covers a follower forwarding these statements, and the unit tests never start an FE from fe.conf.
- **Fails when broken:** An earlier run, before the follower's copy of a forwarded `SET GLOBAL` was checked, failed here: the follower reported `enable_audit_plugin` as false and `audit_plugin_max_sql_length` as 100 after the master had rejected both. A duplicate audit record from the master, a missing record, or a lost startup correction changes the `.out` too.

### Testing

- Ran locally against two FEs of this branch and a 4.1.3 BE, from a runner container on the Docker VM's host network: passes, and the `.out` was generated by it and checked line by line. For the 4.1.3 BE only, the local FE build pinned `be_exec_version = 10` and turned off `enable_local_shuffle_planner` and `enable_bucketed_hash_agg`, whose plan nodes that BE does not know. No PR pipeline runs docker suites.

### Release note

None

### Check List (For Author)

- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: run against a 4.1.3 BE, not a BE of this branch; docker suites do not run in CI

### AI Disclosure

- Tool: Claude Code (Claude Opus 5.5)
- Generated: the suite, its `.out` (generated by the run) and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
### Background

`threat-model.md` is the security contract of the repository: what Doris guarantees, what it leaves to operators, and how reports are triaged. It treats a malicious `SUPER` or ADMIN user as out of model (M3) and lists the configuration knobs that move the model (§4.5a), such as `enable_all_http_auth` (M19).

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: None
PR Type: Build/CI/Chore

Problem Summary:

`query_audit_always_on` makes "no database account can turn query audit off" a property, which M3 alone would classify as out of model. This commit records the switch as a §4.5a knob, adds it as §4.8 property 13 with what it does not cover, notes the exception on the malicious-ADMIN row of §4.7, and proposes the decision as M20, pending maintainer agreement.

### Details

- **Affected:** `threat-model.md` only: the status line, a §4.5a row, §4.7, §4.8 property 13, and a wave-6 table with M20 in §4.14.
- **Developer and release impact:** Reviewers and triagers classify reports about disabling query audit by the switch: with it on, a supported entry that still disables or hollows out query audit is a violation; with it off, M3 holds. Code execution inside the FE, tampering with written records and reliable delivery stay out of scope. The severity tier of property 13 is left to the maintainers.
- **License and third-party:** None.
- **Rollback:** Revert this commit; no code depends on the text.

### Testing

- Not applicable: documentation only. The statements in property 13 are covered by the tests of the commits that implement the switch.

### Release note

None

### 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 text and this message
- Human review: not stated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morningman

Copy link
Copy Markdown
Contributor Author

run buildall

@morningman

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review recovery stopped: Command '['gh', 'api', 'repos/apache/doris/pulls/70123']' returned non-zero exit status 1.
Workflow run: https://github.com/apache/doris/actions/runs/41644265613

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28196 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 32063b01837b8bb49bd4452d99c998c41faed34e, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17738	5128	5053	5053
q2	2104	298	262	262
q3	10285	1370	815	815
q4	4680	457	331	331
q5	7425	786	521	521
q6	183	188	152	152
q7	739	810	593	593
q8	9249	1339	1011	1011
q9	5421	4197	4132	4132
q10	6807	1289	1033	1033
q11	429	246	228	228
q12	628	391	284	284
q13	18091	3496	2978	2978
q14	288	269	247	247
q15	q16	726	738	673	673
q17	1190	738	572	572
q18	6951	6207	6099	6099
q19	1114	957	612	612
q20	372	329	223	223
q21	4663	2124	2254	2124
q22	343	294	253	253
Total cold run time: 99426 ms
Total hot run time: 28196 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5608	5686	5593	5593
q2	685	559	522	522
q3	5183	5342	4913	4913
q4	1971	2152	1553	1553
q5	5261	5128	5424	5128
q6	267	207	164	164
q7	2326	2028	1845	1845
q8	2991	2622	2694	2622
q9	8006	7959	7949	7949
q10	3988	3767	3257	3257
q11	617	453	403	403
q12	675	689	538	538
q13	3655	3856	3298	3298
q14	334	314	293	293
q15	q16	696	755	656	656
q17	8233	6937	6860	6860
q18	12971	12191	12841	12191
q19	892	764	771	764
q20	2177	2138	1914	1914
q21	5532	4585	4661	4585
q22	488	475	439	439
Total cold run time: 72556 ms
Total hot run time: 65487 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 150749 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 32063b01837b8bb49bd4452d99c998c41faed34e, data reload: false

query5	4306	568	452	452
query6	428	204	189	189
query7	4813	434	231	231
query8	327	167	153	153
query9	8789	3190	3173	3173
query10	475	304	262	262
query11	6048	3851	3573	3573
query12	146	92	87	87
query13	1254	449	333	333
query14	6189	3970	3663	3663
query14_1	3422	3419	3443	3419
query15	207	202	180	180
query16	934	428	411	411
query17	850	674	533	533
query18	2427	425	321	321
query19	209	169	163	163
query20	86	87	86	86
query21	211	131	106	106
query22	12961	13109	12979	12979
query23	13558	12927	12283	12283
query23_1	12655	12645	12385	12385
query24	7350	837	463	463
query24_1	470	471	478	471
query25	509	398	362	362
query26	1258	255	134	134
query27	2767	436	271	271
query28	4625	2015	2019	2015
query29	1557	574	422	422
query30	298	217	178	178
query31	1000	933	822	822
query32	137	87	92	87
query33	518	290	227	227
query34	878	861	513	513
query35	726	749	649	649
query36	804	810	719	719
query37	128	97	81	81
query38	1773	1743	1678	1678
query39	781	779	758	758
query39_1	724	717	747	717
query40	213	115	96	96
query41	67	66	61	61
query42	86	83	80	80
query43	350	366	312	312
query44	1323	690	720	690
query45	178	174	165	165
query46	850	957	568	568
query47	2787	3013	2669	2669
query48	300	304	224	224
query49	582	409	288	288
query50	677	272	212	212
query51	10319	10516	10171	10171
query52	79	80	70	70
query53	183	217	150	150
query54	230	210	200	200
query55	71	67	63	63
query56	222	207	210	207
query57	1658	1583	1579	1579
query58	285	260	276	260
query59	2177	2238	2036	2036
query60	303	235	223	223
query61	146	144	137	137
query62	385	331	280	280
query63	189	157	160	157
query64	2732	937	749	749
query65	3342	3296	3260	3260
query66	1766	426	294	294
query67	20346	20132	20167	20132
query68	2968	1011	624	624
query69	378	285	257	257
query70	846	787	767	767
query71	297	226	209	209
query72	2702	2608	2281	2281
query73	509	521	299	299
query74	4613	4509	4321	4321
query75	2315	2282	1905	1905
query76	2320	1008	590	590
query77	339	367	266	266
query78	9731	9628	9158	9158
query79	904	827	525	525
query80	488	405	343	343
query81	510	328	270	270
query82	197	127	103	103
query83	188	193	182	182
query84	290	112	104	104
query85	789	415	375	375
query86	258	240	224	224
query87	1995	1956	1779	1779
query88	3658	2764	2758	2758
query89	320	286	245	245
query90	2092	162	157	157
query91	154	152	125	125
query92	96	86	87	86
query93	982	969	576	576
query94	449	304	278	278
query95	574	410	308	308
query96	676	484	240	240
query97	2425	2429	2314	2314
query98	155	151	151	151
query99	748	767	655	655
Total cold run time: 233235 ms
Total hot run time: 150749 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.37 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 32063b01837b8bb49bd4452d99c998c41faed34e, data reload: false

query1	0.00	0.00	0.00
query2	0.09	0.04	0.04
query3	0.26	0.09	0.09
query4	1.61	0.10	0.11
query5	0.25	0.24	0.23
query6	1.17	0.67	0.68
query7	0.03	0.01	0.01
query8	0.06	0.04	0.03
query9	0.39	0.35	0.36
query10	0.56	0.56	0.58
query11	0.19	0.14	0.14
query12	0.18	0.15	0.14
query13	0.49	0.50	0.50
query14	1.02	1.01	1.01
query15	0.62	0.60	0.61
query16	0.34	0.35	0.35
query17	1.14	1.13	1.18
query18	0.20	0.19	0.19
query19	2.11	2.01	2.01
query20	0.02	0.01	0.02
query21	15.51	0.19	0.13
query22	4.90	0.05	0.06
query23	16.26	0.32	0.13
query24	2.70	0.60	0.58
query25	0.10	0.05	0.04
query26	1.57	0.22	0.16
query27	0.05	0.04	0.04
query28	3.57	0.67	0.36
query29	12.50	4.07	3.22
query30	0.30	0.13	0.10
query31	2.77	0.56	0.32
query32	3.22	0.60	0.50
query33	3.15	3.26	3.13
query34	15.31	3.94	3.36
query35	3.32	3.32	3.34
query36	0.57	0.44	0.42
query37	0.09	0.06	0.06
query38	0.04	0.04	0.04
query39	0.03	0.02	0.02
query40	0.17	0.15	0.14
query41	0.09	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.03	0.04
Total cold run time: 97.03 s
Total hot run time: 24.37 s

morningman added a commit that referenced this pull request Nov 4, 2026
…it messages (#70175)

### Background

Every PR against `master` starts from
`.github/PULL_REQUEST_TEMPLATE.md`, and the root `AGENTS.md` tells
coding agents to write commit messages in the same layout. The current
template asks for a problem summary, a release note, and checkboxes for
tests, behavior changes, and documentation. Doris merges PRs by
squashing, so the description becomes the commit message on `master`.

### What problem does this PR solve?

Issue Number: None
Related PR: #42999 (introduced the current template), #70123 (a
description written in this layout)
PR Type: Build/CI/Chore

Problem Summary:

The current template leaves out what reviewers most often have to ask
for: the context of the module, why the change is needed and why this
approach, why existing tests missed a bug, and what was verified. Many
PRs leave its checkboxes unticked. This PR replaces it with a layout
that opens with Background, has required fields for each PR type, asks a
diff of more than about 300 changed lines to open Details with a Change
map, and adds Testing, optional Notes for Reviewers, a pre-submission
status, and an AI disclosure. Commit messages written by `AGENTS.md`
rules follow the same layout.

### Details

- **Affected:** `.github/PULL_REQUEST_TEMPLATE.md`, which every new PR
description starts from, and the commit and worktree rules in the root
`AGENTS.md`. No build scripts, CI jobs, or workflows change;
`title-checker.yml` accepts the same `[type](scope)` titles as before.
- **Developer and release impact:** Authors fill in more sections, with
the required fields of each PR type listed in a comment under Details;
the reviewer checklist is gone. Coding agents write commit messages in
the new layout, and from a worktree they may keep PR handoff files in
`${DORIS_REPO}/.git/pr-handoff/`. Releases are unaffected.
- **License and third-party:** None.
- **Rollback:** Revert this PR; nothing else depends on the template.

### Testing

- `check_pr.py`, the checker of the `doris-pr-description` skill (not
part of this PR; see Notes for Reviewers), reports the unfilled template
as not ready, with 17 errors that include the empty Background, Problem
Summary, Testing, and Release note and every blank answer line. Its
eleven bundled examples, one or two per PR type and written in this
layout, pass it, and so does this description.
- The description of #70123, written in this layout, passes the same
checker, with one warning that its prose is longer than the limit.

### Notes for Reviewers

- Two commits: the template and the `AGENTS.md` rules, then guidance for
the Change map and three refined comments. With the HTML comments
removed, the second commit changes nothing.
- `AGENTS.md` also drops the second copy of the paragraph on which files
a commit may contain.
- The new `AGENTS.md` text names the `develop-with-evidence` and
`doris-pr-description` skills, which are not in this repository yet.
They are to be added to
[apache/doris-skills](https://github.com/apache/doris-skills), which a
later PR includes here as a git submodule.

### Release note

None

### 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 template, the `AGENTS.md` text, the commit messages,
and this description
- Human review: The author reviewed all of the changes line by line.
@CalvinKirs

Copy link
Copy Markdown
Member

Reviewed 32063b0. The core goal makes sense, and the write checks, effective-value reads, startup corrections, and receiving-FE ownership of forwarded prepared audits all have concrete reasons. I would address the following correctness issues before merging:

  1. An accepted audit timeout can stop every audit-table load. The load-timeout rule only enforces a minimum of 600 seconds. With query_audit_always_on=true and the default stream-load limits, this is still accepted:

    SET GLOBAL audit_plugin_load_timeout = 259201;

    The effective getter preserves that value and AuditStreamLoader sends it as the HTTP timeout. However, the transaction validator rejects it because max_stream_load_timeout_second defaults to 259200. Both the ordinary and cloud transaction managers apply this check. The audit loader clears the batch after the failed load, so subsequent batches keep being discarded until the setting is corrected. File audit still works. The new policy therefore accepts a protected setting that deterministically disables table audit. Please validate the effective timeout against the downstream supported range, including historical/replayed values, and add upper-bound coverage.

  2. The new early-failure audit retains the previous statement's correlation fields. The fallback clears QueryId but leaves SqlHash and StmtId, which AuditLogHelper copies into the event. On one connection, prepare A, execute an unrelated COM_QUERY B, then execute A with a binding or uploaded-long-data error. No new executor runs to assign A's identity, so the failed row contains A's SQL but B's hash and statement ID. Please clear/initialize those fields too, and capture the actual event in the test; mocking logAuditLog only checks that it was called.

I also think the policy could be narrower in three places:

  • Constrain effective behavior rather than each parameter's factory default. The INSERT rule requires Integer.MAX_VALUE. With the default SQL cap of 2097152, setting the INSERT cap to 2097152 produces exactly the same effective cap through min(insert, sql), yet the policy rejects it. This restriction does not improve the recorded text.
  • Keep batching requirements separate from keeping audit enabled. The fixed 50 MiB / 60-second settings prevent ordinary workload tuning. For example, a low-QPS deployment flushing every 30 seconds does not reduce event selection or recorded text. The blanket assumption that any departure from the defaults weakens audit needs stronger justification.
  • Avoid permanently rewriting saved globals solely for SHOW consistency. Master takeover journals the effective values, although the effective readers already enforce the policy. Turning the flag off does not restore the previous settings, and policy-off peers also replay these changes. The PR documents this, so it is an explicit design choice, but displaying configured/effective values would preserve the operator's settings and remove this migration path. Rewriting global defaults also does not make existing sessions' displayed values agree with effective behavior.

I would split out the independently useful negative-SQL-length fix, retain the necessary always-on enforcement, and settle the numerical tuning policy and permanent-normalization requirement separately. The central policy abstraction is reasonable if the broad parameter scope remains; the main simplification opportunity is the scope of the rules.

This was a source review; I did not run builds or tests.

…n identity

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123

Problem Summary:
An oversized audit-plugin timeout caused every audit-table load to fail.
Fit authenticated built-in audit loads to the master's Stream Load limits
at transaction begin and load planning, where authoritative bounds are
available. Also keep the timeout representable by the load sink in signed
milliseconds. Forwarded plans preserve the master-selected timeout despite
different follower limits. Variable replication and ordinary loads remain
unchanged.

Prepared executions failing before executor creation retained the previous
command's statement ID and SQL hash. Clear the unallocated statement ID and
restore the hash captured at PREPARE for every always-on execute. Retaining
the effective preparation hash also preserves SQL conversion fallback and
subsequent SQL-hash block-rule matching.

### Release note

Prevent unsupported timeouts from disabling always-on audit-table loads and
preserve the correct statement identity for prepared-execution audit rows.

### Check List (For Author)

- Test: Regression tests cover master timeout selection, transaction-validator
  acceptance, planning and forwarded-plan timeouts, authentication/non-audit
  exclusions, actual audit events for
  binding/long-data failures, valid retry, and effective preparation hash reuse.
- Behavior changed: Yes
- Does this need documentation: No separate page; update the config description
  and policy comments for master-side Stream Load timeout enforcement.
@CalvinKirs

Copy link
Copy Markdown
Member

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28852 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit d91816e3b981caa38607d9e1d5b55d5e2885df5b, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17651	5128	5057	5057
q2	2181	299	253	253
q3	10213	1377	836	836
q4	4674	469	338	338
q5	7448	793	521	521
q6	184	186	152	152
q7	734	803	613	613
q8	9252	1384	1093	1093
q9	5574	4241	4228	4228
q10	6818	1286	1034	1034
q11	434	244	226	226
q12	639	402	279	279
q13	18141	3700	3066	3066
q14	282	269	239	239
q15	q16	724	701	641	641
q17	1209	766	577	577
q18	7054	6186	6117	6117
q19	1118	976	616	616
q20	392	340	243	243
q21	5560	2450	2462	2450
q22	367	326	273	273
Total cold run time: 100649 ms
Total hot run time: 28852 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5951	5940	6064	5940
q2	745	612	538	538
q3	5598	5796	5363	5363
q4	2021	2144	1547	1547
q5	5856	5931	5554	5554
q6	238	182	140	140
q7	2259	2040	1768	1768
q8	3039	2709	2711	2709
q9	8155	7586	7565	7565
q10	3661	3575	3120	3120
q11	579	414	376	376
q12	663	690	521	521
q13	3326	3599	3040	3040
q14	302	288	262	262
q15	q16	657	672	620	620
q17	7773	7080	6873	6873
q18	13012	12186	12830	12186
q19	928	810	815	810
q20	2132	2121	1918	1918
q21	5619	4582	4679	4582
q22	489	484	443	443
Total cold run time: 73003 ms
Total hot run time: 65875 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 28825 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit d91816e3b981caa38607d9e1d5b55d5e2885df5b, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17627	5298	5150	5150
q2	2122	300	247	247
q3	10275	1434	841	841
q4	4670	464	335	335
q5	7434	813	534	534
q6	196	190	154	154
q7	801	831	605	605
q8	9266	1465	1213	1213
q9	5506	4291	4319	4291
q10	6854	1308	1036	1036
q11	438	248	234	234
q12	636	418	281	281
q13	18110	3620	3009	3009
q14	275	267	254	254
q15	q16	733	714	662	662
q17	1365	758	590	590
q18	7012	6168	6121	6121
q19	1099	1051	634	634
q20	389	343	228	228
q21	5091	2145	2328	2145
q22	349	292	261	261
Total cold run time: 100248 ms
Total hot run time: 28825 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	5821	5769	5757	5757
q2	686	587	537	537
q3	5184	5431	4951	4951
q4	1997	2191	1540	1540
q5	5228	5171	5923	5171
q6	263	193	153	153
q7	2350	2117	1910	1910
q8	3201	2986	2799	2799
q9	8112	8047	7923	7923
q10	3759	3680	3240	3240
q11	636	426	405	405
q12	705	710	520	520
q13	3780	3906	3267	3267
q14	328	328	300	300
q15	q16	714	788	651	651
q17	8475	7632	6970	6970
q18	13094	12198	12874	12198
q19	1026	838	819	819
q20	2139	2139	1942	1942
q21	5842	4625	4878	4625
q22	493	470	414	414
Total cold run time: 73833 ms
Total hot run time: 66092 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 154279 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit d91816e3b981caa38607d9e1d5b55d5e2885df5b, data reload: false

query5	4313	525	399	399
query6	430	205	188	188
query7	4793	437	224	224
query8	326	174	159	159
query9	8806	3201	3196	3196
query10	489	313	251	251
query11	5923	3832	3587	3587
query12	155	91	89	89
query13	1266	451	336	336
query14	6158	3904	3651	3651
query14_1	3415	3361	3423	3361
query15	207	202	178	178
query16	945	441	418	418
query17	882	658	544	544
query18	2430	428	324	324
query19	201	176	143	143
query20	86	86	83	83
query21	208	127	109	109
query22	13051	12897	12776	12776
query23	13445	12851	12509	12509
query23_1	12481	12463	12486	12463
query24	7382	837	482	482
query24_1	483	485	517	485
query25	536	433	370	370
query26	1266	259	145	145
query27	2768	443	271	271
query28	4640	2051	2055	2051
query29	1552	608	481	481
query30	303	225	184	184
query31	1024	929	818	818
query32	141	111	91	91
query33	521	317	248	248
query34	916	854	507	507
query35	756	760	651	651
query36	837	811	732	732
query37	139	98	82	82
query38	1798	1720	1665	1665
query39	800	789	745	745
query39_1	721	734	740	734
query40	222	124	102	102
query41	74	70	68	68
query42	92	84	89	84
query43	350	363	312	312
query44	1355	716	726	716
query45	177	178	171	171
query46	843	975	572	572
query47	3036	2887	2935	2887
query48	305	317	217	217
query49	563	390	301	301
query50	711	285	215	215
query51	10559	10744	10598	10598
query52	84	77	67	67
query53	186	215	152	152
query54	253	228	205	205
query55	72	74	61	61
query56	226	209	225	209
query57	1669	1607	1582	1582
query58	281	266	258	258
query59	2151	2197	2004	2004
query60	293	248	231	231
query61	150	156	153	153
query62	390	348	283	283
query63	186	159	160	159
query64	2763	959	757	757
query65	3308	3265	3240	3240
query66	1765	412	309	309
query67	22885	22671	22530	22530
query68	3226	998	622	622
query69	391	302	262	262
query70	877	802	760	760
query71	288	228	216	216
query72	2832	2636	2245	2245
query73	520	524	309	309
query74	4652	4559	4369	4369
query75	2359	2296	1931	1931
query76	2315	1030	613	613
query77	365	357	280	280
query78	9681	9636	9158	9158
query79	990	870	531	531
query80	1119	450	350	350
query81	573	317	266	266
query82	648	141	113	113
query83	298	206	189	189
query84	314	116	109	109
query85	886	440	387	387
query86	386	234	227	227
query87	1965	1954	1794	1794
query88	3816	2795	2791	2791
query89	339	286	243	243
query90	1918	177	176	176
query91	159	146	127	127
query92	95	80	90	80
query93	1068	1025	587	587
query94	580	329	282	282
query95	571	328	360	328
query96	681	490	240	240
query97	2444	2433	2377	2377
query98	160	151	142	142
query99	783	758	659	659
Total cold run time: 238524 ms
Total hot run time: 154279 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 24.04 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit d91816e3b981caa38607d9e1d5b55d5e2885df5b, data reload: false

query1	0.01	0.01	0.01
query2	0.09	0.05	0.05
query3	0.26	0.09	0.08
query4	1.61	0.11	0.10
query5	0.23	0.24	0.24
query6	1.18	0.68	0.68
query7	0.03	0.01	0.00
query8	0.05	0.04	0.03
query9	0.40	0.34	0.33
query10	0.56	0.56	0.59
query11	0.19	0.15	0.14
query12	0.19	0.15	0.14
query13	0.49	0.49	0.49
query14	1.03	1.02	1.03
query15	0.63	0.61	0.61
query16	0.35	0.36	0.35
query17	1.17	1.15	1.12
query18	0.19	0.18	0.19
query19	2.11	2.09	1.95
query20	0.02	0.01	0.01
query21	15.46	0.19	0.13
query22	4.84	0.05	0.04
query23	16.28	0.31	0.13
query24	1.08	0.26	0.16
query25	0.09	0.06	0.04
query26	0.74	0.21	0.15
query27	0.03	0.03	0.03
query28	3.77	0.83	0.34
query29	12.52	4.15	3.26
query30	0.28	0.12	0.10
query31	2.77	0.56	0.32
query32	3.22	0.60	0.51
query33	3.16	3.26	3.32
query34	15.23	3.95	3.34
query35	3.31	3.33	3.36
query36	0.55	0.48	0.45
query37	0.09	0.07	0.06
query38	0.05	0.04	0.04
query39	0.03	0.03	0.03
query40	0.18	0.15	0.14
query41	0.08	0.03	0.03
query42	0.04	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 94.63 s
Total hot run time: 24.04 s

### Background

PR apache#70123 adds an opt-in FE policy for always-on query auditing.
The PR and current master both changed the FE config and variable tests.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#70123 (branch being integrated)
PR Type: Build/CI/Chore

Problem Summary:

Merge Apache Doris master at 5725aa3 into the published PR head.
Keep both FE configs and the imports needed by both sets of variable tests.

### Details

- Affected: The local integration of PR apache#70123 with upstream master.
- Developer and release impact: A two-parent local merge records both histories.
- License and third-party: None.
- Rollback: Either parent remains directly available in Git.

### Testing

All 92 targeted FE unit tests passed across seven test classes. The final
import-only cleanup passed Checkstyle across the 20 changed Java files.
The Docker audit regression did not run within the local container limits.

### Release note

None

### Check List (For Author)

- Behavior changed: No.
- Does this need documentation: No.
- Pre-submission status: Not ready: the correctness review has open findings.

### AI Disclosure

- Tool: Codex.
- Generated: Conflict resolution, review, and commit description.
- Human review: Pending.
### Background

The pending always-on query audit change protects startup and runtime
settings and records prepared execution on the receiving FE.

### What problem does this PR solve?

Issue Number: None
Related PR: apache#70123 (local review follow-up), apache#69467 and apache#70366 (masking offset contracts)
PR Type: Bugfix

Problem Summary:

Close the review findings on early prepared redaction, invalid dispatcher
intervals, and audit records for rejected prepared handles. Keep audit
metadata separate from execution state, retain the audit file in always-on
mode, and use parser-provided UTF-16 ranges for audit text rewriting.

### Details

- Frequency: Applies to the affected prepared execution or logger paths, nonpositive dispatcher settings, and SQL masking with supplementary characters.
- Root cause: The earlier audit path lacked a saved redaction plan and skipped handle lookup failures. It used a one-sided interval bound and wrote the preparation hash into the live execution context. File logging used a shared switch. The shared masker converted offsets already normalized by the parser.
- Why existing tests missed it: Prepared audit tests exercised known handles and ordinary statements. The earlier focused run omitted the separate supplementary-character masking suite.
- Fix: Pass the saved plan and original template for sensitive execution, emit an event for an unknown handle, require a positive dispatcher interval, pass the hash into the audit event, keep the audit file appender, and give UTF-16 audit replacements an explicit rewrite entry point.
- Other paths and branches: Migrate streaming-insert masking consumers of the same parser offsets. Preserve lexer code-point handling for view rewrites. This commit targets the pending local PR branch.

### Testing

169 targeted FE tests passed in the expanded run. All 23 tests in the prepared-statement class passed after correcting its synthetic query ID fixture. Checkstyle passed on all 29 Java files in the full diff.

### Release note

Sensitive prepared audit records use masked SQL templates. Always-on query audit records unknown prepared handles, keeps its file appender, and rejects invalid dispatcher intervals. Audit SQL masking preserves supplementary characters correctly.

### Check List (For Author)

- Behavior changed: Yes (see Details).
- Does this need documentation: No separate update. The FE config description covers the audit file behavior.
- Pre-submission status: Partially verified: Docker and mixed-version cluster scenarios were not exercised.

### AI Disclosure

- Tool: Codex.
- Generated: Local bug fixes, unit coverage, and follow-up review.
- Human review: Pending.
@CalvinKirs

Copy link
Copy Markdown
Member

run buildall

@github-actions

Copy link
Copy Markdown
Contributor

Codex automated review failed and did not complete.

Error: Review recovery stopped: shared time budget or helper timeout exhausted
Workflow run: https://github.com/apache/doris/actions/runs/45368344931

Please inspect the workflow logs and rerun the review after the underlying issue is resolved.

@CalvinKirs

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes for two verified runtime-policy gaps at fa2e044: the load-disable switch still stops audit-table writes, and the new timeout clamp accepts bounds with no safe intersection. Both are inline below. They have separate causes and fixes.

Reviewed all 32 changed files and the related invocation paths: statement -> AuditLogHelper -> WorkloadRuntimeStatusMgr -> AuditEventProcessor -> file logger / built-in loader -> authenticated stream-load transaction and plan. Three reviewers rechecked their complete scopes and challenged the final findings in round 2; all returned NO_NEW_VALUABLE_FINDINGS.

Critical checkpoint conclusions:

  • Goal and evidence: the immutable opt-in policy enforces the listed settings and prepared execution auditing, but the two findings leave the required table destination disableable. Added tests cover the main behavior; these runtime controls are missing cases.
  • Scope and reuse: policy rules and truncation are centralized; existing setters, queues and journal mechanisms are reused. No additional scope issue identified.
  • Concurrency and locking: statement, RPC, dispatcher and loader threads traced. Existing synchronized batching and reentrant variable locks remain; no new lock-order defect or heavy metadata-lock operation identified.
  • Lifecycle and initialization: corrections follow both config files and precede logging/pipeline startup; master rewriting follows replay shutdown. Prepared cleanup, retained hashes and bindings are consistent; no new initialization cycle or resource leak identified.
  • Config changes: the policy switch is startup-only. Protected mutable configs use the callback on ADMIN/HTTP updates, and effective readers cover stale/replayed variables. The two findings concern remaining runtime load controls.
  • Compatibility: existing global-variable types and replay entries are retained; each receiving FE must enable the policy. Safe rewritten globals persist after the switch is turned off, as documented.
  • Thrift/Protobuf: no definitions or field IDs changed; release-branch schema comparison is not applicable.
  • Parallel paths: ordinary/prepared/forwarded/failed executions, REST truncation, streaming masking, defaults/replay and local/cloud load handling inspected. Both findings affect the shared audit-table path.
  • Special conditions: proxy suppression, executor absence, token/table/master checks and UTF-16 range producers/consumers traced. The timeout clamp lacks a valid-range precondition, as detailed inline.
  • Test coverage: policy on/off, negative length, settings/defaults/hints/follower copies, persisted rewrites, prepared identity/hash/redaction, file appenders and ordinary timeout ranges are covered statically. Add the two missing control-path cases. The docker suite is outside normal PR CI, as disclosed by the author.
  • Expected results: changed regression rows agree with ordering and marker filters. Generated-output provenance and pass claims were not independently executed or verified.
  • Observability and errors: setter rejections fail visibly; startup activation/corrections and loader labels provide context. HTTP config rejections produce system WARNs; this review does not claim they become query audit events.
  • Transactions and persistence: global rewrites use existing edit-log/image replay and takeover ordering. No new persisted format or additional failover defect identified.
  • Writes and crash behavior: existing audit stream-load transaction/commit semantics remain; no user-data publication protocol changes. Full queues, incidental load failures and crashes remain outside the stated reliable-delivery guarantee; the findings are lasting disable mechanisms reachable through supported settings.
  • FE/BE propagation: no new wire variable; existing begin/plan timeout fields are used. The unsafe minimum can defeat the millisecond cap, as detailed inline.
  • Performance: constant-size policy checks and startup-only rewrites; increased prepared audit volume is intentional. No additional new performance defect identified through static inspection.
  • Other invariants: no storage visibility, delete-bitmap or optimizer-rule changes. Prepared failure identity, forwarding and Unicode masking risks were dismissed with source evidence.

No additional user focus was supplied. No existing inline findings were present on the refreshed PR. All candidates and initial risk questions have a recorded disposition, with no remaining coverage gap. Review converged in 2 rounds. Static inspection only: no builds, tests or benchmarks were run.

Review converged after 2 round(s).


// The mutable FE configs. They get no read-side check: their values come only from startup, which corrects them,
// and from ConfigBase.setMutableConfig, whose ProtectedConfHandler rejects what breaks the rules.
private static final ImmutableMap<String, ProtectedConfig> CONFIGS = ImmutableMap.<String, ProtectedConfig>builder()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Prevent the load-disable switch from disabling always-on audit

With query_audit_always_on=true, ADMIN SET FRONTEND CONFIG ("disable_load_job" = "true") still succeeds because that mutable config has no policy callback. Every subsequent built-in audit batch then fails in GlobalTransactionMgr.beginTransaction (and CloudGlobalTransactionMgr.beginTransaction), which reject all loads before any internal-coordinator exemption; AuditLoader.loadIfNecessary clears each failed batch. This leaves fe.audit.log running while permanently disabling the required audit-table destination through one supported runtime setting. Please protect this switch too, or consistently exempt authenticated built-in audit transactions from its begin/commit/publish checks. This is a lasting runtime disable path, rather than an incidental load failure.

private static long boundAuditLoadTimeout(long timeout) {
// The V1 load sink stores its RPC timeout in signed milliseconds.
long maximum = Math.min(Config.max_stream_load_timeout_second, Integer.MAX_VALUE / 1000);
return Math.max(Config.min_load_timeout_second, Math.min(timeout, maximum));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Validate that the audit timeout bounds have a safe intersection

The lower bound can override both maxima calculated above. For example, ADMIN SET FRONTEND CONFIG ("max_stream_load_timeout_second" = "0") is accepted while always-on audit is enabled; with the default minimum of 1 this returns 1, and checkValidTimeoutSecond rejects every subsequent audit transaction because 1 exceeds the configured maximum. Even ordered positive bounds can defeat the overflow cap: minimum 2147484 and maximum 2147483647 return 2147484, which overflows the V1 sink's signed millisecond timeout. Neither config has a validation callback. Please reject policy-incompatible bounds or give internal audit loads a safe independent range, so runtime settings cannot make every batch fail despite this normalization.

### Background

PR apache#70123 adds an opt-in policy for query auditing and validates settings at statement time. Prepared executions reuse their parsed templates after preparation.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123 (introduces always-on query auditing)
PR Type: Bugfix

Problem Summary:

The new policy can lose its restart-only setting during a mutable config reset and leave temporary hint settings in the session after a rejected parse. Protected GLOBAL assignments also need to use the master's replayed state. Prepared audit text needs the mode it was parsed under and the execution adapter's metadata.

### Details

- **Frequency:** Triggered by a mutable config reset after custom opt-in, a policy-rejected hint, a successful protected global assignment returned to a follower, or a prepared audit after a session mode change.
- **Root cause:** Mutable persistence shared the custom overlay, parse rejection bypassed executor cleanup, the follower evaluated already committed values again, and prepared redaction shared the execution adapter.
- **Why existing tests missed it:** They covered direct setting validation and journal serialization without checking parser cleanup, configuration reload, or replay and subsequent forwarding.
- **Fix:** Retain the operator audit setting during mutable reset. Restore temporary settings and mask audit text on policy parse rejection. Read protected GLOBAL values after replay and retain prepared audit text and execution metadata independently.
- **Other paths and branches:** Applies to changes introduced by apache#70123. Existing import pause, HTTP query-plan behavior, mixed-version ownership, and delivery limits retain their baseline behavior.

### Testing

FE Checkstyle and Groovy suite compilation passed. The targeted FE run exercised config, query, prepared audit, and delivery checks. The final replay and prepared reruns are tracked in local evidence.

### Release note

Always-on query auditing preserves the operator's startup setting and produces accurate audit records when temporary hints are rejected or prepared executions use a different SQL mode.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified. The updated two-FE Docker assertions require a live Docker regression run.

### AI Disclosure

- Tool: Codex
- Generated: Code, tests, and commit body
- Human review: Pending
### Background

PR apache#70123 adds policy checks to the query audit pipeline. The first local review of the scoped repairs identified failures in config recovery, forwarded statement order, and audit rejection handling.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123 (introduces the audit policy)
PR Type: Bugfix

Problem Summary:

The scoped fixes need to preserve existing config reset and prepared-context contracts. Protected GLOBAL updates must keep compound SET ordering, and new audit-policy parse failures must produce a safe, recognizable audit event.

### Details

- **Frequency:** Encountered on reset of an invalid operator overlay, on compound SET, or when a temporary hint changes SQL mode or triggers the new rejection.
- **Root cause:** A config reset required parsing the damaged overlay, prepare metadata read a live session after parsing, and the new policy handling assumed one statement.
- **Why existing tests missed it:** Initial tests focused on normal overlays, one setting at a time, and session mode changes after preparation.
- **Fix:** Preserve the last readable startup option during reset recovery. Source audit mode from lexical parsing and preserve the prepared-context lifecycle. Retain compound SET order, safely mask batched statements, and audit the new authorized HTTP planning rejection.
- **Other paths and branches:** Scoped to the behavior added by apache#70123. Existing HTTP forwarding, load pause, and delivery limits retain their previous behavior.

### Testing

FE Checkstyle passed. The expanded targeted FE tests include prepared-context, compound SET, HTTP planning, mode and masking checks. Their final results are tracked in local evidence.

### Release note

Always-on query auditing preserves config recovery and reports rejected query plans and query batches.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified. The live Docker regression remains to be run.

### AI Disclosure

- Tool: Codex
- Generated: Code, unit tests, and commit body
- Human review: Pending
### Background

A rejected query needs its own audit metadata. Forwarded SET executes and validates on the master before the receiving FE updates its session.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123 (introduces the audit policy)
PR Type: Bugfix

Problem Summary:

A new policy rejection can reuse the preceding statement's identifier, and one statement's masking failure can discard the rest of a batch. Re-evaluating a protected SESSION assignment after journal replay can reject a SET the master already accepted.

### Details

- **Frequency:** Triggered by a policy rejection before execution, a valid batch with independent masking outcomes, or a forwarded compound SET reading a setting that changes in the same command.
- **Root cause:** Parse rejection skips statement ID allocation, batch masking shared one failure path, and the follower evaluated a protected assignment against post-replay state.
- **Why existing tests missed it:** They checked the rejection and the basic forwarded result without observing these state transitions.
- **Fix:** Reset statement identity and use the rejected SQL hash, isolate masking fallback by statement, and apply the only permitted protected SESSION value after master success.
- **Other paths and branches:** Scoped to the new audit policy behavior.

### Testing

FE Checkstyle passed. The expanded FE test run covers query identity, per-statement audit masking, forwarded compound settings, and the HTTP fixture using a dialect manager.

### Release note

Always-on query audit retains the correct rejection identity and available statement text, and preserves successful forwarded audit settings.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified. Live Docker regression remains to be run.

### AI Disclosure

- Tool: Codex
- Generated: Code, unit tests, and commit body
- Human review: Pending
### Background

A query rejected before execution can require an audit-only parsing pass. A forwarded compound SET also has an existing ordered series of receiving-session callbacks after master validation.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123 (introduces the audit policy)
PR Type: Bugfix

Problem Summary:

The audit mask pass must leave the client context alone. The permitted audit session value must also be restored without changing how other assignments in a compound SET are evaluated.

### Details

- **Frequency:** Relevant when a rejected packet contains statements requiring a masking traversal, or when other assignments in a forwarded compound SET read the audit variable.
- **Root cause:** The masking visitor shared the caller's context, and the follower restored the protected value before evaluating sibling assignments.
- **Why existing tests missed it:** The initial tests asserted audit output and the final protected value without checking temporary parser state or dependent assignment order.
- **Fix:** Run the audit visitor in an isolated statement context and avoid constructing INSERT commands. Retain ordered callbacks and normalize the protected value at their end.
- **Other paths and branches:** This applies to the new audit policy paths in apache#70123.

### Testing

FE Checkstyle passed. The targeted FE run checks parser isolation, valid forwarded assignment ordering and the HTTP event in its completed unit-test environment.

### Release note

Always-on query audit leaves client parser state intact and preserves compound SET ordering on a follower.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified. Live Docker regression remains to be run.

### AI Disclosure

- Tool: Codex
- Generated: Code, unit tests, and commit body
- Human review: Pending
### Background

The audit-only INSERT parser inspects query text without constructing an executable command.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123 (introduces the audit policy)
PR Type: Bugfix

Problem Summary:

An INSERT can use a prefix CTE with options that require audit masking. Traversing only the INSERT body leaves the prefix CTE outside that masking pass.

### Details

- **Frequency:** Applies to an audit-only INSERT with a prefix CTE that contains masked properties.
- **Root cause:** The grammar supplies the prefix CTE and INSERT query through separate nodes.
- **Why existing tests missed it:** The isolated parser check exercised an INSERT body without a prefix CTE.
- **Fix:** Traverse the prefix CTE through the existing logical builder helper while avoiding executable INSERT construction.
- **Other paths and branches:** Existing statement construction and legacy single-statement masking retain their behavior.

### Testing

FE Checkstyle passed. A synthetic INSERT CTE fixture checks that the audit text retains the INSERT and masks the fixture property value.

### Release note

Always-on audit masking covers prefix CTEs in INSERT statements.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified. Live Docker regression remains to be run.

### AI Disclosure

- Tool: Codex
- Generated: Code, unit test, and commit body
- Human review: Pending
### Background

Audit-only INSERT parsing now visits the query without constructing an executable command.

### What problem does this PR solve?

Issue Number: apache#70122
Related PR: apache#70123
PR Type: Bugfix

Static INSERT partition values are expressions. The audit-only traversal skipped them, which also skipped the existing handling of invalid duplicate partition entries.

### Details

- Reuse the logical builder's existing partition parser between the source query and prefix CTE visits.
- Cover an ordinary static partition and a benign duplicate-column error in a multi-statement audit packet.

### Testing

Checkstyle passed for the Java files changed by the PR. The targeted FE suite is running with the new fixtures.

### Release note

Always-on audit formatting covers static partition expressions in INSERT statements.

### Check List (For Author)

- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Partially verified

### AI Disclosure

- Tool: Codex
- Generated: Code, unit test, and commit body
- Human review: Pending
@CalvinKirs

Copy link
Copy Markdown
Member

Local pipeline review — ✅ PASS

schema: doris-repo-review/v1
status: PASS
pr: apache/doris#70123
commit: 0fb19d3c5615c2092058eb8ac7fd046175dbe311
base: 5725aa3850e0c5f23191465e09fad14b037a87dd
reviewed_at: 2026-11-25T11:08+08:00
reviewer: CalvinKirs
model: gpt-6.2-sol
effort: xhigh
findings: {blocker: 0, major: 0, minor: 0, nit: 0}
rounds: 1
converged: true

Notes for maintainers

  • 252 targeted FE tests passed. Checkstyle reported zero violations across 40 changed Java files. The Groovy regression suite compiled.
  • Live two-FE audit delivery and Doris 4.1.5 BE integration were not rerun on this commit.

Reviewed locally with the doris-repo-review pipeline. Repository policy may accept this receipt for the matching commit; it is not a human Apache approval.

@CalvinKirs

Copy link
Copy Markdown
Member

run buildall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][Audit] Add query_audit_always_on to keep query audit from being disabled at runtime

3 participants