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 1okgpJ-000816-An for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Oct 2022 07:15:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1okgpH-0005OB-4O for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Oct 2022 07:15:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okgpG-0005O2-Pq for pgsql-hackers@lists.postgresql.org; Tue, 18 Oct 2022 07:15:46 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1okgpA-0000Ec-6x for pgsql-hackers@lists.postgresql.org; Tue, 18 Oct 2022 07:15:45 +0000 Received: by mail-wr1-x430.google.com with SMTP id j16so21993421wrh.5 for ; Tue, 18 Oct 2022 00:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=x+lGdmyKt4GI4Gb6q0PuDsbUjNE+IO6E+LwVm3zgYbc=; b=otid6bXlNSk1s8IEYBr+uiOG//DeCzYevp2cvDhITPKJ6n1bPtMWznfIhHZY9XgEAI am2PjzbGCCEdkOivhVyjfNnQODAND8pGXT2OTcTegvGd8TX+MFz95zMWZkzLyPgfMdDf b6eZQ91tikziHD4VqDC8GXSDcDDYjadQsBQ/bRHMcR4tEkGUiQmoW9GlNiXZ0RZJb7W6 rP1Fh417ZW19bOxXA4sWDWx788zglLwBBrID8y1psRlgFW1gUNsODaDSbn7Elp9eArPD N5aluBpBqlMhaS4ioW5Zk2LG+mNg0RpOk0Aahkq+hHUw5zrOAhDoYH6qKjKYCqbGuzho WsdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x+lGdmyKt4GI4Gb6q0PuDsbUjNE+IO6E+LwVm3zgYbc=; b=AO75BUEycLe4uNIDxfq3DHZ2z9Ea/kVR/2wcjb2Tj12yooXz28jOvY1A/nRNr4dKLs OcyuC8TVBw9/z/rNxnP9Q2VZCJLvjJUOg4ycjyns40cngfvGfHuQQ7w6414Bnwh/jf3n IRrjzUQaaC4MdAzFwIl88yGo6aubGrsUp47YVlMxvrvnK5QDPsbKxh5FkamZQAE8Vafs 0OpKn1jpJ+EZl/GxTG30GRbP1IM4yjA5+0pp27Kf5twX6K1CfRbiM5lyrQOG9aa8dp2C WIcDiMxc6EtIRwsuvXjGQUP+ncy4jqv2DFr7YYkXtEjcAsVUq8Ry6uFiiVD41jbK54nj JQew== X-Gm-Message-State: ACrzQf3kBf5qFcOEy1NlNCp/Dr2Jb3SEWpsIgeQewZ6c9G3pka12dX6p j1U2L984m9X3+AvT0fBKHWQ= X-Google-Smtp-Source: AMsMyM6aQaJvVJG/ahOvpYZlVrcdicJhbf8dtmI6CZMv/1GpcKzY2skeOzvUopT/EA3wfuGgbcjpbg== X-Received: by 2002:a5d:4302:0:b0:232:ce6b:40c0 with SMTP id h2-20020a5d4302000000b00232ce6b40c0mr863718wrq.415.1666077338706; Tue, 18 Oct 2022 00:15:38 -0700 (PDT) Received: from [192.168.7.201] ([54.239.6.185]) by smtp.gmail.com with ESMTPSA id x17-20020adff0d1000000b00231ed902a4esm10314369wro.5.2022.10.18.00.15.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Oct 2022 00:15:38 -0700 (PDT) Message-ID: <5000f886-e640-b284-fa64-5cef28b6d272@gmail.com> Date: Tue, 18 Oct 2022 09:14:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: Patch proposal: make use of regular expressions for the username in pg_hba.conf To: Michael Paquier Cc: Tom Lane , Jacob Champion , PostgreSQL Hackers References: <572017.1663646973@sss.pgh.pa.us> <607af3c9-e45d-3941-41a2-d21065d6594b@gmail.com> Content-Language: en-US From: "Drouvot, Bertrand" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 10/18/22 7:51 AM, Michael Paquier wrote: > On Mon, Oct 17, 2022 at 07:56:02PM +0200, Drouvot, Bertrand wrote: >> On 10/14/22 7:30 AM, Michael Paquier wrote: >>> This approach would not stick with >>> pg_ident.conf though, as we validate the fields in each line when we >>> put our hands on ident_user and after the base validation of a line >>> (number of fields, etc.). >> >> I'm not sure to get the issue here with the proposed approach and >> pg_ident.conf. > > My point is about parse_ident_line(), where we need to be careful in > the order of the operations. The macros IDENT_MULTI_VALUE() and > IDENT_FIELD_ABSENT() need to be applied on all the fields first, and > the regex computation needs to be last. Your patch had a subtile > issue here, as users may get errors on the computed regex before the > ordering of the fields as the computation was used *before* the "Get > the PG rolename token" part of the logic. Gotcha, thanks! I was wondering if we shouldn't add a comment about that and I see that you've added one in v2, thanks! BTW, what about adding a new TAP test (dedicated patch) to test the behavior in case of errors during the regexes compilation in pg_ident.conf and pg_hba.conf (not done yet)? (we could add it once this patch series is done). > While putting my hands on that, I was also wondering whether we should > have the error string generated after compilation within the internal > regcomp() routine, but that would require more arguments to > pg_regcomp() (as of file name, line number, **err_string), and that > looks more invasive than necessary. Perhaps the follow-up steps will > prove me wrong, though :) I've had the same thought (and that was what the previous global patch was doing). I'm tempted to think that the follow-steps will prove you right ;-) (specially if at the end those will be the same error messages for databases and roles). > > A last thing is the introduction of a free() routine for AuthTokens, > to minimize the number of places where we haev pg_regfree(). The gain > is minimal, but that looks more consistent with the execution and > compilation paths. Agree, that looks better. I had a look at your v2, did a few tests and it looks good to me. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com