Repository navigation
Reject reserved Hadoop keys in GCS fileSystemProperties #1629
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
Open
akkaur
wants to merge
1
commit into
develop
Choose a base branch
from
restrict-reserved-fs-properties
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/test/java/io/cdap/plugin/gcp/common/GCPUtilsFileSystemPropertiesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /* | ||
| * Copyright © 2026 Cask Data, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy of | ||
| * the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
|
|
||
| package io.cdap.plugin.gcp.common; | ||
|
|
||
| import io.cdap.cdap.etl.api.validation.CauseAttributes; | ||
| import io.cdap.cdap.etl.api.validation.ValidationFailure; | ||
| import io.cdap.cdap.etl.mock.validation.MockFailureCollector; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Tests for the handling of reserved keys in user-supplied file system properties. | ||
| */ | ||
| public class GCPUtilsFileSystemPropertiesTest { | ||
|
|
||
| private static final String CONFIG_PROPERTY = "fileSystemProperties"; | ||
|
|
||
| private static final List<String> RESERVED_KEYS = Arrays.asList( | ||
| "fs.gs.storage.root.url", | ||
| "fs.gs.storage.service.path", | ||
| "fs.gs.token.server.url", | ||
| "fs.gs.http.transport.type", | ||
| "fs.gs.enable.service.account.auth", | ||
| "fs.gs.service.account.auth.email", | ||
| "fs.gs.service.account.auth.keyfile", | ||
| "fs.gs.impl", | ||
| "fs.AbstractFileSystem.gs.impl", | ||
| "fs.gs.proxy.address", | ||
| "fs.gs.proxy.username", | ||
| "fs.gs.proxy.password", | ||
| "fs.gs.auth.access.token.provider.impl", | ||
| "fs.gs.auth.impersonation.service.account", | ||
| "fs.gs.auth.service.account.json.keyfile", | ||
| "fs.gs.auth.service.account.private.key", | ||
| "fs.gs.auth.client.secret", | ||
| "fs.gs.auth.refresh.token", | ||
| "fs.gs.authorization.handler.impl", | ||
| "fs.gs.delegation.token.binding", | ||
| "google.cloud.token.server.url", | ||
| "google.cloud.auth.access.token.provider.impl", | ||
| "google.cloud.proxy.address", | ||
| "cdap.auth.service.account", | ||
| "cdap.auth.service.account.type", | ||
| "cdap.auth.service.account.scopes"); | ||
|
|
||
| private static final List<String> ALLOWED_KEYS = Arrays.asList( | ||
| "fs.gs.inputstream.fadvise", | ||
| "fs.gs.outputstream.upload.chunk.size", | ||
| "fs.gs.block.size", | ||
| "fs.gs.http.max.retry", | ||
| "fs.gs.http.connect-timeout", | ||
| "fs.gs.status.parallel.enable", | ||
| "fs.gs.project.id", | ||
| "fs.gs.system.bucket", | ||
| "mapreduce.input.fileinputformat.split.minsize", | ||
| "avro.mo.config.namedOutput"); | ||
|
|
||
| @Test | ||
| public void testReservedKeysAreDetected() { | ||
| for (String key : RESERVED_KEYS) { | ||
| Assert.assertTrue(key + " should be reserved", GCPUtils.isReservedFileSystemProperty(key)); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testAllowedKeysAreNotDetected() { | ||
| for (String key : ALLOWED_KEYS) { | ||
| Assert.assertFalse(key + " should not be reserved", GCPUtils.isReservedFileSystemProperty(key)); | ||
| } | ||
| Assert.assertFalse(GCPUtils.isReservedFileSystemProperty(null)); | ||
| Assert.assertFalse(GCPUtils.isReservedFileSystemProperty("")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSurroundingWhitespaceDoesNotBypassReservedKeys() { | ||
| Assert.assertTrue(GCPUtils.isReservedFileSystemProperty(" fs.gs.storage.root.url ")); | ||
| Assert.assertTrue(GCPUtils.isReservedFileSystemProperty("\tfs.gs.token.server.url")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateReportsOneFailurePerReservedKey() { | ||
| Map<String, String> properties = new HashMap<>(); | ||
| properties.put("fs.gs.storage.root.url", "https://attacker.example.com/"); | ||
| properties.put("fs.gs.token.server.url", "https://attacker.example.com/token"); | ||
| properties.put("fs.gs.inputstream.fadvise", "AUTO"); | ||
|
|
||
| MockFailureCollector collector = new MockFailureCollector("gcs"); | ||
| GCPUtils.validateFileSystemProperties(properties, CONFIG_PROPERTY, collector); | ||
|
|
||
| List<ValidationFailure> failures = collector.getValidationFailures(); | ||
| Assert.assertEquals(2, failures.size()); | ||
| for (ValidationFailure failure : failures) { | ||
| Assert.assertEquals(1, failure.getCauses().size()); | ||
| Assert.assertEquals(CONFIG_PROPERTY, failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG)); | ||
| Assert.assertTrue(failure.getMessage().contains("is reserved and cannot be overridden")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateAcceptsAllowedKeys() { | ||
| Map<String, String> properties = new HashMap<>(); | ||
| for (String key : ALLOWED_KEYS) { | ||
| properties.put(key, "value"); | ||
| } | ||
| MockFailureCollector collector = new MockFailureCollector("gcs"); | ||
| GCPUtils.validateFileSystemProperties(properties, CONFIG_PROPERTY, collector); | ||
| Assert.assertEquals(0, collector.getValidationFailures().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateAcceptsNullAndEmptyProperties() { | ||
| MockFailureCollector collector = new MockFailureCollector("gcs"); | ||
| GCPUtils.validateFileSystemProperties(null, CONFIG_PROPERTY, collector); | ||
| GCPUtils.validateFileSystemProperties(new HashMap<>(), CONFIG_PROPERTY, collector); | ||
| Assert.assertEquals(0, collector.getValidationFailures().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetFileSystemPropertiesDropsReservedUserKeys() { | ||
| Map<String, String> userProperties = new HashMap<>(); | ||
| userProperties.put("fs.gs.storage.root.url", "https://attacker.example.com/"); | ||
| userProperties.put("google.cloud.token.server.url", "https://attacker.example.com/token"); | ||
| userProperties.put("cdap.auth.service.account", "{\"type\":\"external_account\"}"); | ||
| userProperties.put("fs.gs.auth.access.token.provider.impl", "com.example.EvilProvider"); | ||
| userProperties.put("fs.gs.inputstream.fadvise", "AUTO"); | ||
|
|
||
| GCPConnectorConfig connection = new GCPConnectorConfig("my-project", "filePath", "auto-detect", null); | ||
| Map<String, String> properties = GCPUtils.getFileSystemProperties(connection, "gs://bucket/path", | ||
| userProperties); | ||
|
|
||
| Assert.assertFalse(properties.containsKey("fs.gs.storage.root.url")); | ||
| Assert.assertFalse(properties.containsKey("google.cloud.token.server.url")); | ||
| Assert.assertFalse(properties.containsKey("cdap.auth.service.account")); | ||
| // the access token provider is always the one set by the plugin | ||
| Assert.assertEquals("io.cdap.plugin.gcp.gcs.ServiceAccountAccessTokenProvider", | ||
| properties.get("fs.gs.auth.access.token.provider.impl")); | ||
| Assert.assertEquals("AUTO", properties.get("fs.gs.inputstream.fadvise")); | ||
| Assert.assertEquals("my-project", properties.get("fs.gs.project.id")); | ||
| Assert.assertEquals("bucket", properties.get("fs.gs.system.bucket")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.