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 1raJs3-009CAx-PW for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 18:20:35 +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 1raJs2-007r8h-DA for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Feb 2024 18:20:34 +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 1raJs1-007r8Z-Vs for pgsql-hackers@lists.postgresql.org; Wed, 14 Feb 2024 18:20:34 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1raJrz-006kUO-3h for pgsql-hackers@postgresql.org; Wed, 14 Feb 2024 18:20:32 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e0507eb60cso55082b3a.3 for ; Wed, 14 Feb 2024 10:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1707934830; x=1708539630; 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=o5jYcyLrYVjbpO/VZsl4KfVzFzrMEAeBxbGsIjGratk=; b=TS897swvM0Ug2uu93Y3fNJSlBx350PZXI+4kXFTq7ww1EMnuxVvDKAZVlFeGTjt0Dc 8Amww7tas/qWyYWxIyr0C0ymbsWin8PrjsEP5ASbTvV6HG409CkekMXCzNdWCv3R75ix HagbjXORGjWjz9MSe1IiYOs0MiN+y/SvmKpwCTy5loufYARookST4Dpep2yjI5fy56Dr WGQRxy46wTLebrVqjx+L6olv+AkO7CjVYuwrzN6tqGZMQpPaTVFNEtQYD0p69nziUJ6V F0vSArSY8ZrvH6WX5gH6Y/XwBVTcfKBCLacEfmH8Mgzj7a3hpqg6OO9lNhGuVP4QOwky 280w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707934830; x=1708539630; 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=o5jYcyLrYVjbpO/VZsl4KfVzFzrMEAeBxbGsIjGratk=; b=Bp/6uj56o8ZVALBWnheSw48yxlXGbXSJ8XTkAeqkWBaqzyU92yZX+kctnTkMMOK7Ia g+WlkhEBs4N1HJklhiSWNESXvYHpgUz0ryrYPahGZ6TGz7fsDDsirnLphdfvdO6mJkhg gr5o8reUE7Fzbk6BITV/asRji6lVYwC5foQeXRjpKH+4MshIA2qgivM3Wyg/lDQrhud2 FfVKlFDYWEVGc5c7QDEKkEam3fScypoVmTiyHpUoNs6vLwEXVX1MD4nLThOfZVCDJJPs Rb/UOG9UK8tdW9uiMtGCjkoZC/PPw0xp5LMfZA1XGJt2pkXrgrJn4ECOM77A0Z5jKwDP xWCQ== X-Gm-Message-State: AOJu0Yxv0iFyQQv6fM/zmUHDZw0w7wUoR0UcNAJ+kIwpJz4HfB3IXo0X P5JI5IcA1ioJM8v2TA8zY0y+F1AGP3wttUvl8b+8XnPE65xqyEfpAZerVgATTBzwjh9HqQ0xp4Y = X-Google-Smtp-Source: AGHT+IEdWQKFMOel1+XbiLdtF4RCS1YBJt5+MkELieka4P/pLX3CGdWWpiryVIdSEhkEnprOlnVDxQ== X-Received: by 2002:aa7:86cd:0:b0:6dd:d1fa:ff17 with SMTP id h13-20020aa786cd000000b006ddd1faff17mr3184414pfo.32.1707934829890; Wed, 14 Feb 2024 10:20:29 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVErdbAxJ6TvheqlsQsMiZba1QKYHPsoS6P2Ssen9tUKZtje5W2vYXKQNl/TWtAuixI0scR/v85JUhqQrzdGz2jSEZLi3HVqKbch3sn7Wymn5NNLQrLTKS8XmGCwQPywQ== Received: from jeff-laptop.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id h5-20020a056a00230500b006e044e376adsm6739494pfh.166.2024.02.14.10.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:20:29 -0800 (PST) Message-ID: Subject: MAINTAIN privilege -- what do we need to un-revert it? From: Jeff Davis To: pgsql-hackers@postgresql.org Cc: Joe Conway , Robert Haas , Nathan Bossart Date: Wed, 14 Feb 2024 10:20:28 -0800 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 The MAINTAIN privilege was reverted during the 16 cycle because of the potential for someone to play tricks with search_path. For instance, if user foo does: CREATE FUNCTION mod7(INT) RETURNS INT IMMUTABLE LANGUAGE plpgsql AS $$ BEGIN RETURN mod($1, 7); END; $$; CREATE TABLE x(i INT); CREATE UNIQUE INDEX=C2=A0x_mod7_idx ON x (mod7(i)); GRANT MAINTAIN ON x TO bar; Then user bar can create their own function named "bar.mod(int, int)", and "SET search_path =3D bar, pg_catalog", and then issue a "REINDEX x" and cause problems. There are several factors required for that to be a problem: 1. foo hasn't used a "SET search_path" clause on their function 2. bar must have the privileges to create a function somewhere 3. bar must have privileges on table x There's an argument that we should blame factor #1. Robert stated[1] that users should use SET search_path clauses on their functions, even SECURITY INVOKER functions. And I've added a search_path cache which improves the performance enough to make that more reasonable to do generally. There's also an argument that #2 is to blame. Given the realities of our system, best practice is that users shouldn't have the privileges to create objects, even in their own schema, unless required. (Joe made this suggestion in an offline discussion.) There's also an arugment that #3 is not specific to the MAINTAIN privilege. Clearly similar risks exist for other privileges, like TRIGGER. And even the INSERT privilege, in the above example, would allow bar to violate the unique constraint and corrupt the index[2]. If those arguments are still unconvincing, then the next idea is to fix the search_path for all maintenance commands[3]. I tried this during the 16 cycle, but due to timing issues it was also reverted. I can proceed with this approach again, but I'd like a clear endorsement, in case there were other reasons to doubt the approach. Regards, Jeff Davis [1] https://www.postgresql.org/message-id/CA+TgmoYEP40iBW-A9nPfDp8AhGoekPp3aPDF= zTgBUrqmfCwZzQ@mail.gmail.com [2] https://www.postgresql.org/message-id/fff566293c9165c69bb4c555da1ac02c63660= 664.camel@j-davis.com [3] https://www.postgresql.org/message-id/e44327179e5c9015c8dda67351c04da552066= 017.camel@j-davis.com