-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add NO_CREDENTIALS authentication type for GCS
#27106
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
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR explicitly adds a NO_CREDENTIALS authentication mode for GCS by splitting service-account logic from unauthenticated access, refactors credential handling in the service account implementation, tightens configuration validation for different auth types, and updates tests and documentation accordingly. Class diagram for new and updated GCS authentication classesclassDiagram
class GcsAuth {
<<interface>>
+setAuth(StorageOptions.Builder builder, ConnectorIdentity identity)
}
class GcsServiceAccountAuth {
-GoogleCredentials jsonGoogleCredential
+GcsServiceAccountAuth(GcsFileSystemConfig config)
+setAuth(StorageOptions.Builder builder, ConnectorIdentity identity)
}
class NoCredentialsAuth {
+setAuth(StorageOptions.Builder builder, ConnectorIdentity identity)
}
GcsServiceAccountAuth --|> GcsAuth
NoCredentialsAuth --|> GcsAuth
Class diagram for updated GcsFileSystemConfig AuthType enum and validationclassDiagram
class GcsFileSystemConfig {
+AuthType : enum (ACCESS_TOKEN, SERVICE_ACCOUNT, NO_CREDENTIALS)
+isServiceAccountAuthValid() : boolean
+isNonServiceAccountAuthValid() : boolean
}
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
f1cee33 to
3e7dc29
Compare
|
@chenjian2664 Is this a release blocker of 478? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The documentation refers to
NO_CREDENTIALS_AUTHbut the enum value isNO_CREDENTIALS—please align the docs with the actual enum name. - Add a unit test for NoCredentialsAuth to verify that it falls back to NoCredentials when ADC lookup throws an IOException.
- The GcsFileSystemConfig validation tests have a lot of repetitive assertFailsValidation calls—consider parameterizing these cases to reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The documentation refers to `NO_CREDENTIALS_AUTH` but the enum value is `NO_CREDENTIALS`—please align the docs with the actual enum name.
- Add a unit test for NoCredentialsAuth to verify that it falls back to NoCredentials when ADC lookup throws an IOException.
- The GcsFileSystemConfig validation tests have a lot of repetitive assertFailsValidation calls—consider parameterizing these cases to reduce duplication.
## Individual Comments
### Comment 1
<location> `lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemConfig.java:136-142` </location>
<code_context>
assertFailsValidation(
new GcsFileSystemConfig()
.setAuthType(AuthType.ACCESS_TOKEN)
- .setJsonKey("{}}"),
- "authMethodValid",
- "Either gcs.auth-type or gcs.json-key or gcs.json-key-file-path must be set",
+ .setJsonKey("{}"),
+ "nonServiceAuthValid",
+ "Can't set gcs.json-key or gcs.json-key-file-path",
+ AssertTrue.class);
+
+ assertFailsValidation(
</code_context>
<issue_to_address>
**suggestion (testing):** Good coverage of validation for NO_CREDENTIALS, but missing positive test cases.
Please add tests that verify valid NO_CREDENTIALS configurations to ensure positive scenarios are covered.
</issue_to_address>
### Comment 2
<location> `lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsStorageFactory.java:35-37` </location>
<code_context>
GcsFileSystemConfig config = new GcsFileSystemConfig();
- GcsStorageFactory storageFactory = new GcsStorageFactory(config, new GcsServiceAccountAuth(config));
+ GcsStorageFactory storageFactory = new GcsStorageFactory(config, new NoCredentialsAuth());
Credentials actualCredentials;
try (Storage storage = storageFactory.create(ConnectorIdentity.ofUser("test"))) {
</code_context>
<issue_to_address>
**suggestion (testing):** Test for NoCredentialsAuth only covers default config; edge cases are missing.
Add tests for cases where application default credentials are unavailable to confirm NoCredentialsAuth correctly acts as a fallback.
Suggested implementation:
```java
// No credentials options are set
GcsFileSystemConfig config = new GcsFileSystemConfig();
GcsStorageFactory storageFactory = new GcsStorageFactory(config, new NoCredentialsAuth());
Credentials actualCredentials;
try (Storage storage = storageFactory.create(ConnectorIdentity.ofUser("test"))) {
}
@Test
public void testNoCredentialsAuthFallbackWhenNoADC() throws Exception
{
// Simulate environment with no ADC
String originalGoogleApplicationCredentials = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
try {
// Unset the ADC environment variable
if (originalGoogleApplicationCredentials != null) {
System.clearProperty("GOOGLE_APPLICATION_CREDENTIALS");
}
GcsFileSystemConfig config = new GcsFileSystemConfig();
GcsStorageFactory storageFactory = new GcsStorageFactory(config, new NoCredentialsAuth());
try (Storage storage = storageFactory.create(ConnectorIdentity.ofUser("test"))) {
Credentials credentials = storage.getOptions().getCredentials();
// Should be null or a NoCredentials instance, depending on implementation
assertTrue(credentials == null || credentials.getClass().getSimpleName().equals("NoCredentials"), "NoCredentialsAuth should fallback to no credentials");
}
}
finally {
// Restore ADC environment variable
if (originalGoogleApplicationCredentials != null) {
System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", originalGoogleApplicationCredentials);
}
}
}
```
- If your codebase uses a different way to unset or mock environment variables, adjust the test setup accordingly.
- If `NoCredentialsAuth` produces a specific credentials type, update the assertion to check for that type.
- Ensure the test method is annotated with `@Test` and imported from your test framework (e.g., JUnit).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
0e0a502 to
1c8d57a
Compare
|
CI failure is related to this change: |
1c8d57a to
eeee061
Compare
Please replace NO_CREDENTIALS_AUTH with NO_CREDENTIALS in the commit title. |
eeee061 to
f91c5bb
Compare
| * `NO_CREDENTIALS`: allows accessing Google Cloud Storage without providing | ||
| explicit credentials. Attempts to acquire application default credentials from the | ||
| environment, and falls back to no-credentials access if none are available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be behaviour by default ? Why do we need to implement them as a dedicated enum or configure them out ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the NO_CREDENTIALS behavior was implicitly covered by the SERVICE_ACCOUNT auth type, but in practice it was never reachable because the SERVICE_ACCOUNT validator requires either a json-key or json-key-file-path to be configured. By introducing a dedicated NO_CREDENTIALS type, we can now support this scenario explicitly and ensure the validation logic stays consistent, context see #26984
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant if we didn't set the auth type to any value - it should exhibit this behaviour right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the default is SERVICE_ACCOUNT, so I don't want to change it in this pr - just want to introduce a new type.
WDYT @wendigo
f91c5bb to
e72eae8
Compare
lib/trino-filesystem-gcs/src/main/java/io/trino/filesystem/gcs/NoCredentialsAuth.java
Outdated
Show resolved
Hide resolved
e72eae8 to
5a088ac
Compare
5a088ac to
afe4615
Compare
| // This is consistent with the GCP SDK when no credentials are available in the environment | ||
| return null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it as-is now.
58dc340 to
390f406
Compare
Add a dedicated
NO_CREDENTIALStype to explicitly support unauthenticated access.Description
Fixes #26984
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
(x) Release notes are required, with the following suggested text: