Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s12qG-0092El-0U for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Apr 2024 11:37:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s12qC-00Cnym-KL for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Apr 2024 11:37:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s12qC-00Cnye-AD for pgsql-hackers@lists.postgresql.org; Sun, 28 Apr 2024 11:37:09 +0000 Received: from mail-yb1-xb35.google.com ([2607:f8b0:4864:20::b35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s12q8-000RoR-PF for pgsql-hackers@lists.postgresql.org; Sun, 28 Apr 2024 11:37:07 +0000 Received: by mail-yb1-xb35.google.com with SMTP id 3f1490d57ef6-de467733156so3784698276.0 for ; Sun, 28 Apr 2024 04:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714304223; x=1714909023; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Gbt98+QvlJSTswYussaNxyRNjPAPzSENs7Qo0O0PcOg=; b=m1/Hnz9z94XbJjpgpOdtkc4oZ8jwDBHxvS1M2AfZnJHuHUHj5kSJ7jngkfOXYHUtjz T1iez+TP93VI9kesxHUnQ5nbuIiCkboYClAFPxWoXIzGJ34GzJ3qPvbdgShDGyPaplAx URwFOTZ/x/uBqp7d7gcWvR+LgPZDXtnfWYGustaND4ENYPphbdh/O4i40iKvO2UdlxaZ +Gs0aSE2rfSOqlbbNd7sPY4hyUPAWa2QByXmZD+5JwGB06T3BIJebczdv080oevylVNz cpwNmBvMFGgVy9zDTvMUa2/cBAckyGB8dNP1iRjTyK9SarV4tpSzOTCt1UwYRjcNVQl6 J+lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714304223; x=1714909023; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gbt98+QvlJSTswYussaNxyRNjPAPzSENs7Qo0O0PcOg=; b=qtvj4JrWEMYOA+lYS1RqZofD+hH1A1CQiqOAFFp+K9NAvR8Z6aQz7oeGR64Mzgc5Oz X6dnTcrPtDCNZZ3W6hr+ZtkKyLjZZzkK5qSzzxafT4hjJTmoTZYgjZyESpzSxG0FXik0 8WeovwICz3zX7aEspPzZ/BMSPm2fsyiJaHdLMrfYjFpiMRe449GAAgUb8ZeV8p2qWS0S FJYErVVUcJKYPyV1cmpitbZyAtC6zbRfporfDbE8YW1Z8kSO1qsgVGFQJmU/eetyeMTx oBPzFyy6gFcYRIbtOLI7Kn2x956BnGwOsXDoqpJ6AYcf+VWwMUy8BW6/d8A0tusTWOcm TlrA== X-Forwarded-Encrypted: i=1; AJvYcCVe75XB8sMTrfBiX8vBH79svD2oqCsljq3O3xUwEoPtGYUeQkBGprrRLT2cJdmtWvgQhv0HjlA2UVMyayzlKRB4TaHyP/tQQBR7L7j+lzcy6mcZ X-Gm-Message-State: AOJu0YyFMPCOthN6wEiVPMbvOPZIZY3Zij1hmvYDhzq9pAyhYR3SvsoW 5jhkjqZyBDhVhysUEymE9LUryl6obXu/NvU7y95vrLHBydpUf2L3r029QPjxqIszMBRDZ+HA1NI 8himPAyVQblD05VJZMIpz1cV6dz8= X-Google-Smtp-Source: AGHT+IEUKhY0udw6Z/7/OyhyERhvVpl9uufV7m493wd0RB9/oVhJOfGTCKtfQikDs2L0ty0SpP958/HA5d7gm5xVeR4= X-Received: by 2002:a25:b7cb:0:b0:de4:7831:915 with SMTP id u11-20020a25b7cb000000b00de478310915mr8899805ybj.19.1714304223272; Sun, 28 Apr 2024 04:37:03 -0700 (PDT) MIME-Version: 1.0 References: <56e0000c-6b39-44ce-90b4-d3c3062e408c@postgrespro.ru> <5dee3937-8e9f-cca4-11fb-737709a92b37@gmail.com> <0520c72e-8d97-245e-53f9-173beca2ab2e@gmail.com> In-Reply-To: <0520c72e-8d97-245e-53f9-173beca2ab2e@gmail.com> From: Alexander Korotkov Date: Sun, 28 Apr 2024 14:36:51 +0300 Message-ID: Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands To: Alexander Lakhin Cc: Dmitry Koval , Justin Pryzby , Robert Haas , Pavel Borisov , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Apr 28, 2024 at 2:00=E2=80=AFPM Alexander Lakhin wrote: > 28.04.2024 03:59, Alexander Korotkov wrote: > > The revised patchset is attached. I'm going to push it if there are > > no objections. > > I have one additional question regarding security, if you don't mind: > What permissions should a user have to perform split/merge? > > When we deal with mixed ownership, say, bob is an owner of a > partitioned table, but not an owner of a partition, should we > allow him to perform merge with that partition? > Consider the following script: > CREATE ROLE alice; > GRANT CREATE ON SCHEMA public TO alice; > > SET SESSION AUTHORIZATION alice; > CREATE TABLE t (i int PRIMARY KEY, t text, u text) PARTITION BY RANGE (i)= ; > CREATE TABLE tp_00 PARTITION OF t FOR VALUES FROM (0) TO (10); > CREATE TABLE tp_10 PARTITION OF t FOR VALUES FROM (10) TO (20); > > CREATE POLICY p1 ON tp_00 USING (u =3D current_user); > ALTER TABLE tp_00 ENABLE ROW LEVEL SECURITY; > > INSERT INTO t(i, t, u) VALUES (0, 'info for bob', 'bob'); > INSERT INTO t(i, t, u) VALUES (1, 'info for alice', 'alice'); > RESET SESSION AUTHORIZATION; > > CREATE ROLE bob; > GRANT CREATE ON SCHEMA public TO bob; > ALTER TABLE t OWNER TO bob; > GRANT SELECT ON TABLE tp_00 TO bob; > > SET SESSION AUTHORIZATION bob; > SELECT * FROM tp_00; > --- here bob can see his info only > \d > Schema | Name | Type | Owner > --------+-------+-------------------+------- > public | t | partitioned table | bob > public | tp_00 | table | alice > public | tp_10 | table | alice > > -- but then bob can do: > ALTER TABLE t MERGE PARTITIONS (tp_00, tp_10) INTO tp_00; > -- (yes, he also can detach the partition tp_00, but then he couldn't > -- re-attach nor read it) > > \d > Schema | Name | Type | Owner > --------+-------+-------------------+------- > public | t | partitioned table | bob > public | tp_00 | table | bob > > Thus bob effectively have captured the partition with the data. > > What do you think, does this create a new security risk? Alexander, thank you for discovering this. I believe that the one who merges partitions should have permissions for all the partitions merged. I'll recheck this and provide the patch. ------ Regards, Alexander Korotkov