Skip to content

Harden extra files staging in CommonTemplateJvmInitializer - #4676

Merged
shunping merged 3 commits into
GoogleCloudPlatform:mainfrom
shunping:extra-files-staging-perms
Dec 4, 2026
Merged

shunping merged 3 commits into
GoogleCloudPlatform:mainfrom
shunping:extra-files-staging-perms

Conversation

@shunping

@shunping shunping commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Hardens extra files staging in CommonTemplateJvmInitializer. See internal bug for details.

Internal tracking: b/591510517

@shunping shunping added the improvement Making existing code better label Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.34%. Comparing base (32a17dc) to head (1b0d730).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...templates/common/CommonTemplateJvmInitializer.java 66.66% 6 Missing and 2 partials ⚠️
...leport/v2/common/CommonTemplateJvmInitializer.java 66.66% 6 Missing and 2 partials ⚠️

❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4676      +/-   ##
============================================
+ Coverage     60.13%   60.34%   +0.20%     
- Complexity     8845     8973     +128     
============================================
  Files          1123     1126       +3     
  Lines         72848    73008     +160     
  Branches       8855     8881      +26     
============================================
+ Hits          43808    44054     +246     
+ Misses        26105    26021      -84     
+ Partials       2935     2933       -2     
Components Coverage Δ
spanner-templates 86.11% <ø> (+0.59%) ⬆️
spanner-import-export 72.62% <ø> (-0.10%) ⬇️
spanner-live-forward-migration 87.65% <ø> (ø)
spanner-live-reverse-replication 84.19% <ø> (+1.22%) ⬆️
spanner-bulk-migration 88.30% <ø> (+0.01%) ⬆️
gcs-spanner-dv 86.56% <ø> (ø)
Files with missing lines Coverage Δ
...templates/common/CommonTemplateJvmInitializer.java 60.22% <66.66%> (+4.06%) ⬆️
...leport/v2/common/CommonTemplateJvmInitializer.java 61.62% <66.66%> (+3.88%) ⬆️

... and 21 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shunping
shunping marked this pull request as ready for review December 3, 2026 05:41
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request hardens the staging process for extra files in CommonTemplateJvmInitializer. By migrating to NIO.2 file operations and explicitly setting POSIX file permissions, the changes ensure that staged files and their parent directories are restricted to owner-only access, improving the security posture of the template initialization process.

Highlights

  • Enhanced Security Permissions: Implemented owner-only POSIX permissions (rwx------ for directories, rw------- for files) when staging extra files to ensure secure access.
  • Robust File Handling: Updated the staging logic to correctly overwrite existing files and handle directory creation using modern NIO.2 APIs.
  • Improved Test Coverage: Added new test cases to verify file overwriting behavior and the application of correct POSIX permissions on supported file systems.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request enhances security in CommonTemplateJvmInitializer (for both v1 and v2) by restricting directory and file permissions to owner-only when POSIX is supported, and updates SecretManagerServiceClient usage to a try-with-resources block. The review feedback correctly identifies potential Time-of-Check to Time-of-Use (TOCTOU) race conditions and temporary windows of loose permissions during directory and file creation. It is recommended to create these paths atomically with POSIX attributes directly using Files.createDirectories and Files.createFile (catching FileAlreadyExistsException if the file already exists) to ensure robust security.

@shunping

shunping commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

R: @derrickaw

@shunping
shunping requested a review from derrickaw December 4, 2026 01:37
@shunping
shunping merged commit 81c5782 into GoogleCloudPlatform:main Dec 4, 2026
54 of 55 checks passed
@shunping
shunping deleted the extra-files-staging-perms branch December 4, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Making existing code better size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants