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 1u4ige-006Nqp-3E for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 15:59:00 +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 1u4igb-00CXxn-7R for pgsql-hackers@arkaria.postgresql.org; Tue, 15 Apr 2025 15:58:58 +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 1u4iga-00CXtv-KU for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 15:58:57 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u4igY-000DVu-25 for pgsql-hackers@lists.postgresql.org; Tue, 15 Apr 2025 15:58:56 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-7399838db7fso5606893b3a.0 for ; Tue, 15 Apr 2025 08:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1744732733; x=1745337533; darn=lists.postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=8QiABIKhoBMH2JNUF54wQvDJRPHgjfgoM8e6Q8nurmE=; b=M8Tyu4OjZrnRqt6TYKg/d5k0d9rs2v0EhsgXQnCvxCqgyBvgHDyq1L3MGdAENcIPVX vCUghTB53rls6KEG+D7YTKuNxwbUFpkCc97OOBrCkXSO9LdUBSFq3K7JFGLUJcZZZrh9 IWi7iX4X3p/Gxnuo4OWPVFKn1VsvLJFGKOb0s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744732733; x=1745337533; h=user-agent:in-reply-to: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=8QiABIKhoBMH2JNUF54wQvDJRPHgjfgoM8e6Q8nurmE=; b=BX1dLpDd4AF1z4h+cLXV0w+Ldp+4gDe6EtsRIMsQTrYu+aLN2qit/HBEoXyxgLBe7J 2deb1dakj3vabbN/C/Q6y8SjXEm+cP+SNdmvLtlgEPHi9/VYNTRfcwXAmMzcpnCm64fL LV5aZ4iPRTBISBqGQeAkubvTt4a6/HLWmkzi7bFpxJnS+zP0tf3TkVGHfFs/GYDXg9Kp w7TS+CvgkNKFhT6MNDj4Q3FWAqE1SRuL9QpoJMrJ/UtAoBQdKGlOciZy0rAqllmeJXHE s9/TSMuTRQHErMJL5cJLYFPeGh0/zrD02YAIr8YYcAQvucUPbWfuO1vYYc+vtY8vwfba 2HKA== X-Forwarded-Encrypted: i=1; AJvYcCUpZu7KN9Rqy8Ub3vNgHhy0SPTHcET+LM1aAvytMi5wbdAsuSB4Yrjrnqa69n8w3FxyB1N7fimgqqoFGd/G@lists.postgresql.org X-Gm-Message-State: AOJu0Ywhw4VkdyaCd+8vHZ2yTtrQC9+U6UJ4yA89QGuGbslMImwmhdyy rYbgu/e/OJ7w9XmbvJ9H5cFdZ2jkzkZrcp3T1j1BH8ceH0h/iOlH0ewxRPXr0g== X-Gm-Gg: ASbGncuVKoY5lhZ7+nDi0469ZfjUzVHHU7sR6c0NgrXPlS6zqVqwI/qVbg0sSR9IogT VtbCHIlP8dyO/V1yZFIfMeprhindnuzCHU0MBVKpfFA5+UtzgSy4+pkjwjn8YeRgc9JNIBlZWPT mOiQwFchdmCDVQSqQdxaFiA8p1wTV6v0dQTkGfGPCZNZtWIAov0KG04VMQVUMotaX8rsok8LyBj 2Y9jAdvePo+vwNgrG3x/LNoVAgyjALvbCfunA685nD7+DZnrzXq9yXVUwuNjsFM6Kx3WRN3+pKE QNqCBQwNNh3T88D5qVeXxSc9fsGbXbvQEYdScw== X-Google-Smtp-Source: AGHT+IGbK26VmTaS9M9PUPVXkXlQ4JlAA7Fbl9KD/I5iA3w01RcgCHEAzKQlCI1sF4LCSY+KzloBlQ== X-Received: by 2002:a05:6a00:4b16:b0:728:f21b:ce4c with SMTP id d2e1a72fcca58-73c1f92f43dmr15388b3a.5.1744732733330; Tue, 15 Apr 2025 08:58:53 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73bd2198ac2sm8680908b3a.8.2025.04.15.08.58.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Apr 2025 08:58:52 -0700 (PDT) Date: Tue, 15 Apr 2025 08:58:50 -0700 From: Noah Misch To: Laurenz Albe Cc: Tom Lane , Pavel Stehule , pgsql-hackers@lists.postgresql.org Subject: Re: Wrong security context for deferred triggers? Message-ID: <20250415155850.9b.nmisch@google.com> References: <66021ca9d81c4e1a22b6c417659b05424e130f27.camel@cybertec.at> <6bca669972ef0d4a665fa83c5b751ab116324f8f.camel@cybertec.at> <2653121.1730737337@sss.pgh.pa.us> <51386e72c47d922ef68eaa67451a52dc3f569843.camel@cybertec.at> <3944969.1737570355@sss.pgh.pa.us> <3e4c8fe7adce2e3956e01bae8f1754830bd2d2bf.camel@cybertec.at> <201480.1737653448@sss.pgh.pa.us> <67338f5d321ae6a4bae646e04b9fe0a1f27dd27c.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67338f5d321ae6a4bae646e04b9fe0a1f27dd27c.camel@cybertec.at> 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 Thu, Jan 23, 2025 at 07:28:19PM +0100, Laurenz Albe wrote: > On Thu, 2025-01-23 at 12:30 -0500, Tom Lane wrote: > > Pushed with some cosmetic adjustments > > Thank you! commit 01463e1 wrote: > +NOTICE: I am regress_groot Let's not incur trivially-avoidable trademark risks (https://google.com/search?q=%22i+am+groot%22) in the source tree. > --- a/doc/src/sgml/trigger.sgml > +++ b/doc/src/sgml/trigger.sgml > @@ -129,6 +129,10 @@ > In all cases, a trigger is executed as part of the same transaction as > the statement that triggered it, so if either the statement or the > trigger causes an error, the effects of both will be rolled back. > + Also, the trigger will always run in the security context of the role > + that executed the statement that caused the trigger to fire, unless > + the trigger function is defined as SECURITY DEFINER, > + in which case it will run as the function owner. Phrase "the role that executed the statement" doesn't match what happens if the role changes mid-statement. Example of a statement that does so: select set_config('role', rolname, true), current_user from pg_authid; The term "security context" doesn't otherwise appear in doc/. I would just change "run in the security context of the role" to "run as the role". That's simpler and less likely to create an impression that this stops attacks.