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 1myLF1-0006sk-Vq for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Dec 2021 21:58:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1myLEz-0006aW-0C for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Dec 2021 21:58:13 +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 1myLEy-0006aN-Bw for pgsql-hackers@lists.postgresql.org; Fri, 17 Dec 2021 21:58:12 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1myLEp-0002kk-Vb for pgsql-hackers@postgresql.org; Fri, 17 Dec 2021 21:58:11 +0000 Received: by mail-ed1-x52d.google.com with SMTP id y22so13063160edq.2 for ; Fri, 17 Dec 2021 13:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=CSCyR7ysqZGcGKOJKMTHJi8j09IHcXuc6I74i8eK8BE=; b=Zv4LXy5B0nAkKCpMH3dONr/v9PvsZqYudYreQn6Be1UMneklaxIpIJTsH7UEYYy0bc cTjpbrfIeZVmjB+8QGbsklJM+a17QJVXw6iUWzgw4/frQf4X3AXFQ9/ZZMKm3YI4zCNW WJ6D4Sq1WjRL9kUDvu1+Z7U6P4Nnu6WdsU4c8C3YNftHMvU59U4pMh9GaLfWAZ8YqltO wULGN40XF77J0IYMrGLvOmxmok/elr9H5Wv4coKashVCeBOcW4BjI+rdCumQ8ObymqSj UPttdSubHSKS5NHqO+TN4F20fDn/FwWgs+rZQSSPhqGkyOjo2JJmUjOs+iF94nnx5wcw hm9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=CSCyR7ysqZGcGKOJKMTHJi8j09IHcXuc6I74i8eK8BE=; b=c0f3dPsEMGAsbf6K/A1tLuM0QNoyF2p+UgV3v3EuKpsrFPI+uYtYIpzLyisd7GUUYx S/O12fEbqq5zBuLxUfsfneALGIZrkflcQW7rN8rwXoe3Imi8jAZmp7cCirrr9Djnn98k 3pYoMllDZ2s2weIQF0aC3AqvpQhc6GS/lLCny/PL67CCRQY3FwBpr4NugvJGHVUEOvCB 9MOCEausm6120MkgZE/sq3Xqrw4iYXwbY5uBNnkoPugUlfMf7NbSHC7Xz1iIqtlkYxVo Vs+RgZjc3wBcsou6Dn7uFgSQYYfaa2gPqWs68Piq1200Dh5uUEX0pwLnMzrNkGLvlpVb zPjw== X-Gm-Message-State: AOAM531MeXcicP/bCeTsp2zsUQSd0/95fSaraWa1kFcUs0Igy6R9tnMI yshyIpnkd6341kjlXTj+soN34lD3RbLFJv419upZsT3GffF8vk88L91UQFPOiC3KzXDKpxreFto xeKkBxhJHfRrkP5THQgxPPN6rz0rdMZ8zg8mFaRk+VTEYn4r3zkNpfwbIgbmmQhOlLuyXvbyg/0 QeojIoHdJhdqSMq03VqToSLOjRA+wDDrGk0wXo X-Google-Smtp-Source: ABdhPJw+155oc1pkfpXjaDON7gaqv9Szg0VsWDrt1KyCzvp0gC+4TzUq8Vu3MJg5tZblbTqVDnme4A== X-Received: by 2002:a17:907:6d94:: with SMTP id sb20mr4265526ejc.206.1639778281140; Fri, 17 Dec 2021 13:58:01 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id di5sm3281342ejc.45.2021.12.17.13.58.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 13:58:00 -0800 (PST) Message-ID: <773e96e5-77ef-ad26-ad37-03ca41a0ad25@enterprisedb.com> Date: Fri, 17 Dec 2021 22:57:56 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: Column Filtering in Logical Replication Content-Language: en-US To: Alvaro Herrera , Rahila Syed Cc: PostgreSQL-development References: <202112172107.i5ebyfyrifk7@alvherre.pgsql> From: Tomas Vondra In-Reply-To: <202112172107.i5ebyfyrifk7@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/17/21 22:07, Alvaro Herrera wrote: > So I've been thinking about this as a "security" item (you can see my > comments to that effect sprinkled all over this thread), in the sense > that if a publication "hides" some column, then the replica just won't > get access to it. But in reality that's mistaken: the filtering that > this patch implements is done based on the queries that *the replica* > executes at its own volition; if the replica decides to ignore the list > of columns, it'll be able to get all columns. All it takes is an > uncooperative replica in order for the lot of data to be exposed anyway. > Interesting, I haven't really looked at this as a security feature. And in my experience if something is not carefully designed to be secure from the get go, it's really hard to add that bit later ... You say it's the replica making the decisions, but my mental model is it's the publisher decoding the data for a given list of publications (which indeed is specified by the subscriber). But the subscriber can't tweak the definition of publications, right? Or what do you mean by queries executed by the replica? What are the gap? > If the server has a *separate* security mechanism to hide the columns > (per-column privs), it is that feature that will protect the data, not > the logical-replication-feature to filter out columns. > Right. Although I haven't thought about how logical decoding interacts with column privileges. I don't think logical decoding actually checks column privileges - I certainly don't recall any ACL checks in src/backend/replication ... AFAIK we only really check privileges during initial sync (when creating the slot and copying data), but then we keep replicating data even if the privilege gets revoked for the table/column. In principle the replication role is pretty close to superuser. > > This led me to realize that the replica-side code in tablesync.c is > totally oblivious to what's the publication through which a table is > being received from in the replica. So we're not aware of a replica > being exposed only a subset of columns through some specific > publication; and a lot more hacking is needed than this patch does, in > order to be aware of which publications are being used. > > I'm going to have a deeper look at this whole thing. > Does that mean we currently sync all the columns in the initial sync, and only start filtering columns later while decoding transactions? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company