From 4f66c93f61439b4db866b21cc1ecd5bf815564ef Mon Sep 17 00:00:00 2001 From: Joe Conway Date: Sat, 23 Nov 2019 10:41:52 -0500 Subject: Update sepgsql to add mandatory access control for TRUNCATE Use SELinux "db_table: { truncate }" to check if permission is granted to TRUNCATE. Update example SELinux policy to grant needed permission for TRUNCATE. Add new regression test to demonstrate a positive and negative cases. Test will only be run if the loaded SELinux policy has the "db_table: { truncate }" permission. Makes use of recent commit which added object TRUNCATE hook. Patch by Yuli Khodorkovskiy with minor editorialization by me. Not back-patched because the object TRUNCATE hook was not. Author: Yuli Khodorkovskiy Reviewed-by: Joe Conway Discussion: https://postgr.es/m/CAFL5wJcomybj1Xdw7qWmPJRpGuFukKgNrDb6uVBaCMgYS9dkaA%40mail.gmail.com --- contrib/sepgsql/hooks.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'contrib/sepgsql/hooks.c') diff --git a/contrib/sepgsql/hooks.c b/contrib/sepgsql/hooks.c index 49f32ac4d33..cdf1452cf57 100644 --- a/contrib/sepgsql/hooks.c +++ b/contrib/sepgsql/hooks.c @@ -188,6 +188,20 @@ sepgsql_object_access(ObjectAccessType access, } break; + case OAT_TRUNCATE: + { + switch (classId) + { + case RelationRelationId: + sepgsql_relation_truncate(objectId); + break; + default: + /* Ignore unsupported object classes */ + break; + } + } + break; + case OAT_POST_ALTER: { ObjectAccessPostAlter *pa_arg = arg; -- cgit v1.2.3