Skip to content

Commit

Permalink
#136: Fixed switching the source schema (#143)
Browse files Browse the repository at this point in the history
* #136: Fixed source schema switching.

Co-authored-by: Christoph Pirkl <[email protected]>
  • Loading branch information
redcatbear and kaklakariada authored Oct 26, 2023
1 parent 3b63e03 commit 3e76939
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
7 changes: 5 additions & 2 deletions doc/changes/changes_1.5.1.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# Exasol Row Level Security (Lua) 1.5.1, released 2023-10-25
# Exasol Row Level Security (Lua) 1.5.1, released 2023-10-26

Code name: Fix CVE-2023-42503
Code name: Fix CVE-2023-42503 and source schema switching

## Summary

In this release we updated the test dependency `exasol-testcontainers` to version 6.6.2 in order to update the transitive dependency `org.apache.commons:commons-compress` to 1.24.0. This fixes CVE-2023-42505.

We also fixed a bug that prevented users from switching the source schema with `ALTER VIRTUAL SCHEMA ... SET SCHEMA_NAME=`.

## Features

* #136: Fixed source schema switching
* #140: Updated test dependency to fix CVE-2023-42505

## Dependency Updates
Expand Down
17 changes: 13 additions & 4 deletions src/main/lua/exasol/rls/RlsAdapter.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local log = require("remotelog")

-- Derive from AbstractVirtualSchemaAdapter
local RlsAdapter = {}
RlsAdapter.__index = RlsAdapter
Expand Down Expand Up @@ -63,12 +65,19 @@ function RlsAdapter:refresh(request, properties)
end

--- Alter the schema properties.
-- This request provides two sets of user-defined properties. The old ones (i.e. the ones that where set before this
-- request) and the properties that the user changed.
-- @param request virtual schema request
-- @param properties user-defined properties
-- @param old_properties old user-defined properties
-- @param new_properties new user-defined properties
-- @return response containing the metadata for the virtual schema like table and column structure
function RlsAdapter:set_properties(request, properties)
properties:validate()
return {type = "setProperties", schemaMetadata = self:_handle_schema_scanning_request(request, properties)}
function RlsAdapter:set_properties(request, old_properties, new_properties)
log.debug("Old properties " .. tostring(old_properties))
log.debug("New properties " .. tostring(new_properties))
local merged_properties = old_properties:merge(new_properties)
log.debug("Merged properties " .. tostring(merged_properties))
merged_properties:validate()
return {type = "setProperties", schemaMetadata = self:_handle_schema_scanning_request(request, merged_properties)}
end

--- Rewrite a pushed down query.
Expand Down
13 changes: 12 additions & 1 deletion src/test/java/com/exasol/AbstractLuaVirtualSchemaIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract class AbstractLuaVirtualSchemaIT {
+ " end\n" //
+ " end\n" //
+ ")\n\n";
public static final String DEFAULT_LOG_PORT = "3000";
protected static Connection connection;
protected static ExasolObjectFactory factory;
private static ExasolSchema scriptSchema;
Expand Down Expand Up @@ -85,7 +86,17 @@ protected VirtualSchema createVirtualSchema(final Schema sourceSchema, final Map
}

protected VirtualSchema createVirtualSchema(final Schema sourceSchema) {
return createVirtualSchema(sourceSchema, Collections.emptyMap());
return createVirtualSchema(sourceSchema, getDebugProperties());
}

private Map<String, String> getDebugProperties() {
final String debugHost = System.getProperty("com.exasol.log.host");
if(debugHost == null) {
return Collections.emptyMap();
} else {
final String debugAddress = debugHost + ":" + System.getProperty("com.exasol.log.port", DEFAULT_LOG_PORT);
return Map.of("DEBUG_ADDRESS", debugAddress, "LOG_LEVEL", "TRACE");
}
}

protected AdapterScript createAdapterScript(final String prefix) throws IOException {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/exasol/MetadataReadingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,30 @@ private void execute(final String sql) throws SQLException {
}
}

@Test
void testChangeSourceSchema() {
final Schema sourceSchemaBefore = createSchema("SCHEMA_SWITCH");
final Table tableBefore = sourceSchemaBefore.createTable("T_BEFORE", "I", "DECIMAL(18,0)");
final Schema sourceSchemaAfter = createSchema("SCHEMA_AFTER_SWITCH");
final Table tableAfter = sourceSchemaAfter.createTable("T_AFTER", "D", "DATE");
final VirtualSchema virtualSchema = createVirtualSchema(sourceSchemaBefore);
final User user = createUserWithVirtualSchemaAccess("USER_FOR_SCHEMA_SWITCH", virtualSchema);
assertVirtualTableStructure(tableBefore, user, expectRows("I", "DECIMAL(18,0)"));
replaceSourceSchema(virtualSchema, sourceSchemaAfter);
assertRlsQueryWithUser("/*snapshot execution*/DESCRIBE SCHEMA_SWITCH_RLS.T_AFTER", user,
expectRows("D", "DATE"));
}

private void replaceSourceSchema(final VirtualSchema virtualSchema, final Schema sourceSchema) {
final String sql = "ALTER VIRTUAL SCHEMA " + virtualSchema.getFullyQualifiedName() + " SET SCHEMA_NAME='" +
sourceSchema.getName() + "'";
try {
execute(sql);
} catch (final SQLException exception) {
throw new AssertionError("Unable to replace source schema using query '" + sql + "'", exception);
}
}

@Test
void testProtectTableAfterRefresh() throws SQLException {
final Schema sourceSchema = createSchema("SCHEMA_FOR_PROTECT_AFTER_REFRESH");
Expand Down

0 comments on commit 3e76939

Please sign in to comment.