Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the robustness and security of log file handling in PerConnectionFileHandler by implementing a fallback mechanism for the global log file when it is locked or foreign-owned, enforcing strict POSIX file permissions, and robustly handling thread interrupts during write operations. The review feedback highlights a critical path resolution bug in openGlobalChannel where differing canonical paths before and after file creation on symlinked filesystems (like macOS) can leak keys in ACTIVE_GLOBAL_PATHS and permanently lock out future handlers. To resolve this, it is recommended to canonicalize the parent directory from the start and clean up the now-unused canonicalClaimKey helper method.
5652b76 to
a1fb46f
Compare
| PosixFilePermissions.asFileAttribute(FILE_PERMS_0600); | ||
| private static final int PROCESS_UID = resolveProcessUid(); | ||
| private static final UserPrincipal PROCESS_PRINCIPAL = resolveProcessPrincipal(); | ||
| static volatile Integer overrideUidForTesting; |
There was a problem hiding this comment.
Nit. This is a mutable static test hook in production code. Could tests pass the UID in through a package-private parameter instead?
There was a problem hiding this comment.
Since both PerConnectionFileHandler and overrideUidForTesting are package-private, external callers outside com.google.cloud.bigquery.jdbc cannot access or mutate it, and effectiveProcessUid() is only read on cold directory/channel open validation (never on log writes). Threading an explicit UID parameter through the constructors, ChannelLogWriter, and the static NIO helpers (ensureSecureDirectory, openGlobalChannel, openAppendValidated, verifyPosixOwner) touches ~45 lines across PRs 2–6 solely for test plumbing, so we kept the single package-private hook to keep the stack diffs minimal.
a1fb46f to
8abca56
Compare
Stack: PR 2 of 6 (base:
fix/bq-jdbc-log-file-hardening)Bug: b/584840147
Summary
Adds in-JVM and cross-process sentinel locking on
BQ-JDBC-GLOBAL.logwith collision-free fallback file allocation andClosedByInterruptExceptionchannel recovery inPerConnectionFileHandler.Design Decisions
ACTIVE_GLOBAL_PATHSand acquires a non-blocking 1-byte sentinel lock (FileChannel.tryLock(Long.MAX_VALUE - 1, 1L, false)), falling back to an exclusiveBQ-JDBC-GLOBAL-<yyyyMMddHHmmss>-<4hex>.logfile on contention.finallyaround NIO channel opens and writes and reopens validated channels afterClosedByInterruptException.