diff --git a/doc/changes/changes_1.5.1.md b/doc/changes/changes_1.5.1.md index 4cf5185..1e94d56 100644 --- a/doc/changes/changes_1.5.1.md +++ b/doc/changes/changes_1.5.1.md @@ -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 diff --git a/src/main/lua/exasol/rls/RlsAdapter.lua b/src/main/lua/exasol/rls/RlsAdapter.lua index ee88fc2..1b380ce 100644 --- a/src/main/lua/exasol/rls/RlsAdapter.lua +++ b/src/main/lua/exasol/rls/RlsAdapter.lua @@ -1,3 +1,5 @@ +local log = require("remotelog") + -- Derive from AbstractVirtualSchemaAdapter local RlsAdapter = {} RlsAdapter.__index = RlsAdapter @@ -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. diff --git a/src/test/java/com/exasol/AbstractLuaVirtualSchemaIT.java b/src/test/java/com/exasol/AbstractLuaVirtualSchemaIT.java index c25debc..98c86f4 100644 --- a/src/test/java/com/exasol/AbstractLuaVirtualSchemaIT.java +++ b/src/test/java/com/exasol/AbstractLuaVirtualSchemaIT.java @@ -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; @@ -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 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 { diff --git a/src/test/java/com/exasol/MetadataReadingIT.java b/src/test/java/com/exasol/MetadataReadingIT.java index fa35a7a..b823a50 100644 --- a/src/test/java/com/exasol/MetadataReadingIT.java +++ b/src/test/java/com/exasol/MetadataReadingIT.java @@ -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");