Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNBXY-00005T-OR for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 11:44:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNBXX-0005T8-4H for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Feb 2023 11:44:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNBXW-0005Sy-MZ for pgsql-hackers@lists.postgresql.org; Wed, 01 Feb 2023 11:44:34 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pNBXU-0003If-7h for pgsql-hackers@postgresql.org; Wed, 01 Feb 2023 11:44:34 +0000 Received: by mail-ej1-x633.google.com with SMTP id hx15so31055669ejc.11 for ; Wed, 01 Feb 2023 03:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=8XDrB/Z0691keAp2phKjB+gDTu4okgsqsVN1jEA8ycY=; b=SP8vjHxjpGuUdADBPCtdH29bhi3zMiAifMfEK7ZV4OxGVfOP/aloLbfV+WWc2tEZsQ G7u9yY8fsQNsbnyb+2LwCVkmv6OZDNhN3Z8cR60FwP8wGUq5zku8Ub1Vg9G19VZjAFe9 11VxrFGUsxqdiAXaCK+ev618oq8zIcIAiL0HLLmZJWrn+gVCKXIS99U2+7X96ktH+L47 AUg4EBHqmo+ur5WTcxR9t8yUmwlMRTpQOtYjJxpGuMHvGn5qtPAPnNU5vpfKlQyN4U+S +1VFWTVkr4zWdu3YE+EaSBocYWAss7/Xyt7sVYDtrckZDflssuyujryPWrb3/p8KyZaF pLmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:mime-version:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=8XDrB/Z0691keAp2phKjB+gDTu4okgsqsVN1jEA8ycY=; b=onnF5SOYdLWvnNJm6sl4RJuCEYs3WVAZefXKuW02fG+UaH9wcCsQlrLUqmTO6NVSyc 2ti5xP0YN+yLHZnaghDRt8wYgmv4hK0RR69YoxSmqLIkyveayGTunA0QifGhRde/H38Q hMSglGZXeVwUACA+/cPHrpdbzNaOLyuIx6DMIiPD0221t9mzv+1X0SJAGYy2R2kr9fkA 7Ap10zNTtrrVimkiBskAMS6pFtCbaugp9i7HGHICw/BGgUuzizbG8YoV02GNA59emGQV aedqJyhYZA6ME34VqNNjLd/oC73VgasT7V72aApuJb90bGqbgEH1YFiHU6tokQRZSeWv wwfw== X-Gm-Message-State: AO0yUKVpgMkgHuFTgoAluwWEWNL6bkGsKH2G/QTS27SiE8Qe4nkTChEK bgtooNJzfPzFGNzLL88WZvy6HpcDOGbxHAY3 X-Google-Smtp-Source: AK7set+RIB/hXqQ4eQ0aZBQZnKLjyaAp5STr3j1XJSjxk7atKUudMSt932uTRqwQb4tKldJhLWsF2g== X-Received: by 2002:a17:907:724b:b0:888:9bd6:34d2 with SMTP id ds11-20020a170907724b00b008889bd634d2mr2377968ejc.63.1675251870712; Wed, 01 Feb 2023 03:44:30 -0800 (PST) Received: from antos ([88.103.134.93]) by smtp.gmail.com with ESMTPSA id t26-20020a17090616da00b007aee7ca1199sm10020112ejd.10.2023.02.01.03.44.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 03:44:30 -0800 (PST) From: Antonin Houska To: pgsql-hackers@postgresql.org Subject: RLS makes COPY TO process child tables X-Mailer: MH-E 8.6+git; nmh 1.7+dev; GNU Emacs 28.2.50 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Date: Wed, 01 Feb 2023 12:45:57 +0100 Message-ID: <3472.1675251957@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=-=-= Content-Type: text/plain While working on [1] I noticed that if RLS gets enabled, the COPY TO command includes the contents of child table into the result, although the documentation says it should not: "COPY TO can be used only with plain tables, not views, and does not copy rows from child tables or child partitions. For example, COPY table TO copies the same rows as SELECT * FROM ONLY table. The syntax COPY (SELECT * FROM table) TO ... can be used to dump all of the rows in an inheritance hierarchy, partitioned table, or view." A test case is attached (rls.sql) as well as fix proposal (copy_rls_no_inh.diff). [1] https://commitfest.postgresql.org/41/3641/ -- Antonin Houska Web: https://www.cybertec-postgresql.com --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=rls.sql create table a(i int); insert into a values (1); create table a1() inherits(a); insert into a1 values (1); -- Only the parent table is copied, as the documentation claims. copy a to stdout; alter table a enable row level security; create role u; create policy pol_perm on a as permissive for select to u using (true); grant select on table a to u; set role u; -- Both "a" and "a1" appears in the output. copy a to stdout; --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=copy_rls_no_inh.diff diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index e34f583ea7..3b8c25dadd 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -249,6 +249,7 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, from = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)), pstrdup(RelationGetRelationName(rel)), -1); + from->inh = false; /* Build query */ select = makeNode(SelectStmt); --=-=-=--