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 1qfMdu-00AezJ-Li for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Sep 2023 15:46:34 +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 1qfMct-00A539-Dj for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Sep 2023 15:45:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qfMct-00A530-4e for pgsql-bugs@lists.postgresql.org; Sun, 10 Sep 2023 15:45:30 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qfMco-004HmZ-J4 for pgsql-bugs@postgresql.org; Sun, 10 Sep 2023 15:45:30 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-3a76d882080so2837324b6e.2 for ; Sun, 10 Sep 2023 08:45:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1694360724; x=1694965524; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:date:cc:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=7AGHvBbsgZIjtkwVxDa1Q2QCYM8GMdzhG57jmR9SvDM=; b=SpIW3Jzw3IhquPvt3wDMdgWK8fwfe9VUmqL+/M8xRG9XlVxM5QZwRr6/AHKU6VXqD5 GgJkVjlkRH9U/wVDEYEETqAw2BszNW557jQKWP8WHEANfV7ViRaUsT0Lj9arMrG+fTmC cGxnzOHRkVZKJPL95oGaqIT0cUMlf7bdALIRAep/70/fHHUJgOSO6+RTV8yj21ZP0KBG 8wiWHvDM4GgTFvxs8pqiD/WNHQXSMsAso98+QV/I3l4nBo3oylMaJJ0kpRJQLwApbQO5 JQEkCDJzztfrWGLwyZa/H4g3CUYB/wh9X09G3rnNuehIPqB2EeguYv2nkWfeG+O8/m86 YRbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694360724; x=1694965524; h=mime-version:user-agent:content-transfer-encoding:date:cc:to:from :subject:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7AGHvBbsgZIjtkwVxDa1Q2QCYM8GMdzhG57jmR9SvDM=; b=V2LPpTnbrTLJoW7ZfQbGWT5MPG3c2NlITg8Dw8Bn4lug1rJ89shRUrckePLqA/ZXWB bSxPl3TkidW1SteW5g42FEXzk6ymMet2nOHv8VjxxcziWZdOenPkNN6ixFKQW+WS5S0D kL7gjmfNWtQ3Nb+malWd+5KYCxT9I7XZoSLdJtTpFoMOyChVRzR8CyLCffWYZbBO5Bqz v2obA6v3wajkfv3LA935haYFpI5b0Q07/VlJk7o5nkN8VDFj5xEc5iYQrQX7aLmkASGE 16JBVpIFGWfv/021Q3y8xbRF/8kxXhTF63sx8YXgYRBjpZ2dpse+YNCxXtvkabW8G+2l xXlA== X-Gm-Message-State: AOJu0YxxzGa6Q3y0qkeic/aAK9b0iaENd267iYx6m8GqL3DbplKG3V/o c+KFbPIHzovw08aLe7yVokfrakmqv3q4o3VoA6c= X-Google-Smtp-Source: AGHT+IEVn+tEIFhxOv+PcpAl9zjg+NO97qYw5ykHw5L7ikCIce/yQkmHGUICDKzmTvtgeeYxH1OVHA== X-Received: by 2002:a54:418c:0:b0:3a7:366f:3b01 with SMTP id 12-20020a54418c000000b003a7366f3b01mr8925388oiy.33.1694360724618; Sun, 10 Sep 2023 08:45:24 -0700 (PDT) Received: from jeff-laptop.lan (c-98-45-81-55.hsd1.ca.comcast.net. [98.45.81.55]) by smtp.gmail.com with ESMTPSA id a23-20020a62e217000000b00686e00313easm4118032pfi.157.2023.09.10.08.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Sep 2023 08:45:24 -0700 (PDT) Message-ID: Subject: [16+] subscription can end up in inconsistent state From: Jeff Davis To: pgsql-bugs@postgresql.org Cc: Robert Haas Date: Sun, 10 Sep 2023 08:45:22 -0700 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk [ Moved from -security, where it was initially posted as a precaution. It was determined that the normal bug process is the right way to fix this. ] If I understand correctly, the security requirements for checking a non-superuser's connection string are that (a) the connection string itself specifies a password, thereby ensuring it won't come from a PGPASSFILE; and (b) checking PQconnectionUsedPassword() after the connection to ensure that the password was actually used for authentication, rather than some other method. If subpasswordrequired=3Dtrue, that causes (b) to be consistently checked for all connections. The checking of (a) is more complicated -- it's checked at CREATE/ALTER time, but only if the user is not a superuser. If the superuser gives the subscription to a non-superuser, or if the subowner loses their superuser status, then the subscription is in a weird state: subpasswordrequired may be true even if subconninfo doesn't have a password. That means that (a) is not being checked, and (b) is being checked. Repro (16+): Publisher: CREATE USER repl REPLICATION PASSWORD 'secret'; CREATE TABLE t(i INT); INSERT INTO t VALUES(1); GRANT SELECT ON t TO repl; CREATE PUBLICATION p1 FOR TABLE t; Subscriber (has a PGPASSFILE for user "repl"): CREATE USER u1; CREATE TABLE t(i INT); ALTER TABLE t OWNER TO u1; -- no password specified; relies on passfile CREATE SUBSCRIPTION s1 CONNECTION 'dbname=3Dpostgres user=3Drepl' PUBLICATION p1 WITH (enabled=3Dfalse); ALTER SUBSCRIPTION s1 OWNER TO u1; SELECT COUNT(*) FROM t; -- 0 \c - u1 -- still using passfile ALTER SUBSCRIPTION s1 ENABLE; SELECT pg_sleep(2); SELECT COUNT(*) FROM t; -- 1 ALTER SUBSCRIPTION s1 REFRESH PUBLICATION; It's also possible to get into this state by the superuser modifying a non-superuser's subscription. The purpose of the "password_required" option is to handle the case where a subscription was formerly owned by a superuser, or has been modified by a superuser. The docs say: "[password_required] ... This setting is ignored when the subscription is owned by a superuser... Only superusers can set this value to false." https://www.postgresql.org/docs/16/sql-createsubscription.html So a superuser changing the owner or modifying another user's subscription is a supported operation, and not just a superuser doing the wrong thing. (Perhaps the docs should be more clear on this point?) We could address this either by: * maintaining the invariant that if subpasswordrequired=3Dtrue, then subconninfo specifies a password; or * calling walrcv_check_conninfo() before each connection The former might raise some compatibility concerns with 15 (or questions about what we can do with the default for "password_required"), so right now the latter looks like the right fix. Regards, Jeff Davis