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 1sRtHU-001rYA-UL for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 12:52:16 +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 1sRtHT-00DxiA-Fr for pgsql-hackers@arkaria.postgresql.org; Thu, 11 Jul 2024 12:52:15 +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 1sRtHT-00Dxi0-5m for pgsql-hackers@lists.postgresql.org; Thu, 11 Jul 2024 12:52:15 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRtHQ-001YYX-DF for pgsql-hackers@postgresql.org; Thu, 11 Jul 2024 12:52:14 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-375daa47685so3059815ab.0 for ; Thu, 11 Jul 2024 05:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1720702330; x=1721307130; darn=postgresql.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QQrgACG+ipUTLQjfxpRmQcCORMXHPFaAJnh2SQb0EJo=; b=Uf/j42zhmm/TBSBhrI1s2muRErDjiTUMXdudFrHrO8fScB14PXZ6PMXXW9D+CDCLyc WOYHoK2IafTV8D/p/emrZnrT4xu5ygKHWuLo1bj+Lx2Ke98he75rMBKU9U7Vijf/b7C3 fayTtgxfZauFNAhhlqf1gJCj/+GcdIN/2XBME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720702330; x=1721307130; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QQrgACG+ipUTLQjfxpRmQcCORMXHPFaAJnh2SQb0EJo=; b=dQboTAnfc5tH+tpklFgJRK2W0oT+QmBz9bcTke1+PaJ+RTlS5LDly+rIv7JiIrjIwa qMUH9x4vDr9vezzzq3zTKyMfQQ7LE3MidKHq4bLSFLc9l4zFWWifGaLUnD9DJl3s3l1p n44x7ZuxTkLJnb8TCd59Z/GF4zKpA6U2VrNCmwKOk76PfitviApHEfH5uJuc1xqHKFic Ncwk0j9Ona4nL90eAQZbxHxnnqGJwc3AJ96LB71PIb+jjWNvYqp9gDQd891i2TPaRIJJ 7R8oPC9SKPr03FidwiQ8m19JMWINkKiH6Uf9Xv3MLz//Wc6JHiQ4l1ZjYuZA5qxZ+qFn 7dNQ== X-Forwarded-Encrypted: i=1; AJvYcCWEF+o6AjuFLp38UQTdjB6ZUDcITr5R+MswhZ/ORk5RwFUYddsvB+XXytr2kLrt93BPcUNy53AfigOp8O0WNk2cO7lT1qnJXdAVs9aF X-Gm-Message-State: AOJu0YyAaGGdpjXf/4d6o0l5WXdDJMVg1eBqSLp32ZWXL3c6ihsZ/ZE+ ZOVxL1yc/rRCPhRJlnppAwcw2vTvf0TM1lEpWuCdze2qA3WUtau+wb0SBIUuww== X-Google-Smtp-Source: AGHT+IFSztzZQzyE/3E/I4YCqcFKMhpyTfvvlKX4S3C4Spn9niGbSjEr0yV4CgwOoigtGNUDpOj8rQ== X-Received: by 2002:a05:6e02:12e7:b0:375:92ed:254a with SMTP id e9e14a558f8ab-38a577e8dd7mr94571395ab.18.1720702330471; Thu, 11 Jul 2024 05:52:10 -0700 (PDT) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-77d603fa73csm3662839a12.21.2024.07.11.05.52.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2024 05:52:09 -0700 (PDT) Date: Thu, 11 Jul 2024 05:52:07 -0700 From: Noah Misch To: Jeff Davis Cc: Michael Paquier , Nathan Bossart , pgsql-hackers@postgresql.org, Joe Conway , Robert Haas Subject: Re: MAINTAIN privilege -- what do we need to un-revert it? Message-ID: <20240711125207.98.nmisch@google.com> References: <20240214190226.GA373350@nathanxps13> <4d497d82e4516037dc1082d5a62d199ea00d62e7.camel@j-davis.com> <20240223213055.GA1805646@nathanxps13> <196d1c86d43a147e777bb74159774f255dbe73e3.camel@j-davis.com> <20240228165523.GA2435539@nathanxps13> <31ae1bf73e8a1dae3ee7ef2dd43a9bbda1e1ab86.camel@j-davis.com> <20240630222344.db.nmisch@google.com> <23fac3b2a722373a52b92a12ee0f500821450f97.camel@j-davis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <23fac3b2a722373a52b92a12ee0f500821450f97.camel@j-davis.com> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Jul 09, 2024 at 05:47:36PM -0700, Jeff Davis wrote: > On Tue, 2024-07-09 at 15:20 +0900, Michael Paquier wrote: > > On Sun, Jun 30, 2024 at 03:23:44PM -0700, Noah Misch wrote: > > Hmm.  Is RestrictSearchPath() something that we should advertise more > > strongly, thinking here about extensions that call NewGUCNestLevel()? > > That would be really easy to miss, and it could have bad > > consequences. > > I know that this is not something that's published in the release > > notes, but it looks like something sensible to have, though. > > The pattern also involves SetUserIdAndSecContext(). Perhaps we could > come up with a wrapper function to better encapsulate the general > pattern? Worth a look. usercontext.c has an existing wrapper for a superuser process switching to an untrusted user. It could become the home for another wrapper targeting MAINTAIN-relevant callers. > > > While "not necessary for security", ExecCreateTableAs() should do > > > it for the > > > same reason it calls NewGUCNestLevel(). > > > > +1. > > Do you have a suggestion about how that should be done? > > It's not trivial, because the both creates the table and populates it > in ExecutorRun. For table creation, we need to use the original > search_path, but we need to use the restricted search_path when > populating it. > > I could try to refactor it into two statements and execute them > separately, or I could try to rewrite the statement to use a fully- > qualified destination table before execution. Thoughts? Those sound fine. Also fine: just adding a comment on why creation namespace considerations led to not doing it there.