Skip to content

Commit

Permalink
Allow all catalog access by default in file-based access control
Browse files Browse the repository at this point in the history
If no catalog rules are defined, allow all catalog access
  • Loading branch information
dain committed Oct 7, 2020
1 parent 66e0952 commit 78025d0
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ ownership of any schema, you can use the following rules:
.. code-block:: json
{
"catalogs": [
{
"allow": true
}
],
"schemas": [
{
"user": "admin",
Expand Down Expand Up @@ -179,11 +174,6 @@ The example below defines the following table access policy:
.. code-block:: json
{
"catalogs": [
{
"allow": true
}
],
"tables": [
{
"user": "admin",
Expand Down Expand Up @@ -299,11 +289,6 @@ and Kerberos authentication:
.. code-block:: json
{
"catalogs": [
{
"allow": true
}
],
"principals": [
{
"principal": "(.*)",
Expand All @@ -325,11 +310,6 @@ name, and allow ``alice`` and ``bob`` to use a group principal named as
.. code-block:: json
{
"catalogs": [
{
"allow": true
}
],
"principals": [
{
"principal": "([^/]+)/?.*@example.net",
Expand Down
5 changes: 0 additions & 5 deletions presto-docs/src/main/sphinx/security/query-access.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"queries": [
{
"user": "admin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"system_information": [
{
"user": "admin",
Expand Down
5 changes: 0 additions & 5 deletions presto-docs/src/main/sphinx/security/user-impersonation.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"impersonation": [
{
"original_user": "alice",
Expand Down
5 changes: 0 additions & 5 deletions presto-main/src/test/resources/catalog_impersonation.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"impersonation": [
{
"original_user": "alice",
Expand Down
5 changes: 0 additions & 5 deletions presto-main/src/test/resources/catalog_principal.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"principals": [
{
"principal": "(.*)",
Expand Down
5 changes: 0 additions & 5 deletions presto-main/src/test/resources/system_information.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"system_information": [
{
"user": "admin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@
import java.util.Set;
import java.util.regex.Pattern;

import static io.prestosql.plugin.base.security.CatalogAccessControlRule.AccessMode.ALL;
import static java.util.Objects.requireNonNull;

public class CatalogAccessControlRule
{
public static final CatalogAccessControlRule ALLOW_ALL = new CatalogAccessControlRule(
ALL,
Optional.empty(),
Optional.empty(),
Optional.empty());

private final AccessMode accessMode;
private final Optional<Pattern> userRegex;
private final Optional<Pattern> groupRegex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,26 @@ private static PrestoException invalidRefreshPeriodException(Map<String, String>
private static SystemAccessControl create(String configFileName)
{
FileBasedSystemAccessControlRules rules = parseJson(Paths.get(configFileName), FileBasedSystemAccessControlRules.class);

ImmutableList.Builder<CatalogAccessControlRule> catalogRulesBuilder = ImmutableList.builder();
catalogRulesBuilder.addAll(rules.getCatalogRules());

// Hack to allow Presto Admin to access the "system" catalog for retrieving server status.
// todo Change userRegex from ".*" to one particular user that Presto Admin will be restricted to run as
catalogRulesBuilder.add(new CatalogAccessControlRule(
ALL,
Optional.of(Pattern.compile(".*")),
Optional.empty(),
Optional.of(Pattern.compile("system"))));

List<CatalogAccessControlRule> catalogAccessControlRules;
if (rules.getCatalogRules().isPresent()) {
ImmutableList.Builder<CatalogAccessControlRule> catalogRulesBuilder = ImmutableList.builder();
catalogRulesBuilder.addAll(rules.getCatalogRules().get());

// Hack to allow Presto Admin to access the "system" catalog for retrieving server status.
// todo Change userRegex from ".*" to one particular user that Presto Admin will be restricted to run as
catalogRulesBuilder.add(new CatalogAccessControlRule(
ALL,
Optional.of(Pattern.compile(".*")),
Optional.empty(),
Optional.of(Pattern.compile("system"))));
catalogAccessControlRules = catalogRulesBuilder.build();
}
else {
// if no rules are defined then all access is allowed
catalogAccessControlRules = ImmutableList.of(CatalogAccessControlRule.ALLOW_ALL);
}
return new FileBasedSystemAccessControl(
catalogRulesBuilder.build(),
catalogAccessControlRules,
rules.getQueryAccessRules(),
rules.getImpersonationRules(),
rules.getPrincipalUserMatchRules(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class FileBasedSystemAccessControlRules
{
private final List<CatalogAccessControlRule> catalogRules;
private final Optional<List<CatalogAccessControlRule>> catalogRules;
private final Optional<List<QueryAccessRule>> queryAccessRules;
private final Optional<List<ImpersonationRule>> impersonationRules;
private final Optional<List<PrincipalUserMatchRule>> principalUserMatchRules;
Expand All @@ -40,7 +40,7 @@ public FileBasedSystemAccessControlRules(
@JsonProperty("schemas") Optional<List<CatalogSchemaAccessControlRule>> schemaAccessControlRules,
@JsonProperty("tables") Optional<List<CatalogTableAccessControlRule>> tableAccessControlRules)
{
this.catalogRules = catalogRules.map(ImmutableList::copyOf).orElse(ImmutableList.of());
this.catalogRules = catalogRules.map(ImmutableList::copyOf);
this.queryAccessRules = queryAccessRules.map(ImmutableList::copyOf);
this.principalUserMatchRules = principalUserMatchRules.map(ImmutableList::copyOf);
this.impersonationRules = impersonationRules.map(ImmutableList::copyOf);
Expand All @@ -49,7 +49,7 @@ public FileBasedSystemAccessControlRules(
this.tableRules = tableAccessControlRules.map(ImmutableList::copyOf);
}

public List<CatalogAccessControlRule> getCatalogRules()
public Optional<List<CatalogAccessControlRule>> getCatalogRules()
{
return catalogRules;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class TestFileBasedSystemAccessControl
private static final SystemSecurityContext CHARLIE = new SystemSecurityContext(charlie, queryId);
private static final SystemSecurityContext ALICE = new SystemSecurityContext(alice, queryId);
private static final SystemSecurityContext JOE = new SystemSecurityContext(joe, queryId);
private static final SystemSecurityContext UNKNOWN = new SystemSecurityContext(Identity.ofUser("some-unknown-user-id"), queryId);

private static final String CREATE_SCHEMA_ACCESS_DENIED_MESSAGE = "Access Denied: Cannot create schema .*";
private static final String DROP_SCHEMA_ACCESS_DENIED_MESSAGE = "Access Denied: Cannot drop schema .*";
Expand All @@ -94,6 +95,45 @@ public class TestFileBasedSystemAccessControl
private static final String GRANT_DELETE_PRIVILEGE_ACCESS_DENIED_MESSAGE = "Access Denied: Cannot grant privilege DELETE on table .*";
private static final String REVOKE_DELETE_PRIVILEGE_ACCESS_DENIED_MESSAGE = "Access Denied: Cannot revoke privilege DELETE on table .*";

@Test
public void testEmptyFile()
{
SystemAccessControl accessControl = newFileBasedSystemAccessControl("empty.json");

accessControl.checkCanCreateSchema(UNKNOWN, new CatalogSchemaName("some-catalog", "unknown"));
accessControl.checkCanDropSchema(UNKNOWN, new CatalogSchemaName("some-catalog", "unknown"));
accessControl.checkCanRenameSchema(UNKNOWN, new CatalogSchemaName("some-catalog", "unknown"), "new_unknown");
accessControl.checkCanSetSchemaAuthorization(UNKNOWN,
new CatalogSchemaName("some-catalog", "unknown"),
new PrestoPrincipal(PrincipalType.ROLE, "some_role"));
accessControl.checkCanShowCreateSchema(UNKNOWN, new CatalogSchemaName("some-catalog", "unknown"));

accessControl.checkCanSelectFromColumns(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"), ImmutableSet.of());
accessControl.checkCanShowColumns(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"));
accessControl.checkCanInsertIntoTable(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"));
accessControl.checkCanDeleteFromTable(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"));

accessControl.checkCanCreateTable(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"));
accessControl.checkCanDropTable(UNKNOWN, new CatalogSchemaTableName("some-catalog", "unknown", "unknown"));
accessControl.checkCanRenameTable(UNKNOWN,
new CatalogSchemaTableName("some-catalog", "unknown", "unknown"),
new CatalogSchemaTableName("some-catalog", "unknown", "new_unknown"));

accessControl.checkCanSetUser(Optional.empty(), "unknown");
accessControl.checkCanSetUser(Optional.of(new KerberosPrincipal("[email protected]")), "unknown");

accessControl.checkCanSetSystemSessionProperty(UNKNOWN, "anything");
accessControl.checkCanSetCatalogSessionProperty(UNKNOWN, "unknown", "anything");

accessControl.checkCanExecuteQuery(UNKNOWN);
accessControl.checkCanViewQueryOwnedBy(UNKNOWN, "anyone");
accessControl.checkCanKillQueryOwnedBy(UNKNOWN, "anyone");

// system information access is denied by default
assertThrows(AccessDeniedException.class, () -> accessControl.checkCanReadSystemInformation(UNKNOWN));
assertThrows(AccessDeniedException.class, () -> accessControl.checkCanWriteSystemInformation(UNKNOWN));
}

@Test
public void testSchemaRulesForCheckCanCreateSchema()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"principals": [
{
"principal": "(.*)",
Expand Down
1 change: 1 addition & 0 deletions presto-plugin-toolkit/src/test/resources/empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"schemas": [
{
"catalog": "unknown",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"tables": [
{
"catalog": "unknown",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"schemas": [
],
"tables": [
Expand Down
5 changes: 0 additions & 5 deletions presto-plugin-toolkit/src/test/resources/query.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"queries": [
{
"user": "admin",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"catalogs": [
{
"allow": true
}
],
"system_information": [
{
"user": "admin",
Expand Down

0 comments on commit 78025d0

Please sign in to comment.