Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not source system- and user- Git settings / Fix GitMirrorAuthTest #816

Merged
merged 3 commits into from
Mar 8, 2023

Conversation

trustin
Copy link
Member

@trustin trustin commented Mar 2, 2023

Motivation:

We can't test Git-over-HTTPS authentication with GitMirrorAuthTest because of the following:

  • JGit silently sources the custom configurations, breaking our expected behaviors:
    • ~/.gitconfig
    • ~/.config/jgit
    • ~/.jgitconfig
    • /etc/gitconfig
  • It's not convenient to pass Git username and password via system properties.

Modifications:

  • Added IsolatedSystemReader that prevents reading the system- and user- Git settings so that Central Dogma doesn't behave differently between environments.
  • Revamped GitMirrorAuthTest so that it always uses github.com/line/centraldogma-authtest.git as its test repository.
    • The Git-over-SSH test now always runs as a part of the build.
    • The Git-over-HTTPS test requires sensitive information, so it still has to run manually, although we could at least run it as a part of GitHub action (but not in a PR build).
  • Updated GitMirrorAuthTest so that it pulls GitHub username and password via environment variables rather than system properties.

Result:

  • Central Dogma doesn't behave differently between environments.
  • GitMirrorAuthTest now always runs the Git-over-SSH test.
  • GitMirrorAuthTest now uses environment variables rather than JVM system properties to retrieve GitHub username and password.

@trustin trustin added the defect label Mar 2, 2023
@trustin trustin added this to the 0.60.2 milestone Mar 2, 2023
Motivation:

We can't test Git-over-HTTPS authentication with `GitMirrorAuthTest` because of the following:

- JGit silently sources the custom configurations, breaking our expected behaviors:
  - `~/.gitconfig`
  - `~/.config/jgit`
  - `~/.jgitconfig`
  - `/etc/gitconfig`
- It's not convenient to pass Git username and password via system properties.

Modifications:

- Added `IsolatedSystemReader` that prevents reading the system- and user- Git settings so that Central Dogma doesn't behave differently between environments.
- Revamped `GitMirrorAuthTest` so that it always uses `github.com/line/centraldogma-authtest.git` as its test repository.
  - The Git-over-SSH test now always runs as a part of the build.
  - The Git-over-HTTPS test requires sensitive information, so it still has to run manually, although we could at least run it as a part of GitHub action (but not in a PR build).
- Updated `GitMirrorAuthTest` so that it pulls GitHub username and password via environment variables rather than system properties.

Result:

- Central Dogma doesn't behave differently between environments.
- `GitMirrorAuthTest` now always runs the Git-over-SSH test.
- `GitMirrorAuthTest` now uses environment variables rather than JVM system properties to retrieve GitHub username and password.
Copy link
Contributor

@taiga-nada taiga-nada left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you.

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Patch coverage: 95.00% and project coverage change: +0.08 🎉

Comparison is base (79221af) 65.50% compared to head (deaf2f5) 65.59%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #816      +/-   ##
============================================
+ Coverage     65.50%   65.59%   +0.08%     
- Complexity     3294     3308      +14     
============================================
  Files           353      354       +1     
  Lines         13796    13816      +20     
  Branches       1492     1492              
============================================
+ Hits           9037     9062      +25     
+ Misses         3911     3908       -3     
+ Partials        848      846       -2     
Impacted Files Coverage Δ
...raldogma/server/internal/IsolatedSystemReader.java 94.44% <94.44%> (ø)
...ntraldogma/server/internal/mirror/GitWithAuth.java 64.04% <100.00%> (+0.40%) ⬆️
...internal/storage/repository/git/GitRepository.java 76.31% <100.00%> (+0.02%) ⬆️
...centraldogma/server/internal/api/WatchService.java 76.27% <0.00%> (-3.39%) ⬇️
...centraldogma/server/internal/mirror/GitMirror.java 80.88% <0.00%> (+0.29%) ⬆️
...r/internal/admin/auth/FileBasedSessionManager.java 77.69% <0.00%> (+1.43%) ⬆️
.../linecorp/centraldogma/client/AbstractWatcher.java 80.00% <0.00%> (+2.66%) ⬆️
...ient/armeria/legacy/LegacyCentralDogmaBuilder.java 85.18% <0.00%> (+3.70%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left two super minor nits. Thanks @trustin 👍 🙇 👍

*/
private static final String GIT_PASSPHRASE = System.getProperty("git.passphrase");
private static final String GITHUB_PASSWORD =
System.getenv("GITHUB_CD_AUTHTEST_PASSWORD");
Copy link
Contributor

Choose a reason for hiding this comment

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

As-is is also fine, but I'm wondering why we don't fallback to user.password for symmetry

Suggested change
System.getenv("GITHUB_CD_AUTHTEST_PASSWORD");
System.getenv("GITHUB_CD_AUTHTEST_PASSWORD"),
System.getProperty("user.password"))

Copy link
Member Author

Choose a reason for hiding this comment

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

user.name is JDK standard property which is always given, whereas user.password is not. 😉 Let me leave it as it is.

@@ -0,0 +1,20 @@
-----BEGIN EC PRIVATE KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

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

Question) Just to make sure, is this a read-only deploy key?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's read-only.

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @trustin! 🙇‍♂️

Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

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

Much simplified. Thanks!

@trustin trustin added this pull request to the merge queue Mar 8, 2023
Merged via the queue into line:master with commit 1188635 Mar 8, 2023
@trustin trustin deleted the isolated_env branch March 8, 2023 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants