Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the JDBC driver's logging infrastructure to support secure, per-connection file logging using NIO SeekableByteChannel directly, preventing lock file creation and enforcing strict POSIX file permissions. It also introduces a typed ConnectionLogContext to avoid parameter collisions during message formatting and ensures proper cleanup of executors and OpenTelemetry resources upon connection failure. The code review feedback identifies critical resource leaks in PerConnectionFileHandler where opened channels could be leaked if setting POSIX permissions or positioning the channel throws an exception. Additionally, a potential NullPointerException was flagged in BigQueryConnection's cleanup block if openTelemetry is null during a failed initialization.
47aaf40 to
578cc0b
Compare
|
/gemini review |
578cc0b to
8c47507
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors PerConnectionFileHandler to use custom NIO SeekableByteChannel writers instead of standard FileHandler, enforcing secure owner-only POSIX permissions and rejecting symbolic links to improve security. Feedback on these changes includes removing the expensive FileChannel.force(false) call during flushes, improving the robustness of the POSIX owner verification in containerized environments using UserPrincipalLookupService, and adding a defensive null check in closeQuietlyWithSuppressed to prevent a potential NullPointerException from masking primary exceptions.
8c47507 to
5b55b06
Compare
keshavdandeva
left a comment
There was a problem hiding this comment.
The permission hardening works: new directories and files come out 0700 / 0600. But replacing FileHandler with a raw FileChannel introduced one blocker and three majors that main does not have. Details inline.
Question. On Windows, tryLock() on the log file is a mandatory lock. Can another process still tail BQ-JDBC-GLOBAL.log while the JVM runs? FileHandler locked a .lck sidecar instead.
77ae50e to
d2e8aba
Compare
d2e8aba to
483b66a
Compare
| Files.readAttributes(current, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); | ||
| if (attrs.isSymbolicLink()) { | ||
| if (isTarget || !isPosix) { | ||
| throw new IOException("Refusing to use symbolic link in log path: " + current); |
There was a problem hiding this comment.
Question. A LogPath that is itself a symlink is still refused, while links higher in the path are followed when root or the user owns them. Should the last component follow the same rule, e.g. /var/log/app -> /data/logs/app?
There was a problem hiding this comment.
Keeping the leaf component (isTarget) rejected as a symlink is intentional for two reasons:
- Destination directory ownership validation: In
ensureSecureDirectory,verifyPosixOwner(current, true)inspects the symlink inode itself (NOFOLLOW_LINKS), not its target. For intermediate ancestors (/tmp -> /private/tmp,/var/run -> /run), subsequent loop iterations still validate the descendant directory components; if we allowedcontinueonisTarget(i == nameCount - 1), the loop would finish without verifying ownership of the resolved destination directory unless we added recursivereadSymbolicLinkchain-walking with cycle bounds. - Security contract (
b/584840147): Rejecting a symlinked leafLogPathdirectly enforces the symlink-redirection protection on the log directory while still supporting OS-level ancestor symlinks. Deployments mapping/var/log/appto another volume can either bind-mount/data/logs/appor pointLogPathto/var/log/app/jdbc(making/var/log/appan allowed ancestor symlink).
…and allow root owner
|
/gcbrun |
Stack: PR 1 of 6 (base:
main)Bug: b/584840147
Summary
Replaces
java.util.logging.FileHandlerinPerConnectionFileHandlerwith a Java New I/O (NIO)FileChannelwriter (ChannelLogWriter) enforcing owner-only POSIX (0700directory /0600file) permissions, component-by-component symbolic-link and hard-link checks, and graceful error handling.Design Decisions
FileChannel(ChannelLogWriter) overjava.util.logging.FileHandler: Applies0600(rw-------) atomically viaStandardOpenOption.CREATE_NEW, avoids.lcksidecar files and%pattern expansion, and keepsflush()as a no-op over unbuffered OS channel writes.nlink == 1) checks: Walks every path segment from root withLinkOption.NOFOLLOW_LINKS, rejecting target symlinks, non-regular files, hard-linked files (unix:nlink > 1), and foreign-owned paths (while allowing root-owned OS ancestor symlinks), and re-verifies attributes post-open.LogPathtargets report viajava.util.loggingErrorManagerwithout throwingSQLExceptionfromDriverManager.getConnection(...).