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 1lAjGW-0000XK-GO for pgsql-general@arkaria.postgresql.org; Sat, 13 Feb 2021 00:58: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 1lAjGT-0002Pe-QM for pgsql-general@arkaria.postgresql.org; Sat, 13 Feb 2021 00:58:25 +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 1lAjGT-0002PR-Gr for pgsql-general@lists.postgresql.org; Sat, 13 Feb 2021 00:58:25 +0000 Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lAjGP-0003QR-CR for pgsql-general@postgresql.org; Sat, 13 Feb 2021 00:58:24 +0000 Received: by mail-qk1-x72e.google.com with SMTP id r77so1383549qka.12 for ; Fri, 12 Feb 2021 16:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:references:from:subject:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=P+CdTapoTbIxHjMabdxyYlZUV2ne2+l9/uwPLlv36S8=; b=AJfJD3ZKe/jqvrk6HQInclJ95yzA8CQGejoE7OsOcQY2LtzB9iASMKCRDre4NfzKAM JIsL/35RKytVfMSdk0T6mRWtngvjOOFF/IHvXCGaUEiA7bVb5mkoPrjNCqPgO4WVpYl7 pqpImdOBFyKdSY5+/tOztQP0HaqIkqEL3pQsGid963BAjh3ZwptYalpZvxhGSVPEG6rw 1P6lK5FDu9mftrzf01bX4o2tUL6lex8Txw0S1UwfaW6hPKqS3gSkmpSLQNxX8KmClH96 mYFxHk6lGaN0PrJ+A5EuMx2BdE0/P38y4wW1lVf5GiEEGZYGsjQYbjdYncYoo+Na/MPv JXZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=P+CdTapoTbIxHjMabdxyYlZUV2ne2+l9/uwPLlv36S8=; b=baPvJ0H7qTgEe4wPkiogCajjwBpD8Knr4bOszAXkU0ht8oraMII5zrKZqq12pPcXhK bMDzlwrGdE9KJxiry4CWsHHvEMVh9KYmzAFtfIzTUxC0Atx2dX1v+DF7xObKFtw3F7BM vcWVEeBLqF+dEgR/g6ajQcmtWRGCxYQ3Kgm7+wZUL/f/5QQkpDkxu+aUIDYYNNLFjauh 1SpnxzFPZqCCNFz3E/uoSemdR51YZPhDNN3/vbNt75YQS2Io6iiYodOgdUpIAUFTadvy I93ewTHChu8zEOphrt8GsJMJGcbrbV1cNxTo1SEAtGwhfGaJHVKztCg+eSN96o4BfNmX tsHA== X-Gm-Message-State: AOAM531tEI3WAZaj3tCaxNk9idwWYsEsWws8hlDZXz5i8bsfJQJxXIPH KuOl+AJ27cDOUh1F+4xSTJY= X-Google-Smtp-Source: ABdhPJxH1lPQEJwXwe1Y7IcgXydQ1K/71otzs7hxHUzOQ1pesFufh22odl9lk97vW737QPI/Uk7eug== X-Received: by 2002:a37:83c3:: with SMTP id f186mr4739072qkd.185.1613177899476; Fri, 12 Feb 2021 16:58:19 -0800 (PST) Received: from [192.168.67.200] (dsl-66-36-157-191.mtl.aei.ca. [66.36.157.191]) by smtp.gmail.com with ESMTPSA id o10sm6788927qtg.37.2021.02.12.16.58.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Feb 2021 16:58:19 -0800 (PST) To: "Zwettler Markus (OIZ)" , Laurenz Albe Cc: "pgsql-general@postgresql.org" , Tom Lane References: From: Thomas Guyot Subject: Re: AW: ldap connection parameter lookup Message-ID: <78668471-cc86-95ab-ee08-407d41d8afe6@gmail.com> Date: Fri, 12 Feb 2021 19:58:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021-01-22 10:22, Zwettler Markus (OIZ) wrote: >> >> On Fri, 2021-01-15 at 14:09 +0000, Zwettler Markus (OIZ) wrote: >>> I want to use ldap to lookup the connection parameters: >>> https://www.postgresql.org/docs/12/libpq-ldap.html >>> >>> or is there also some kind of generic variant like this (meaning lookup connection >>> parameters for the database name I tell you somehow): >>> >>> [${PGDATABASE}] >>> ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=${PGD >>> ATABASE}) >> >> I proposed something like that a while ago: >> https://postgr.es/m/D960CB61B694CF459DCFB4B0128514C2F3442B%40exadv11 >> .host.magwien.gv.at >> but it was rejected. >> >> Perhaps you could come up with a better version. >> > I'm afraid not. My proposal is as close to yours. > > Anyway. PostgreSQL needs some kind of generic central name resolution service. > > It is not feasible to do static entries per database in a large environment with hundreds of clients. > > It's also not feasible to have ordinary endusers have to handle this static entry by themselves. Hi, I think the error here is trying to pass parameters defined in the block key to the ldap parameter. That's rather hackish and requires proper understanding of all possible implications, and the uses is rather limited (what if you need multiple LDAP parameters?) What if we have something like: [ldap] ldap://ldap.mycompany.com/dc=mycompany,dc=com?description?one?(cn=${PGDATABASE}) Basically, allow any environment variable in the ldap queries, including both coming from the user/application and setting some standard ones like PGUSER, PGHOST, PGDATABASE for parameters passed on the command line/api call (whichever takes precedence). You then connect with the ldap service, pass any required option as env or parameters (here the database name), and let postgresql interpolate it in the query (of course we also need to properly escape the string in ldap uri...). Unset env variables would be considered an error. The only possible caveat I see is that we could have to allow escaping the $, even though I don't think there's any realistic possibility for it to be used on the ldap url (and can it be url-encoded? in which case it would be already solved...) Regards, -- Thomas