Skip to content

[Pipe] Enforce source and receiver privileges - #19361

Open
Caideyipi wants to merge 7 commits into
apache:dev/1.3from
Caideyipi:security/pipe-privilege-enforcement
Open

Caideyipi wants to merge 7 commits into
apache:dev/1.3from
Caideyipi:security/pipe-privilege-enforcement

Conversation

@Caideyipi

@Caideyipi Caideyipi commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add authentication checks to DataNode Pipe request handling before compressed payload decoding and slice assembly.
  • Carry authenticated source identity through data, schema, logical-view, and asynchronous LOAD transfer paths.
  • Add regression coverage across receiver authentication, source privilege filtering, logical-view authorization, and LOAD identity handling.

Example

A DataNode sink authenticates with a V2 Pipe handshake as alice and sends a tablet transfer without opening a client session. Before this change, the transfer is rejected with NOT_LOGIN; after it, the receiver checks the authenticated identity for the required privilege, allowing authorized transfers and returning NO_PERMISSION when that privilege is missing.

Validation

  • Scoped Spotless passed.
  • IoTDBDataNodeReceiverTest passed locally (19 tests, 0 failures).
  • PR CI for head 4ed168887d45041f9aa8f05ae2306e7026ba0c38 is pending.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

CI follow-up for 1cb065a134a3fd0d563c802fe0c6af2e7819b6c7:

  • Removed testLogicalViewSnapshotRetainsSourcePaths, which attempted logical-view creation against both Memory and PBTree schema backends; both reject that operation as unsupported.
  • Updated the forwarding IT setup to provide the supported source.user and source.password attributes for pipes created through ConfigNode RPC, which bypasses SQL creator-identity injection.
  • Verification: Spotless completed successfully, and SchemaRegionSnapshotParserTest passed locally (8/8). The triple-cluster forwarding IT was not rerun locally.
  • This PR remains a draft. CI for the updated head is queued or in progress.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

CI repair summary

  • Reviewed failing CI head 1cb065a134a3fd0d563c802fe0c6af2e7819b6c7 (45108104698, triple job 137474023943): IoTDBPipeForwardIT.testForwardingPipeRequests failed during pipe creation with status 1107 instead of 200. CreatePipeProcedureV2 stores source.password in hashed form, while ConfigNode, DataRegion, and SchemaRegion source startup validated only plaintext. All three paths now validate the stored hash first and retain plaintext fallback for existing tasks.
  • The same run's manual-create-schema job also failed existing forwarding fixtures that omitted source identity. The fail-closed source privilege checks withheld their data/schema/auth events. Those fixtures now configure source authentication explicitly; missing identity still does not bypass checks.
  • Scoped Spotless and git diff --check pass. Local runtime Pipe ITs were not run because another Maven verification was active; that process was left untouched. Post-fix CI was queued at confirmation (45136134695); no result is claimed.
  • Reviewed CI SHA: 1cb065a134a3fd0d563c802fe0c6af2e7819b6c7. Final local and confirmed remote SHA: f88c6047ca974af9cb8ef644ce775ed5bd16c71f. The PR remains draft.

@Caideyipi

Caideyipi commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI follow-up for reviewed commit f88c6047ca974af9cb8ef644ce775ed5bd16c71f; updated PR head: f82b3ee00181fa8853cff437a12160b428af48c4.

  • Removed the redundant extractor user=root attribute from IoTDBPipeWriteBackSinkIT; source authentication is already supplied via source.user.
  • Updated IoTDBPipeManualConflictIT.testDoubleLivingTemplate to wait until the receiver observes all three source timeseries before issuing DDL that depends on the asynchronously replicated template.
  • Local verification: spotless:apply passed and git diff --check passed. The focused ITs were not run locally because clean-source verification would require clean, which was explicitly prohibited for this task.
  • CI is now active for this head: Multi-Cluster IT is pending, Cluster IT - 1C3D is in progress, and the remaining workflows are queued.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

CI follow-up:

At the failing PR head f82b3ee00181fa8853cff437a12160b428af48c4, IoTDBPipeManualConflictIT.testDoubleLivingTemplate exposed that the admin transfer filter only recognized a schema template through paths where it was already bound. A valid unbound template was therefore rejected during transfer, and the receiving side later reported that t1 did not exist.

This update adds an admin short-circuit in PipeConfigTreePrivilegeParseVisitor.canShowSchemaTemplate; non-admin path authorization remains unchanged.

Verification: mvn spotless:apply -P with-integration-tests -pl iotdb-core/confignode and git diff --check passed. The failing integration test was not run locally.

Commit 0cd243d0c8d37894baa2ee3197ad38dd33115c80 is confirmed as both the source-branch and PR head. The PR remains a draft.

@Caideyipi
Caideyipi marked this pull request as ready for review November 25, 2026 10:40
TREE_STATEMENT_TO_PLAN_VISITOR.process(remainBatches.next(), null), false);
}

@Override

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/schemaregion/IoTDBSchemaRegionSource.java:216 — getNextEventInCurrentSnapshot calls remainBatches.next() without hasNext check

When the snapshot generator is exhausted and remainBatches was already created and fully drained by previous hasNextEventInCurrentSnapshot()/getNextEventInCurrentSnapshot() calls, the final remainBatches.next() throws NoSuchElementException. hasNextEventInCurrentSnapshot() only rebuilds remainBatches when it is null, so after the last batch is consumed the next call to getNextEventInCurrentSnapshot() (e.g. from supply() when hasNextSnapshotPlan() returned true earlier in the
…[truncated]

Fix: Guard with remainBatches.hasNext() and return/throw a controlled PipeException, or reset remainBatches to null after it is exhausted so it is rebuilt from batchVisitor.getRemainBatches().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No code change. IoTDBSchemaRegionSource.supply() is synchronized and calls hasNextSnapshotPlan() immediately before getNextEventInCurrentSnapshot(). When the generator is exhausted, that check materializes remainBatches and returns false if it is drained, so the getter is not called with an empty iterator. While the generator still has input, the batch visitor either emits a statement or accumulates data for its remaining batch.

},
"PipeProcessorSubtask::executeOnce",
executionGuard);
tsFileEvent.close();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java:202 — tsFileEvent.close() runs even when consumption yielded, discarding parser state

consumeTabletInsertionEventsWithRetry rethrows PipeProcessorSubtaskYieldException/PipeRuntimeOutOfMemoryCriticalException to signal that the event must be retried later, and its javadoc/implementation explicitly retains the iterator and pending tablet for that retry. Here tsFileEvent.close() is called unconditionally after the call, so on a yield the parser state, pending tablet and isTsFileParsingCompleted are reset; the retried event re-parses the whole TsFile from scratch (and `mark
…[truncated]

Fix: Only call tsFileEvent.close() and markHistoricalTsFileSplit when consumption completed normally; let the yield/OOM exceptions propagate without closing the event.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No code change. consumeTabletInsertionEventsWithRetry rethrows PipeProcessorSubtaskYieldException and PipeRuntimeOutOfMemoryCriticalException on retryable paths. Those exceptions exit the call before the following close() and markHistoricalTsFileSplit() statements execute, leaving parser state intact for retry.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review-comment follow-up for reviewed head 0cd243d0c8d37894baa2ee3197ad38dd33115c80:

  • Fixed stale receiver handshake gating; a rejected credential-less V2 handshake no longer prevents transfers authenticated by an existing logged-in session.
  • Added regression coverage for opening a session, issuing a V2 handshake without credentials, and successfully transferring afterward.
  • No code changes for the snapshot iterator and retry comments: synchronized availability checks prevent retrieving an exhausted iterator, and retryable exceptions bypass the subsequent event cleanup and historical marker calls.
  • Verification: scoped Spotless passed (0 files changed); IoTDBPipeReceiverSessionIT#testDataNodeReceiverSessionHandling passed (1/1); git diff --check passed. The first IT attempt stopped on an upstream empty Failsafe match; the corrected run passed.
  • Reviewed SHA: 0cd243d0c8d37894baa2ee3197ad38dd33115c80.
  • Final local and confirmed remote source-branch/PR SHA: 72b266a6a96febd4a1a486ce2d9fe6c188c2bff1.
  • The PR remains open and all discussions remain unresolved. Remote CI was not awaited.

@@ -504,14 +512,42 @@ private TPipeTransferResp checkPipeTransferAuthenticated(final PipeRequestType r
}

final IClientSession clientSession = SESSION_MANAGER.getCurrSession();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

critical iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/thrift/IoTDBDataNodeReceiver.java:514 — Pipe transfers from IoTDB sinks are rejected: sink connections never open a session

checkPipeTransferAuthenticated now returns NOT_LOGIN whenever SESSION_MANAGER.getCurrSession() is null or not logged in. IoTDBSyncClientManager.sendHandshakeReq only sends HANDSHAKE_DATANODE_V2 (username/password) and never calls openSession, so on every sink connection the session stays unauthenticated and all TRANSFER_* requests (tablet, tsfile, schema plan, compressed, slice) fail with NOT_LOGIN, breaking all DataNode-to-DataNode pipe replication.

Fix: Accept the pipe-handshake credential path without requiring a logged-in session: when hasPipeHandshakeCredential is true and username/userEntity are set, return null before the session check (keep the mismatch check only when a session is logged in).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. Fixed in 4ed168887d45041f9aa8f05ae2306e7026ba0c38: authenticated V2 Pipe handshake credentials now permit transfers without openSession, while a logged-in session is still checked and must match the handshake identity. Slice state is also cleared when authentication changes between session-backed and handshake-only requests. IoTDBDataNodeReceiverTest passes locally (19/19); CI for this head is pending.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review follow-up for 4ed168887d45041f9aa8f05ae2306e7026ba0c38:

  • V2 Pipe handshake identity now authenticates transfer requests without an openSession; when a session exists, its identity must still match the handshake identity.
  • Statement execution checks privileges using the authenticated identity and creates a handshake-backed SessionInfo for sessionless connections.
  • Corrected the CI regression expectation: a rejected handshake leaves the existing logged-in session subject to authorization, so an unprivileged statement returns NO_PERMISSION (803), not NOT_LOGIN (802). Added coverage for sessionless authorization and slice-state transitions.
  • Local verification: scoped Spotless passed; IoTDBDataNodeReceiverTest passed (19/19); git diff --check passed.
  • CI for this head is pending. The PR remains open, and discussions remain unresolved.

if (username == null) {
return emptyTree;
}
final org.apache.iotdb.confignode.rpc.thrift.TAuthizedPatternTreeResp response =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

major iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/PipeConfigTreePrivilegeParseVisitor.java:372 — trimPatternTree throws on partially authorized delete plans even with skipIfNoPrivileges

In trimPatternTree the condition !skipIfNoPrivileges && !originalTree.equals(intersectedTree) is inverted relative to every other check in this visitor (getAllIntersectedPatterns, getDeniedIndexes, noPrivilege). With the default skipIfNoPrivileges=true, a PipeDeleteTimeSeriesPlan/PipeDeleteLogicalViewPlan that is only partially covered by the source user's READ_SCHEMA tree throws a PipeException instead of being trimmed, aborting the pipe task on a common path.

Fix: Change the condition to !skipIfNoPrivileges && !originalTree.equals(intersectedTree) -> throw only when skipIfNoPrivileges is false, i.e. use if (!skipIfNoPrivileges && !originalTree.equals(intersectedTree)).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No code change is needed. At the current PR head, trimPatternTree already checks !skipIfNoPrivileges && !originalTree.equals(intersectedTree), so a partially covered tree is intersected when skipIfNoPrivileges is true and rejected only when it is false. The condition shown in the comment matches the intended guard. Please let me know if you were referring to a different revision.

String userName = attributes.get(ActiveLoadPathHelper.USER_KEY);
if (userName == null || userName.isEmpty()) {
if (sessionUsername == null || sessionUsername.isEmpty()) {
throw new IOException("The authenticated user for active LOAD could not be resolved.");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/active/ActiveLoadUtil.java:124 — Active LOAD now fails when no session is bound instead of defaulting to the admin user

appendCurrentUserIfAbsent previously fell back to AuthorityChecker.SUPER_USER when no current session existed; it now throws IOException ("The authenticated user for active LOAD could not be resolved.") and loadTsFileAsyncToActiveDir swallows it into a false return. Any programmatic/plugin caller of loadTsFileAsyncToActiveDir without a bound session (e.g. non-pipe async LOAD from a background thread) silently stops loading files.

Fix: Keep the previous SUPER_USER fallback when no session is bound and no user attribute is supplied, and only enforce the identity match when a session is present.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I am keeping this fail-closed. Without a logged-in session or an explicitly supplied authenticated identity, the loader cannot safely attribute the file. Falling back to SUPER_USER would let a sessionless caller persist work that is later executed with administrator privileges, bypassing the identity checks added here. The SQL async path supplies the request user and authenticated marker in LoadTsFileAnalyzer#doAsyncLoad; background callers need to provide an authenticated identity instead of inheriting the administrator account. No code change was made.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review-comment handling summary

  • Reviewed head: 4ed168887d45041f9aa8f05ae2306e7026ba0c38.
  • The partial pattern-tree guard already matches the requested behavior, so no edit was needed. The sessionless active-load path remains fail-closed because defaulting to SUPER_USER would attribute work to an administrator without a logged-in session or supplied authenticated identity.
  • Replied to both new inline comments. Confirmed the two outdated receiver discussions are addressed by the current code and regression coverage; those threads are resolved. Other discussions remain unresolved.
  • Verification: inspected the current control flow, supported SQL caller, and related receiver tests. No source changes were made, so tests were not run.
  • Final local and confirmed remote head: 4ed168887d45041f9aa8f05ae2306e7026ba0c38 (unchanged); no commit or push was needed. The PR remains open.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants