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 1oCTDy-0000gT-V3 for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Jul 2022 21:51:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oCTDv-0005AB-Vp for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Jul 2022 21:51: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 1oCTDv-00051f-KJ for pgsql-hackers@lists.postgresql.org; Fri, 15 Jul 2022 21:51:47 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oCTDp-0008Kd-4E for pgsql-hackers@postgresql.org; Fri, 15 Jul 2022 21:51:46 +0000 Received: by mail-pg1-x52f.google.com with SMTP id f65so5499170pgc.12 for ; Fri, 15 Jul 2022 14:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timescale.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=dHewatQhacuUNBz3OZJeog6GW2AYhnjE6HXpqOAbh+Q=; b=f1RqTmC4eVOzCscwrpJ40Q2zQ2em2XztSkMXTZqX6j5LzBeznG7OS98+whpwbolkN6 zXhXA4sj3pU8pcs+Mz/SfWvUu+5oX/gxtoX6yhsFugvk+Nm1iuCXxfvu/wh2HL5Sg3Wl GvqV94Z6Kv/K3EwNmZrwBXVQ3Bt+88jUXxD39BC7Uwh/a0Ad4tDts5dGvlIlBQ6e3aQC aUYAvpxVEUwgiwpa0lkqpE2AfMD2VZDrTI38msq8WIRf1K/WSSQf0jyz0i2c3AS620N9 ED6JoKLWBw1NNR+v9OOeSGw+eoriOwaA8GI8gEAoRKArU5EmyAQJFiO9QkLZ5+E0LD9F N8bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=dHewatQhacuUNBz3OZJeog6GW2AYhnjE6HXpqOAbh+Q=; b=Bl7xoezAMcf2x3nCi2bAyCOGRTwMSUGojMMJrlx/YB//ENe0+SHCa2N9TNSbm2oLuN S2He7SzU9E948vaR1v2ENiSlQSzSUDPtB7cziv2caMRVt7TgCwyKy7RdsMba8bdEy/F1 dp3VgCrArMcC5JvddbCXQWu5p5/kTYw/PxUX5X5FV51cPDOFSsK6Uw+XD+vjBtGpg+hD kYgT4TmhtRcmXy+KQm0t8CPTPuuwUWrZmgZXE4j0subDnrKohwebV6K84CPxexal0smD gedhuxKY9HUwbiM1tl0CuoW8FIWKk59IqvnUBQMwg5ALrenpJvgiJ95ELmofX/PjtUsw 9XmA== X-Gm-Message-State: AJIora+e6mz7BaBz0lnb02ce/9nXhDK1ZOZMuqU6Q2xztdiD0gdA25Og kCyRfneyJMRaCuf3g+nbaP/4ow== X-Google-Smtp-Source: AGRyM1tcFJWiA+AqzCziyLAR0MUZZLZtReQJI+kfidjItqMU1fUhyXJqonRkvqQ9AcA0R8S81/efiw== X-Received: by 2002:aa7:8c51:0:b0:525:4141:fe5e with SMTP id e17-20020aa78c51000000b005254141fe5emr15904938pfd.51.1657921899455; Fri, 15 Jul 2022 14:51:39 -0700 (PDT) Received: from [192.168.1.21] ([50.39.205.221]) by smtp.gmail.com with ESMTPSA id gg15-20020a17090b0a0f00b001ec932d7592sm3985261pjb.9.2022.07.15.14.51.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Jul 2022 14:51:39 -0700 (PDT) Message-ID: <1d3d62a0-2d7f-4592-bf76-ba59a77e61cc@timescale.com> Date: Fri, 15 Jul 2022 14:51:38 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] Log details for client certificate failures Content-Language: en-US To: Andres Freund Cc: Peter Eisentraut , "pgsql-hackers@postgresql.org" References: <2ef20161-e99d-a6ea-a36d-577843a2daae@enterprisedb.com> <49b48719-d6cf-9e03-fab3-e4505cf9d585@enterprisedb.com> <059e67f5-3769-24c8-f460-4e5d87af529a@enterprisedb.com> <0167a8c5-1754-9121-b994-0719a6493a21@timescale.com> <20220715191156.jecddreykoakdljm@awork3.anarazel.de> <20220715203500.vanqxt23bmufjais@awork3.anarazel.de> <2878aee8-a4a6-8078-9740-efe90fcf8328@timescale.com> <20220715211914.c5oasfknx2njndov@awork3.anarazel.de> From: Jacob Champion In-Reply-To: <20220715211914.c5oasfknx2njndov@awork3.anarazel.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/15/22 14:19, Andres Freund wrote: > On 2022-07-15 14:01:53 -0700, Jacob Champion wrote: >> On 7/15/22 13:35, Andres Freund wrote: >>> I don't know, but I don't think not caring at all is a good >>> option. Particularly for unauthenticated data I'd say that escaping everything >>> but printable ascii chars is a sensible approach. >> >> It'll also be painful for anyone whose infrastructure isn't in a Latin >> character set... Maybe that's worth the tradeoff for a v1. > > I don't think it's a huge issue, or really avoidable, pre-authentication. > Don't we require all server-side encodings to be supersets of ascii? Well, I was going to say that for this feature, where the goal is to debug a failed certificate chain, having to manually unescape the logged certificate names if your infrastructure already handled UTF-8 natively would be a real pain. But your later point about truncation makes that moot; I forgot that my patch can truncate in the middle of a UTF-8 sequence, so you're probably dealing with replacement glyphs anyway. I don't really have a leg to stand on there. > We already have pg_clean_ascii() and use it for application_name, fwiw. That seems much worse than escaping for this particular patch; if your cert's Common Name is in (non-ASCII) UTF-8 then all you'll see is "CN=?????????" in the log lines that were supposed to be helping you root-cause. Escaping would be much more helpful in this case. >> Is there an acceptable approach that could centralize it, so we fix it >> once and are done? E.g. a log_encoding GUC and either conversion or >> escaping in send_message_to_server_log()? > > Introducing escaping to ascii for all log messages seems like it'd be > incredibly invasive, and would remove a lot of worthwhile information. Nor > does it really address the whole scope - consider e.g. the truncation in this > patch, that can't be done correctly by the time send_message_to_server_log() > is reached - just chopping in the middle of a multi-byte string would have > made the string invalidly encoded. And we can't perform encoding conversion > from client data until we've gone further into the authentication process, I > think. > > Always escaping ANSI escape codes (or rather the non-printable ascii range) is > more convincing. Then we'd just need to make sure that client controlled data > is properly encoded before handing it over to other parts of the system. > > I can see a point in a log_encoding GUC at some point, but it seems a bit > separate from the discussion here. Fair enough. --Jacob