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

Allow fetching file based access provider rules via http(s) url #14008

Merged
merged 4 commits into from
Dec 27, 2022

Conversation

arkadiuszbalcerek
Copy link
Contributor

@arkadiuszbalcerek arkadiuszbalcerek commented Sep 6, 2022

Description

This is actually replacement for #11491
The changes are integrated with the newest trino code
New fork created as we don't have write permission to https://github.com/clemensvonschwerin/presto/tree/file-system-based-access-provider-via-rest
Would like to move it forward and finally get merged to official trino codebase

Is this change a fix, improvement, new feature, refactoring, or other?

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

How would you describe this change to a non-technical end user or system administrator?

Related issues, pull requests, and links

Documentation

( ) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
(x) Release notes entries required with the following suggested text:

# Security
* Allow fetching access control rules via http(s) url

@cla-bot
Copy link

cla-bot bot commented Sep 6, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@arkadiuszbalcerek
Copy link
Contributor Author

arkadiuszbalcerek commented Sep 6, 2022

Hi @kokosing,
This PR is replacement for #11491
It is integrated with the newest trino and some adjustments are done. Could you please trigger the checks and review it?

@github-actions github-actions bot added the docs label Sep 6, 2022
@kokosing
Copy link
Member

kokosing commented Sep 6, 2022

@Praveen2112 Would you like to do a review?

@Praveen2112
Copy link
Member

Will take a look at it

@cla-bot
Copy link

cla-bot bot commented Sep 7, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@arkadiuszbalcerek
Copy link
Contributor Author

Hi @kokosing @Praveen2112 I fixed some tests so all checks except plugin/trino-elasticsearch succeeded. plugin/trino-elasticsearch got cancelled (due to exceeding the timeout I guess) but I don't think it is related to changes in this PR (previous run succeeded). Please review and give us some feedback what else should be improved to get this merged

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

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

Instead of reusing FileBasedAccessControl - can we have a generic Connector/System Access Control based on JsonRules and have different ways of injecting rules from a file or from a URI (with a specific start point).

lib/trino-plugin-toolkit/pom.xml Outdated Show resolved Hide resolved
@@ -106,12 +105,12 @@
private final List<SessionPropertyAccessControlRule> sessionPropertyRules;
private final Set<AnySchemaPermissionsRule> anySchemaPermissionsRules;

public FileBasedAccessControl(CatalogName catalogName, File configFile)
public FileBasedAccessControl(CatalogName catalogName, Supplier<AccessControlRules> rulesProvider)
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a different AccessControl implementation if they are fetched from REST APIs or maybe we could have a generic JsonBasedAccessControl and rules can be injected from a file or a remote hosted file or using some endpoints. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

@cla-bot
Copy link

cla-bot bot commented Sep 12, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@github-actions github-actions bot added jdbc Relates to Trino JDBC driver release-notes tests:hive labels Sep 12, 2022
@cla-bot
Copy link

cla-bot bot commented Sep 12, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

1 similar comment
@cla-bot
Copy link

cla-bot bot commented Sep 12, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

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

Can you squash the commits. We could have one for preparatory changes and one with the actual set of changes.

@@ -104,12 +103,12 @@
private final List<SessionPropertyAccessControlRule> sessionPropertyRules;
private final Set<AnySchemaPermissionsRule> anySchemaPermissionsRules;

public FileBasedAccessControl(CatalogName catalogName, File configFile)
public FileBasedAccessControl(CatalogName catalogName, Supplier<AccessControlRules> rulesProvider)
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename it as JsonAccessControl or something ?

cc: @kokosing Any good names we can use here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean rename the file/class? We have a few classes starting with FileBasedAccessControl? Do you want to rename all of them?

Copy link
Member

Choose a reason for hiding this comment

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

Since we inject the AccessControlRules I guess FileBasedAccessControl makes less sense here. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored - renamed to RulesBasedAccessControl

{
this.catalogName = catalogName.toString();

AccessControlRules rules = parseJson(configFile.toPath(), AccessControlRules.class);
checkArgument(!rules.hasRoleRules(), "File connector access control does not support role rules: %s", configFile);
AccessControlRules rules = rulesProvider.get();
Copy link
Member

Choose a reason for hiding this comment

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

requireNonNull check for supplier ? Any specific reason for supplier ? Can we inject AccessControlRules directly ?

Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

}

@Config(SECURITY_CONFIG_FILE)
public FileBasedAccessControlConfig setConfigFile(File configFile)
public FileBasedAccessControlConfig setConfigFilePath(String configFilePath)
Copy link
Member

Choose a reason for hiding this comment

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

Can we have it as a part of preparatory commit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I squashed to two commits. Unfortunately this one went to the second one. I won't be able now to extract it and squash other way. If this is a problem I can create another PR with this one as initial commit

@@ -56,4 +69,9 @@ public FileBasedAccessControlConfig setRefreshPeriod(Duration refreshPeriod)
this.refreshPeriod = refreshPeriod;
return this;
}

public boolean isRest()
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking if it a file or a REST url ? Can we have have some enum which could be configured so we could have dedicated set of properties for each type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

@cla-bot
Copy link

cla-bot bot commented Sep 13, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link

cla-bot bot commented Sep 13, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link

cla-bot bot commented Sep 13, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@AdrianSkierniewski
Copy link

Hi Guys,

The work on this PR has been dragging on for several months. We already invested quite some time and resources to constantly rebase. We're following the same pattern that it's already used in other places when you can configure refresh via HTTP request. An example bellow:

The configuration JSON can either be retrieved from a file or REST-endpoint specified via hive.s3.security-mapping.config-file.

https://trino.io/docs/current/connector/hive-s3.html?highlight=iam#s3-security-mapping

We're really grateful Trino community for a such amazing piece of software, so please don't get me wrong. It feels really unproductive on our side to constantly invest more time on the PR and engage in endless discussions.

@Praveen2112 @kokosing could you help us with merging this one?

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Thanks for working on this and we really appreciate your effort this PR, we do have a minor concerns which we have specified. Do let us know if there are any issues in applying them.

<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-client</artifactId>
<exclusions>
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to exclude them ? Can we provide a comment here - does the versions conflict ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

io.airlift.node is needed only for tests. If not excluded here dependency-scope-maven-plugin will complain

Copy link
Member

Choose a reason for hiding this comment

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

Where do we use them in tests ?

Copy link
Member

Choose a reason for hiding this comment

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

Instead of excluding this - Can we add node as a rutime dependency


        <!-- used by tests but also needed transitively -->
        <dependency>
            <groupId>io.airlift</groupId>
            <artifactId>node</artifactId>
            <scope>runtime</scope>
        </dependency>
        

@@ -104,12 +103,12 @@
private final List<SessionPropertyAccessControlRule> sessionPropertyRules;
private final Set<AnySchemaPermissionsRule> anySchemaPermissionsRules;

public FileBasedAccessControl(CatalogName catalogName, File configFile)
public FileBasedAccessControl(CatalogName catalogName, Supplier<AccessControlRules> rulesProvider)
Copy link
Member

Choose a reason for hiding this comment

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

Since we inject the AccessControlRules I guess FileBasedAccessControl makes less sense here. WDYT ?

{
this.catalogName = catalogName.toString();

AccessControlRules rules = parseJson(configFile.toPath(), AccessControlRules.class);
checkArgument(!rules.hasRoleRules(), "File connector access control does not support role rules: %s", configFile);
AccessControlRules rules = rulesProvider.get();
Copy link
Member

Choose a reason for hiding this comment

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

ditto

.in(Scopes.SINGLETON);
httpClientBinder(innerBinder).bindHttpClient("security-http-client", ForAccessControlRules.class)
.withConfigDefaults(config -> config
.setRequestTimeout(Duration.succinctDuration(10, TimeUnit.SECONDS))
Copy link
Member

@Praveen2112 Praveen2112 Oct 24, 2022

Choose a reason for hiding this comment

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

Any specific reason for setting this configuration to 10s. We could also cofigure them via http-client config if required ?

Mentioned here - #6210 (comment)

{
}

public static <R> R parseJSONString(String jsonString, String jsonPointer, Class<R> clazz)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a static method, can we have something like a parser (S3SecurityMappingsParser)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored - this util doesn't exist any more

config -> !config.isRest(),
innerBinder -> {
innerBinder.bind(new TypeLiteral<Supplier<AccessControlRules>>() {})
.toProvider(() -> new LocalFileAccessControlRulesProvider<>(configuration, AccessControlRules.class))
Copy link
Member

Choose a reason for hiding this comment

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

Can we inject this Supplier instead of specifying a Provider implementation ?

Copy link
Member

Choose a reason for hiding this comment

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

In this case we don't have to build the configuration here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

Comment on lines 90 to 73
try {
refreshPeriod = config.getRefreshPeriod();
}
catch (IllegalArgumentException e) {
throw invalidRefreshPeriodException(config, configFilePath);
}
if (refreshPeriod.toMillis() == 0) {
throw invalidRefreshPeriodException(config, configFilePath);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this validation part of the config like public Optional<@MinDuration("1ms") Duration>.

Copy link
Member

Choose a reason for hiding this comment

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

We can use Optional too. Maybe it could go as a preparatory commit. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored - actually it was dead code - refreshperiod validation are based on annotations and included in config class

public RulesProvider(FileBasedAccessControlConfig config, Class<R> clazz)
{
this.clazz = requireNonNull(clazz);
this.jsonPointer = requireNonNull(config.getJsonPointer());
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this jsonPointer for LocalFileBasedImpl since in the docs it has been restricted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

jsonPointer is only for rest based config now

@cla-bot
Copy link

cla-bot bot commented Nov 2, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot
Copy link

cla-bot bot commented Nov 3, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@Praveen2112
Copy link
Member

Can you please squash the commits.

@cla-bot
Copy link

cla-bot bot commented Nov 3, 2022

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@arkadiuszbalcerek
Copy link
Contributor Author

@Praveen2112 please trigger the checks. Actually the code was refactored quite a lot so most of the comment shouldn't be relevant any more. Please review.

@arkadiuszbalcerek arkadiuszbalcerek force-pushed the mck branch 3 times, most recently from 4f6ed63 to 4d522da Compare December 19, 2022 15:04
@arkadiuszbalcerek
Copy link
Contributor Author

@Praveen2112 I applied the comments. Please review

.initialize();

lifeCycleManager = injector.getInstance(LifeCycleManager.class);
baseUri = injector.getInstance(io.airlift.http.server.testing.TestingHttpServer.class).getBaseUrl();
Copy link
Member

Choose a reason for hiding this comment

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

Instead of getting instance of TestingHttpServer - can we fetch HttpServerInfo and get the Url based on it ? So we don't specify a class name with package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

.setRequestTimeout(Duration.succinctDuration(10, TimeUnit.SECONDS))
.setSelectorCount(1)
.setMinThreads(1));
binder.bind(AccessControlRulesRestExtractor.class);
Copy link
Member

Choose a reason for hiding this comment

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

We need to specify the scope as Singleton

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return () -> parseJson(readFile(configFile), config.getJsonPointer(), FileBasedSystemAccessControlRules.class);
}

private String readFile(File configFile)
Copy link
Member

Choose a reason for hiding this comment

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

JsonUtils has a method to read input from file - can we use that implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

configBinder(binder).bindConfig(FileBasedAccessControlConfig.class);
install(conditionalModule(
FileBasedAccessControlConfig.class,
systemAccessControlConfig -> systemAccessControlConfig.isHttp(),
Copy link
Member

Choose a reason for hiding this comment

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

Can we use lambda here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

{
configBinder(binder).bindConfig(FileBasedAccessControlConfig.class);
install(conditionalModule(
FileBasedAccessControlConfig.class,
accessControlConfig -> accessControlConfig.isHttp(),
Copy link
Member

Choose a reason for hiding this comment

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

We can use lambda here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


public boolean isHttp()
{
if (configFile.startsWith("https://") || configFile.startsWith("http://")) {
Copy link
Member

Choose a reason for hiding this comment

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

can we something like this - return configFile.startsWith("https://") || configFile.startsWith("http://"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@AssertTrue(message = "Config file does not exist.")
public boolean isConfigFileValid()
{
if (Objects.nonNull(configFile) && !isHttp() && !new File(configFile).exists()) {
Copy link
Member

Choose a reason for hiding this comment

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

We don't have to add non-null check here - Can we move it to the end of class ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm not sure if we don't need non-null check here. We have NotNull validation for configFile field. You shouldn't relay on order of validations, If I remove this non-null check we might (and will in this case) end up with NPE instead of NotNull validation failure

Copy link
Member

Choose a reason for hiding this comment

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

Custom validation happens after the getter/setter validation happens - so NotNull will be checked already. I think this non-null check would be redundant

return accessControlRulesProvider;
}

private String readFile(File configFile)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

FileBasedAccessControlConfig fileBasedAccessControlConfig = injector.getInstance(FileBasedAccessControlConfig.class);
String configFileName = fileBasedAccessControlConfig.getConfigFile().getPath();
String configFile = fileBasedAccessControlConfig.getConfigFile();
Supplier<FileBasedSystemAccessControlRules> rulesProvider = injector.getInstance(Key.get(new TypeLiteral<Supplier<FileBasedSystemAccessControlRules>>() {}));
Copy link
Member

Choose a reason for hiding this comment

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

Can make it to be in-sync with FileBasedConnectorAccessControl implementation - Like we can we have a prep commit - which would introduce this a new FileBasedSystemAccessControlModule() which would inject a SystemAccessControl (wrapped with refresh option if required) and here we could configure the injector - to get an instance of the SystemAccessControl - this would make the design uniform and simple. WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added prep commit with this refactoring before applying any new changes

@arkadiuszbalcerek arkadiuszbalcerek force-pushed the mck branch 2 times, most recently from 8df2a0f to 31c9159 Compare December 20, 2022 18:22
@arkadiuszbalcerek
Copy link
Contributor Author

Hi @Praveen2112 I applied the comments. please review

Copy link
Member

@Praveen2112 Praveen2112 left a comment

Choose a reason for hiding this comment

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

Minor changes

}

@Inject
@Provides
Copy link
Member

Choose a reason for hiding this comment

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

@singleton annotation is missing.

@@ -15,6 +15,7 @@

import com.google.common.collect.ImmutableMap;
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename the commit message as Extract new module for FileBasedSystemAccessControl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -819,23 +820,23 @@ public void testRefreshing()
public void testAllowModeIsRequired()
{
assertThatThrownBy(() -> newAccessControlManager(createTestTransactionManager(), "catalog_allow_unset.json"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageStartingWith("Invalid JSON file");
.isInstanceOf(ProvisionException.class)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this change in this commit ?

@@ -0,0 +1,714 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Try to keep the commit message less than 75 character length.

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class AccessControlRulesRestExtractor
Copy link
Member

Choose a reason for hiding this comment

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

nit : Can we rename it as RestBasedAccessControlRulesProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HttpBasedAccessControlRulesProvider? to stick to the convention and avoid rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public <R> R extract(Class<R> clazz)
{
String body = getRawJsonString();
return parseJson(body, jsonPointer, clazz);
Copy link
Member

Choose a reason for hiding this comment

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

Can we inline body

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@AssertTrue(message = "Config file does not exist.")
public boolean isConfigFileValid()
{
if (Objects.nonNull(configFile) && !isHttp() && !new File(configFile).exists()) {
Copy link
Member

Choose a reason for hiding this comment

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

Custom validation happens after the getter/setter validation happens - so NotNull will be checked already. I think this non-null check would be redundant


public class FileBasedAccessControlConfig
{
public static final String SECURITY_CONFIG_FILE = "security.config-file";
public static final String SECURITY_REFRESH_PERIOD = "security.refresh-period";
public static final String SECURITY_JSON_POINTER = "security.json-pointer";
Copy link
Member

Choose a reason for hiding this comment

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

Can we inline this string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

.setConfigFile(securityConfigUrl)
.setRefreshPeriod(Duration.valueOf("1ms"))
.setJsonPointer("/data"));
}
Copy link
Member

Choose a reason for hiding this comment

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

test for non-existing file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was already added in testValidationWithLocalFile

@arkadiuszbalcerek
Copy link
Contributor Author

@Praveen2112 Regarding this one #14008 (comment) we need to change the test in this commit. After refactoring FileBasedSystemAccessControl they failed (different exception thrown)

@arkadiuszbalcerek
Copy link
Contributor Author

@Praveen2112 comments applied

@arkadiuszbalcerek
Copy link
Contributor Author

Hi @mosabua could you please have a look at docs change?

@Praveen2112
Copy link
Member

Merged !! Thanks for working on this

@github-actions github-actions bot added this to the 404 milestone Dec 27, 2022
@arkadiuszbalcerek
Copy link
Contributor Author

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed docs jdbc Relates to Trino JDBC driver release-notes
Development

Successfully merging this pull request may close these issues.

8 participants