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 1ojK72-0006T4-Vd for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Oct 2022 12:48:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojK71-0007xz-M7 for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Oct 2022 12:48:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojK71-0007xq-Ak for pgsql-hackers@lists.postgresql.org; Fri, 14 Oct 2022 12:48:27 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ojK6w-00050W-HI for pgsql-hackers@lists.postgresql.org; Fri, 14 Oct 2022 12:48:26 +0000 Received: by mail-wm1-x32c.google.com with SMTP id n9so3007948wms.1 for ; Fri, 14 Oct 2022 05:48:22 -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=/s5RFWOXVFG5y6wPkTxNiIo125W/hRpg9E3mRqEBsug=; b=Ajvb4Mqid0tNqxyDuOEaHYy0rFY6/sNBzh0VWZHqzVE6QHEwQ0KsUhzEqvhSIykDp6 jQcihAkOXAIO/g559EEbfi5IfRiZ37RItmSyPAjFmHuuHsi7C3xk9TUvrNQkSb549EDR aCuI+09Pi8QmVND0fBGmxatXidtcVzIi18w923DIIXRKuxMTZmgY5WduuOF6gsz5gnbY 66BLyFwLlHj/WQGNwO033ofzt07cRF9JbTbNWM14PCHgP+ya4qetwy/bgwCzEXC77wAh mWXJ6mvK90hk7k2cxxSDfofdzSpPHCvUnpPuSioOYYsHUTmvTwEWUSZRvHCmEZTjdmVV wm4A== 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=/s5RFWOXVFG5y6wPkTxNiIo125W/hRpg9E3mRqEBsug=; b=TY/BD7LZuqGA+e3zLwqCtpitKzea/fntC03aHFnBPF8j/3j3DAQzqURBOC8yuH6oQP LY6JgjiMql03/KbBDdB28Z5QEeGHQwvAr9JxThBoxrRqLyRrN9AT/nv8524wJJ7W9Ovk q+Xh5XwjRux1hhnnKoTzbglePALlSbPngqRhPJ5yjswWNZBXjTZawaWoMz5K/K3BLp8j 8xJa8XbeNmv/GfQ+EjOGH3VtsvUcu/yLQ3rB0SgaFMfXba1RFMVRtKufUibKzWtXlUOe mhPm7OWiXaScYsf/PEBE9pbWNQC9duN4/ZIl+ExgvBumeK8f1oKAv5vLYrOtrPmMVgpD sCQA== X-Gm-Message-State: ACrzQf0DN2bLwzN7Tx3UKiJGTxgmZKj9PjfFxzayl+Jccr+OQwEH+J4y oJszbWxZdLVpctM+UGSNGAs= X-Google-Smtp-Source: AMsMyM6C9B9fN6JDqJu4WgCvEhKtWCwMdbnoxVpPL63lU3CZFWIBkbPFPw6G5Ebkg16jPY5NaPIqvg== X-Received: by 2002:a7b:cd14:0:b0:3c6:bf44:770d with SMTP id f20-20020a7bcd14000000b003c6bf44770dmr3470346wmj.35.1665751701155; Fri, 14 Oct 2022 05:48:21 -0700 (PDT) Received: from [192.168.4.65] ([54.239.6.185]) by smtp.gmail.com with ESMTPSA id 62-20020a1c0241000000b003a3170a7af9sm2166156wmc.4.2022.10.14.05.48.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 14 Oct 2022 05:48:20 -0700 (PDT) Message-ID: <1a7c54f7-d06b-1fa4-f356-19a229ffb986@gmail.com> Date: Fri, 14 Oct 2022 14:47:04 +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/14/22 8:18 AM, Michael Paquier wrote: > On Fri, Oct 14, 2022 at 02:30:25PM +0900, Michael Paquier wrote: >> First, as of HEAD, AuthToken is only used for elements in a list of >> role and database names in hba.conf before filling in each HbaLine, >> hence we limit its usage to the initial parsing. The patch assigns an >> optional regex_t to it, then extends the use of AuthToken for single >> hostname entries in pg_hba.conf. Things going first: shouldn't we >> combine ident_user and "re" together in the same structure? Even if >> we finish by not using AuthToken to store the computed regex, it seems >> to me that we'd better use the same base structure for pg_ident.conf >> and pg_hba.conf. While looking closely at the patch, we would expand >> the use of AuthToken outside its original context. I have also looked >> at make_auth_token(), and wondered if it could be possible to have this >> routine compile the regexes. 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.). So with all that in mind, it feels right to >> not use AuthToken at all when building each HbaLine and each >> IdentLine, but a new, separate, structure. We could call that an >> AuthItem (string, its compiled regex) perhaps? It could have its own >> make() routine, taking in input an AuthToken and process >> pg_regcomp(). Better ideas for this new structure would be welcome, >> and the idea is that we'd store the post-parsing state of an >> AuthToken to something that has a compiled regex. We could finish by >> using AuthToken at the end and expand its use, but it does not feel >> completely right either to have a make() routine but not be able to >> compile its regular expression when creating the AuthToken. > > I have have sent this part too quickly. As AuthTokens are used in > check_db() and check_role() when matching entries, it is more > intuitive to store the regex_t directly in it. Yeah, I also think this is the right place for it. > Changing IdentLine to > use a AuthToken makes the "quoted" part useless in this case, still it > could be used in Assert()s to make sure that the data is shaped as > expected at check-time, enforced at false when creating it in > parse_ident_line()? I agree, that makes sense. I'll work on that. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com