=============== LIBRARY RULES =============== From library maintainers: - Maven coordinate: com.housedevinci:gdpr-shredding-spring-boot-starter, current version 0.2.0. - This is pseudonymisation with key destruction, never unqualified erasure; whether it satisfies a given erasure request is the DPO's call. - Data keys are random, never derived from the master key. - A key-store outage is not an erasure. ### Start the sample with Docker Compose and Spring Boot Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Starts the sample application using Docker Compose, sets required environment variables (SHREDDING_MASTER_KEY, SHREDDING_ERASURE_LOG_SECRET, SHREDDING_BLIND_INDEX_SECRET) from random data, and runs the Spring Boot app via the Maven wrapper. ```bash docker compose -f gdpr-shredding-sample/docker-compose.yml up -d export SHREDDING_MASTER_KEY=$(head -c 32 /dev/urandom | base64) export SHREDDING_ERASURE_LOG_SECRET=$(head -c 32 /dev/urandom | base64) export SHREDDING_BLIND_INDEX_SECRET=$(head -c 32 /dev/urandom | base64) cd gdpr-shredding-sample && ../mvnw spring-boot:run ``` -------------------------------- ### Backup retention configuration examples Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-rc-0.2.0.md Shows two configuration property values and their resulting errors. The first causes a DateTimeException, the second a KeyUnavailableException with a PSQLException. ```text shredding.erasure.backup-retention=PT9000000000000H -> java.time.DateTimeException: Instant exceeds minimum or maximum instant shredding.erasure.backup-retention=PT3000000000000H -> KeyUnavailableException[SHRED-KEY-UNAVAILABLE] shredding key store is unavailable (SQLState 22008) | PSQLException: ERROR: timestamp out of range: "344265-02-19 ..." ``` -------------------------------- ### Build with Maven Wrapper Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Runs the full build and verification with the Maven wrapper. Requires Docker because Testcontainers starts PostgreSQL. ```bash ./mvnw -B clean verify # needs Docker: Testcontainers starts PostgreSQL ``` -------------------------------- ### Create a customer with curl Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Sends a POST request to localhost:8080/customers with a JSON body containing tenantId, customerId, email, and phone. This is part of the quick start to demonstrate the API. ```bash curl -s localhost:8080/customers -H 'content-type: application/json' -d '{ "tenantId":"acme","customerId":"cust-42", "email":"alice@example.com","phone":"+33100000000" }' ``` -------------------------------- ### Schema-qualified @SQLRestriction example Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Example of schema-qualifying a function in @SQLRestriction to avoid read-back failures. Unqualified names cause erasure failure. ```java @SQLRestriction("public.pr18_visible(owner_id)") ``` -------------------------------- ### RC-7: Lock timeout error output Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-rc-0.2.0.md Example error output when a lock timeout occurs, showing the KeyUnavailableException message and SQLState 55P03. ```text KeyUnavailableException[SHRED-KEY-UNAVAILABLE] shredding key store is unavailable (SQLState 55P03) ``` -------------------------------- ### Erasure request example Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Shows how to invoke the erasure service with an ErasureRequest for a specific tenant and subject, with a reason and actor. After erasure, the email reads '[erased]' and the erasure log records the event. ```java erasureService.erase(new ErasureRequest( TenantId.of("acme"), SubjectId.of("cust-42"), "dpo", "art 17 request")); ``` -------------------------------- ### RC-12 Probe Output: Non-reproducible Build Reported as Build Failure Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-rc-0.2.0.md Example output from the RC-12 probe when verify-reproducible.sh reports a DIFFERS line and exits 1. The probe incorrectly labels the failure as a build failure instead of a reproducibility issue. ```text build failed in: scripts/verify-reproducible.sh (two -DskipTests builds); last 40 lines of the log: | gdpr-shredding-core-0.1.0-SNAPSHOT.jar DIFFERS aa vs bb ERROR rc12 the probe could not reach a verdict (see above) ``` -------------------------------- ### Audited entity with @Shredded and @BlindIndex fields Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Example entity showing required @NotAudited on @Shredded and @BlindIndex fields. Startup fails with SHRED-SCHEMA-010 or SHRED-CONFIG-001 if these are not followed. ```java @Entity @Audited @Table(name = "customer", schema = "public") public class Customer { @Id Long id; @Column(name = "customer_id") String customerId; @Column(name = "tenant_id") String tenantId; @NotAudited @Shredded(subject = "#{customerId}", tenant = "#{tenantId}") @Convert(converter = EmailConverter.class) String email; @NotAudited @BlindIndex(of = "email", subjectColumn = "customer_id", tenantColumn = "tenant_id") @Column(name = "email_idx") byte[] emailIndex; } ``` -------------------------------- ### CustomerEmailConverter extends ShreddedStringConverter Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md A two-line converter class that binds the converter to the 'Customer' entity and 'email' field. The startup scan cross-checks every @Shredded field against its @Convert mapping and refuses to start if names disagree. ```java @Converter public class CustomerEmailConverter extends ShreddedStringConverter { public CustomerEmailConverter() { super("Customer", "email"); } } ``` -------------------------------- ### Core module: verify schema and build store Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Java code showing how to verify the schema, create a JdbcKeyProvider and JdbcErasureStore, and optionally include acknowledged copies. The store refuses erasures that do not name its acknowledged copies. ```java VerifiedSchema schema = JdbcSupport.verifySchema(runtimeDataSource).schema(); var keys = new JdbcKeyProvider(runtimeDataSource, schema, masterKey, random, clock); var store = new JdbcErasureStore(runtimeDataSource, schema, chain, blindIndexColumns, residual); // or, with acknowledged copies (entry n is named shredding.jdbc.acknowledged-copies[n]): var store = new JdbcErasureStore(runtimeDataSource, schema, chain, blindIndexColumns, residual, CopySignatures.defaults(), List.of(AcknowledgedCopy.trigger("public", "customer", "customer_history", "historyIndexScrubber"))); ``` -------------------------------- ### Startup refusal error message Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Error message shown at startup when no schema is configured for a @Shredded entity. Indicates the entity name, table, and required configuration. ```text SHRED-CONFIG-001: Customer is @Shredded and is mapped to the table "customer", which names no schema. ... Set spring.jpa.properties.hibernate.default_schema= for the application, or map @Table(schema = "") on this entity. ``` -------------------------------- ### Record current state: tables, triggers, functions Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these queries before upgrading to capture the current state of tables, triggers, and functions. A tgenabled other than 'O' or 'A' indicates a guard has been off or replaced. On a 0.1.x schema, proconfig is NULL on all three functions; after step 3 it must read '{"search_path=pg_catalog, pg_temp"}'. ```sql SELECT tablename, tableowner FROM pg_tables WHERE schemaname = current_schema() AND tablename LIKE 'shredding%'; SELECT tgname, tgenabled FROM pg_trigger WHERE NOT tgisinternal; SELECT proname, md5(prosrc) FROM pg_proc WHERE pronamespace = current_schema()::regnamespace AND proname LIKE 'shredding%'; SELECT proname, proconfig FROM pg_proc WHERE pronamespace = current_schema()::regnamespace AND proname LIKE 'shredding%'; ``` -------------------------------- ### Record current triggers, rules, publications, slots, foreign keys, and audit tables Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these queries before the upgrade to record the state of triggers, rules, publications, logical slots, foreign keys, and audit tables on the table and its partitions or children. The 'fam' table lists partitions and legacy inheritance children at any depth; it vanishes with the session. ```sql -- triggers and rules on the table and every partition or child SELECT tgrelid::regclass, tgname, tgenabled FROM pg_catalog.pg_trigger WHERE NOT tgisinternal AND tgenabled <> 'D' AND tgrelid IN (SELECT relid FROM fam); SELECT ev_class::regclass, rulename FROM pg_catalog.pg_rewrite WHERE rulename <> '_RETURN' AND ev_class IN (SELECT relid FROM fam); -- publications carrying the table or any member of its family (a partitioned table published -- without publish_via_partition_root is reported as its partitions), with their column lists -- (NULL: every column) SELECT p.pubname, p.pubupdate, t.relid::regclass, t.attrs FROM pg_catalog.pg_publication p, pg_catalog.pg_get_publication_tables(p.pubname::text) t WHERE t.relid IN (SELECT relid FROM fam); -- logical slots of this database that decode without a publication SELECT slot_name, plugin, active FROM pg_catalog.pg_replication_slots WHERE slot_type = 'logical' AND database = current_database() AND plugin <> 'pgoutput'; -- foreign keys on the table or any member of its family, either side SELECT conname, conrelid::regclass, confrelid::regclass FROM pg_catalog.pg_constraint WHERE contype = 'f' AND (conrelid IN (SELECT relid FROM fam) OR confrelid IN (SELECT relid FROM fam)); -- leftover audit or history tables holding a column of the index's name (ordinary tables -- outside the family; a materialized view is found by the dependents query above) SELECT a.attrelid::regclass FROM pg_catalog.pg_attribute a JOIN pg_catalog.pg_class c ON c.oid = a.attrelid WHERE a.attname = 'email_idx' AND NOT a.attisdropped AND c.relkind = 'r' AND a.attrelid NOT IN (SELECT relid FROM fam); ``` -------------------------------- ### YAML configuration: disable schema initialization and allow privileged runtime role Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Use this configuration only when a role cannot be added in the same window. It disables schema initialization and allows the privileged runtime role, resulting in a WARN at every startup. This configuration should not be presented as an append-only erasure log to a supervisory authority. ```yaml shredding: jdbc: initialize-schema: false allow-privileged-runtime-role: true ``` -------------------------------- ### Add gdpr-shredding-spring-boot-starter Maven dependency Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Include this dependency in your Maven pom.xml to use the GDPR Shredding starter. Version 0.2.0 is specified. Requires Java 21, Spring Boot 4.1, and PostgreSQL. ```xml com.housedevinci gdpr-shredding-spring-boot-starter 0.2.0 ``` -------------------------------- ### RC-8: Maven verify command Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-rc-0.2.0.md Command used to run the full build with tests, ignoring test failures, to reproduce the branch numbers. ```bash CIPHER_PROBE_MAVEN=1 ./mvnw -B verify -Dmaven.test.failure.ignore=true ``` -------------------------------- ### Inspect blind-index column family (public.customer.email_idx) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these queries to list what step 3a will have to change for each blind-index column. The temporary table 'fam' collects the table and all its partitions/inheritance children. Any row returned by the statistics or dependency queries is a finding that 0.2.0 will refuse (SHRED-SCHEMA-010). ```sql -- the table and every partition or inheritance child, at any depth (partitions are in -- pg_inherits too); every query below that names "fam" reads it, so run them in this session CREATE TEMPORARY TABLE fam AS WITH RECURSIVE t(relid) AS ( SELECT 'public.customer'::regclass::oid UNION SELECT i.inhrelid FROM pg_catalog.pg_inherits i JOIN t ON i.inhparent = t.relid ) SELECT relid FROM t; -- the statistics target (16: -1 is the default; 17: NULL is the default), on the table and -- every partition or inheritance child; anything but 0 is refused SELECT a.attrelid::regclass, a.attname, a.attstattarget FROM pg_catalog.pg_attribute a WHERE a.attrelid IN (SELECT relid FROM fam) AND a.attname = 'email_idx'; -- statistics already stored, on the table or on any member of the family: any row is refused SELECT schemaname, tablename, attname, inherited FROM pg_catalog.pg_stats WHERE (quote_ident(schemaname) || '.' || quote_ident(tablename))::regclass IN (SELECT relid FROM fam) AND attname = 'email_idx'; -- expression indexes and extended statistics on the family: refused when they read the column SELECT indexrelid::regclass, pg_catalog.pg_get_indexdef(indexrelid) FROM pg_catalog.pg_index WHERE indrelid IN (SELECT relid FROM fam) AND indexprs IS NOT NULL; SELECT stxrelid::regclass, stxname FROM pg_catalog.pg_statistic_ext WHERE stxrelid IN (SELECT relid FROM fam); -- what depends on the column (views, policies, generated columns): decides step 3a's shape SELECT pg_catalog.pg_describe_object(d.classid, d.objid, d.objsubid) FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_attribute a ON a.attrelid = d.refobjid AND a.attnum = d.refobjsubid WHERE d.refclassid = 'pg_catalog.pg_class'::regclass AND d.refobjid IN (SELECT relid FROM fam) AND d.deptype <> 'i' AND a.attname = 'email_idx'; ``` -------------------------------- ### Repro: drop and recreate trigger with WHEN predicate (SQL) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-no-ddl-at-runtime.md Reproduction for leg 1 (the erasure log). Run as the owner against a schema created by the bundled script. Drops the original guard trigger and recreates it with the same name so the schema appears byte-identical to the clean one while the guard no longer fires. ```sql DROP TRIGGER shredding_erasure_append_only ON shredding_erasure; CREATE TRIGGER shredding_erasure_append_only BEFORE UPDATE OR DELETE ON shredding_erasure; ``` -------------------------------- ### Custom HibernatePropertiesCustomizer to compose Envers first Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Bean that sets the integrator provider to compose Envers' integrator first, ensuring this module's customizer runs last. Uses EnversFirstIntegrator. ```java @Bean @Order(Ordered.HIGHEST_PRECEDENCE) HibernatePropertiesCustomizer enversFirst() { // Envers' integrator is composed first; this module's customizer composes itself last. return props -> props.put(JpaSettings.INTEGRATOR_PROVIDER, (IntegratorProvider) () -> List.of(new EnversFirstIntegrator())); } ``` -------------------------------- ### YAML configuration for shredding keys Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Configures the master key and HMAC secrets for erasure log and blind index, all sourced from environment variables. The master key must be base64 and at least 32 bytes. ```yaml shredding: master-key: ${SHREDDING_MASTER_KEY} # base64, >= 32 bytes, environment only erasure-log: hmac-secret: ${SHREDDING_ERASURE_LOG_SECRET} blind-index: hmac-secret: ${SHREDDING_BLIND_INDEX_SECRET} ``` -------------------------------- ### Configure acknowledged copies in YAML Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md YAML configuration to acknowledge triggers, publications, or replication slots that must stay. Each entry warns at startup, records erasures as PARTIAL until the hook succeeds, and refuses startup if the object does not exist. ```yaml shredding: jdbc: acknowledged-copies: - kind: trigger # trigger | publication | replication-slot schema: public # trigger only table: customer # trigger only name: customer_history # as pg_catalog stores it: unquoted names in lower case cleared-by: historyIndexScrubber # PostErasureHook.name(), required ``` -------------------------------- ### CREATE FUNCTION string body vs atomic body Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-read-back-bracket.md Two PostgreSQL function definitions showing the difference between a string body and a SQL-standard atomic body. The string body fails inside the window with relation does not exist, while the atomic body succeeds. ```sql CREATE FUNCTION public.pr18_string_body() RETURNS bigint AS $$ SELECT count(*) FROM pr18_allow $$ LANGUAGE sql ``` ```sql CREATE FUNCTION public.pr18_atomic_body() RETURNS bigint LANGUAGE sql BEGIN ATOMIC SELECT count(*) FROM pr18_allow; END ``` -------------------------------- ### Find attnums and count pg_statistic rows for manual deletion (PostgreSQL 16/17) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Superuser deletes exactly those rows after the owner's SET STATISTICS 0. First list attnums for every descendant, then count rows to verify. ```sql SELECT a.attrelid::regclass, a.attname, a.attnum FROM pg_catalog.pg_attribute a WHERE a.attrelid IN (SELECT relid FROM pg_catalog.pg_partition_tree('public.customer')) AND a.attname IN ('email_idx', 'email_low'); ``` ```sql SELECT pg_catalog.count(*) FROM pg_catalog.pg_statistic WHERE (starelid = 'public.customer'::regclass AND staattnum = 4) OR (starelid = 'public.customer'::regclass AND staattnum = 6); ``` -------------------------------- ### Check and change database owner Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Ensure the database is not owned by the application role. Query the current owner and alter it to a different role. ```sql SELECT pg_get_userbyid(datdba) FROM pg_database WHERE datname = current_database(); ALTER DATABASE OWNER TO ; ``` -------------------------------- ### Check row security and privileges for runtime role Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run as the runtime role, substituting its name. Both of the last two columns must be true, and rowsecurity false unless bypassrls is true. ```sql SELECT c.relrowsecurity AS rowsecurity, c.relforcerowsecurity AS forced, r.rolbypassrls AS bypassrls, pg_catalog.has_table_privilege(r.oid, c.oid, 'SELECT') AS can_select, pg_catalog.has_table_privilege(r.oid, c.oid, 'UPDATE') AS can_update FROM pg_catalog.pg_class c, pg_catalog.pg_roles r WHERE c.oid = 'public.customer'::regclass AND r.rolname = ''; ``` -------------------------------- ### ShreddingContext.withReadBracket for raw EntityManager find Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Use this to wrap a raw EntityManager entity operation (find, merge, refresh, entity-returning query) so the load is verified against the row's tenant, subject, and identifier. Without it, such operations are refused with SHRED-READ-UNVERIFIED or SHRED-READ-UNSCOPED. This is the one stable entry point an application calls directly. ```java Doc doc = ShreddingContext.withReadBracket(() -> entityManager.find(Doc.class, id)); ``` -------------------------------- ### SQL query to detect dropped bigserial default Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-no-ddl-at-runtime.md This SQL query checks for a pg_attrdef row for the erasure table's sequence column, requiring a pg_depend 'n' edge pointing to the sequence's oid. A count other than 1 indicates a dropped default or a default wired to a different sequence, triggering SHRED-SCHEMA-002. ```sql SELECT count(*) FROM pg_attrdef ad JOIN pg_depend d ON d.classid = 'pg_attrdef'::regclass AND d.objid = ad.oid AND d.refclassid = 'pg_class'::regclass AND d.refobjid = AND d.deptype = 'n' WHERE ad.adrelid = AND ad.adnum = ``` -------------------------------- ### Undo ownership changes for the application role (variant B) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these SQL statements as the owner role or a superuser to restore ownership of the tables, guard functions, and schema to the application role. This is required for variant B of the rollback. The last GRANT statement can be replaced with ALTER SCHEMA ... OWNER TO if step 2 also moved the schema. ```sql ALTER TABLE shredding_data_key OWNER TO ; ALTER TABLE shredding_erased_subject OWNER TO ; ALTER TABLE shredding_erasure OWNER TO ; ALTER TABLE shredding_erasure_anchor OWNER TO ; ALTER FUNCTION shredding_erasure_append_only() OWNER TO ; ALTER FUNCTION shredding_erasure_anchor_monotonic() OWNER TO ; ALTER FUNCTION shredding_erasure_anchor_append_only() OWNER TO ; GRANT CREATE ON SCHEMA TO ; ``` -------------------------------- ### NOTICE output: resolved oid and name for pg_class Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-no-ddl-at-runtime.md Shown as the observable output of the probe when the unqualified `||` operator is shadowed. The resolved oid is 1259 and the name is pg_class. ```text NOTICE: resolved oid = 1259, name = pg_class ``` -------------------------------- ### Repro: create enum, implicit cast, and table for C-19-1 Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-mapping-admission.md Run as the runtime role. The role owns one of the two types involved, so CREATE CAST is permitted. The implicit cast from app.c191_e to text makes the driver's varchar-bound equality resolve through app.c191_lie, so no 42883 error occurs; the framework read-back resolves the same way because casts are not looked up through search_path. ```sql CREATE TYPE app.c191_e AS ENUM ('T1','T2'); CREATE FUNCTION app.c191_lie(app.c191_e) RETURNS text LANGUAGE sql IMMUTABLE AS $$ SELECT 'nope'::text $$; CREATE CAST (app.c191_e AS text) WITH FUNCTION app.c191_lie(app.c191_e) AS IMPLICIT; CREATE TABLE app.c191 (id bigint, tenant app.c191_e, subject varchar(64), email_idx varchar(64)); INSERT INTO app.c191 VALUES (1, 'T1', 's-c191', 'HMAC-RESIDUE'); ``` -------------------------------- ### Map schema per entity with @Table Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Alternative to global schema configuration: specify the schema directly on each @Shredded entity using @Table(schema = "app"). ```java @Entity @Table(name = "customer", schema = "app") public class Customer { ... } ``` -------------------------------- ### Set search_path for a function Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Remedy for functions used in @SQLRestriction or @Filter conditions: set the function's search_path to the schema and pg_catalog. ```sql ALTER FUNCTION SET search_path = , pg_catalog ``` -------------------------------- ### Generate secrets for GDPR Shredding Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Generate the three secrets required by the library and pass them through the environment. The SHREDDING_BLIND_INDEX_SECRET is only needed if you use @BlindIndex. ```bash export SHREDDING_MASTER_KEY=$(head -c 32 /dev/urandom | base64) export SHREDDING_ERASURE_LOG_SECRET=$(head -c 32 /dev/urandom | base64) export SHREDDING_BLIND_INDEX_SECRET=$(head -c 32 /dev/urandom | base64) # only if you use @BlindIndex ``` -------------------------------- ### Move ownership of shredding tables and functions to an owner role Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Use these ALTER statements to transfer ownership of the shredding tables and guard functions to a role that is not the application's. The three functions do not move with the tables, so they must be altered separately. REASSIGN OWNED BY is an alternative but moves all objects owned by the application role. ```sql ALTER TABLE shredding_data_key OWNER TO ; ALTER TABLE shredding_erased_subject OWNER TO ; ALTER TABLE shredding_erasure OWNER TO ; ALTER TABLE shredding_erasure_anchor OWNER TO ; ALTER FUNCTION shredding_erasure_append_only() OWNER TO ; ALTER FUNCTION shredding_erasure_anchor_monotonic() OWNER TO ; ALTER FUNCTION shredding_erasure_anchor_append_only() OWNER TO ; ``` -------------------------------- ### SQL: Insert, disable trigger, delete to empty erasure trail Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-no-ddl-at-runtime.md Executed on the same connection after the shadowed role passes verification. Inserts one row, disables all triggers on the erasure table, then deletes all rows, emptying the trail. Demonstrates that the INFO line is false and SHRED-SCHEMA-004 is not a control against the role it is about. ```sql INSERT INTO public.shredding_erasure (...) -- 1 row ALTER TABLE public.shredding_erasure DISABLE TRIGGER ALL -- succeeds DELETE FROM public.shredding_erasure -- succeeds, trail emptied ``` -------------------------------- ### Revoke DDL and shadowing privileges from application role Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Revoke CREATE on schema, TEMPORARY on database, and CREATE on database from the application role and PUBLIC. The last two lines prevent creation of pg_temp.shredding_erasure and CREATE SCHEMA. ```sql REVOKE CREATE ON SCHEMA FROM ; REVOKE CREATE ON SCHEMA public FROM PUBLIC; -- PostgreSQL 14 and earlier REVOKE TEMPORARY ON DATABASE FROM , PUBLIC; REVOKE CREATE ON DATABASE FROM , PUBLIC; ``` -------------------------------- ### Clear attribute stats for blind-index column (PostgreSQL 18+) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run as table owner after SET STATISTICS 0 on the column and each stored generated column computed from it. Execute once per column and per partition or child. ```sql SELECT pg_catalog.pg_clear_attribute_stats('public', 'customer', 'email_idx', false); SELECT pg_catalog.pg_clear_attribute_stats('public', 'customer', 'email_idx', true); -- a parent ``` -------------------------------- ### Configure default schema in application.yml Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Set the Hibernate default schema to 'app' in your Spring configuration. Required to avoid startup refusal SHRED-CONFIG-001. ```yaml spring: jpa: properties: hibernate.default_schema: app # the schema your own tables live in ``` -------------------------------- ### SQLGrammarException for unresolved pr18_visible function Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-read-back-bracket.md Shows the error when a @SQLRestriction function is not schema-qualified inside the windowed read-back. The transaction rolls back whole and the erasure fails closed. ```text SQLGrammarException: ERROR: function pr18_visible(character varying) does not exist [select count(*) from public.pr18_restricted_note prn1_0 where (pr18_visible(prn1_0.owner_id)) and ...] ``` -------------------------------- ### Disable statistics on blind index column Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Required SQL to set statistics to 0 on the blind index column so that ANALYZE does not store sampled values in pg_statistic, which would remain matchable after erasure. Must be done in the same migration as column creation. ```sql ALTER TABLE public.customer ALTER COLUMN email_bidx SET STATISTICS 0; ``` -------------------------------- ### Delete pg_statistic rows with row-count check (PostgreSQL 16/17) Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run as superuser after obtaining the count (here 2). Deletes the rows and verifies the exact number deleted, raising an exception if it differs. ```sql BEGIN; DO $$ DECLARE n bigint; BEGIN DELETE FROM pg_catalog.pg_statistic WHERE (starelid = 'public.customer'::regclass AND staattnum = 4) OR (starelid = 'public.customer'::regclass AND staattnum = 6); GET DIAGNOSTICS n = ROW_COUNT; IF n <> 2 THEN RAISE EXCEPTION 'expected 2 pg_statistic rows, deleted %', n; END IF; END $$; COMMIT; ``` -------------------------------- ### Reproduce inheritance child bypass with CREATE TABLE and INSERT Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/SECURITY-REVIEW-feat-no-ddl-at-runtime.md Creates a child table inheriting from shredding_erasure and inserts a row with seq 999. The row is invisible to the parent's row-level trigger and is returned by every read of the verified relation, including the module's own read() and the chain verifier. ```sql CREATE TABLE shredding_erasure_child () INHERITS (shredding_erasure); INSERT INTO shredding_erasure_child (seq, ts, ...) VALUES (999, ...); ``` -------------------------------- ### Clear planner statistics on a blind-index column Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these statements as the owner role to stop ANALYZE from sampling the column and delete existing statistics. The SET STATISTICS 0 statement prevents future sampling; the TYPE statement removes stored statistics. Each ALTER TABLE takes an ACCESS EXCLUSIVE lock, so lock_timeout is set to 5 seconds; on timeout, retry. ```sql SET search_path = pg_catalog, pg_temp; SET lock_timeout = '5s'; ALTER TABLE public.customer ALTER COLUMN email_idx SET STATISTICS 0; ALTER TABLE public.customer ALTER COLUMN email_idx TYPE bytea USING email_idx; ``` -------------------------------- ### Clear and drop blind-index column from audit/history tables Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Run these SQL statements to remove a blind-index column from an audit or history table, as required by step 4 of the upgrade. The column must be cleared before dropping it. ```sql UPDATE _aud SET = NULL; ALTER TABLE
_aud DROP COLUMN ; ``` -------------------------------- ### Check that mapped table has no parent Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/upgrading-0.2.0.md Each mapped table with a blind index must have no parent. The query must return no row. ```sql SELECT inhparent::regclass FROM pg_catalog.pg_inherits WHERE inhrelid = 'public.customer'::regclass; -- must return no row ``` -------------------------------- ### Disable Envers auto-registration Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Property to disable Envers' auto-registration of listeners, required for manual mode so this module's listener stays last. ```properties spring.jpa.properties.hibernate.envers.autoRegisterListeners=false ``` -------------------------------- ### Java entity with @Shredded and @BlindIndex Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/README.md Shows a JPA entity with @Shredded on the email field to encrypt it under a per-customer key, and @BlindIndex for equality lookups. The converter class extends ShreddedStringConverter. The email field becomes unreadable after erasure. ```java @Entity @Table(name = "customer") public class Customer { @Id @GeneratedValue Long id; @Column(name = "tenant_id") String tenantId; // stays readable @Column(name = "customer_id") String customerId; // stays readable: the audit rows point here @Shredded(subject = "#{customerId}", tenant = "#{tenantId}") @Convert(converter = CustomerEmailConverter.class) @Column(name = "email") String email; // encrypted under this customer's own key @BlindIndex(of = "email", subjectColumn = "customer_id", tenantColumn = "tenant_id") @Column(name = "email_bidx") byte[] emailBidx; // equality lookups; nulled by an erasure @Override public String toString() { return "Customer[" + customerId + "]"; } } @Converter public class CustomerEmailConverter extends ShreddedStringConverter { public CustomerEmailConverter() { super("Customer", "email"); } } ``` -------------------------------- ### Shredded byte[] field with @Immutable Source: https://github.com/1of1canopus/gdpr-shredding/blob/main/docs/index.md Shows a @Shredded byte[] field annotated with @Immutable, required to prevent Hibernate from deep-copying the converted value. Without @Immutable, the second converter call under IDENTITY fails with SHRED-CONTEXT-001. Note that @Immutable prevents dirty checking from detecting in-place mutations; assign a whole new array instead. ```java @Shredded(subject = "#{ownerId}") @Convert(converter = DocumentPayloadConverter.class) @Immutable @Column(name = "payload") byte[] payload; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.