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 1npDZj-0002RW-AP for pgsql-general@arkaria.postgresql.org; Thu, 12 May 2022 18:30:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1npDZg-0000zE-1M for pgsql-general@arkaria.postgresql.org; Thu, 12 May 2022 18:30:08 +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 1npDZf-0000z4-LJ for pgsql-general@lists.postgresql.org; Thu, 12 May 2022 18:30:07 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1npDZb-0007jH-7I for pgsql-general@lists.postgresql.org; Thu, 12 May 2022 18:30:06 +0000 Received: by mail-pf1-x42b.google.com with SMTP id bo5so5575851pfb.4 for ; Thu, 12 May 2022 11:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zwlS3BlW9GDP7+dZrsHtLfvUx0vRl511CtJsxaWrrwQ=; b=UgZBFsPb2+Sbk2+3eAKZSYIBpS5w4X6JaZFXY1+V8kNi5FLCFr8qaleocwbKvVmqEq fIRgS418NOfplvJWH8Z7z1yPJ/oxHvJCc/d6XY2ccwv3xmEc8OqLWg7jksmzOUK5dNK+ Wij2KxV1Y22KZpwdzX/QsfnA6V1uHslb8acqs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=zwlS3BlW9GDP7+dZrsHtLfvUx0vRl511CtJsxaWrrwQ=; b=4fRe0yS+wihDFsZKff8y4pkdqB2LyvqjcEH+1zFAsOKvlBZdHSbNEpvP6XxLwtDfTA Mm8Hlb9/6TrLFdwRIo6TeWLAr+H5UcL9IF4TkNn5y8GeSvkezw46nT8uTX/iV5Bih5+G pkH0Dvp/SKUWAAJm2Q7O5k3Zpu4dPidZ4ClQ9jS/BfzORdPGJQxHDT/eEPsf8AtC8hhz U0LWVgU4jMxhH6bfaP/jH7HxSmRVxj5o+U10Miw33kc3to7n0tHVJEGLRccrv+jnTZkD kRAI1khxNOftmAwcY4xTPk1OLPUTCvVDgqS2sjMaoeABcxdw+Mw+cJXfrKiRh6zFu44K axlQ== X-Gm-Message-State: AOAM530s4QTa6zmiGsqpIGbvp/3N9Nbc9at+oLGGt11qhaGva9qxMuTX ovvgQ1HcPQPSdc4Z+i5Z9NbTcg== X-Google-Smtp-Source: ABdhPJwYzCXXezi0WyNVgrFepKUlrWMjVxzjQKyG04M6xcB8GWuF4UTFJ0LAGew7pUkbrIocAWWHqg== X-Received: by 2002:a63:e146:0:b0:39d:1b00:e475 with SMTP id h6-20020a63e146000000b0039d1b00e475mr710498pgk.537.1652380202121; Thu, 12 May 2022 11:30:02 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:f922:1fb2:3b49:3795]) by smtp.gmail.com with ESMTPSA id u15-20020a63df0f000000b003c14af5061bsm41210pgg.51.2022.05.12.11.30.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2022 11:30:00 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Restricting user to see schema structure From: Bryn Llewellyn In-Reply-To: Date: Thu, 12 May 2022 11:29:59 -0700 Cc: Adrian Klaver , pgsql-general list Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Neeraj M R X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > adrian.klaver@aklaver.com wrote: >=20 >> neerajmr12219@gmail.com wrote: >>=20 >> Is there anyway that we can restrict a user from seeing the schema = structure. I can restrict the user from accessing the data in the schema = but the user is still able to see the table names and what all columns = are present in them. >=20 > No. Here=E2=80=99s something that you can do, Neeraj. But you have to design = your app this way from the start. It'd be hard to retrofit without a = re-write. Design (and document the practice) to encapsulate the database = functionality (i.e. the business functions that the client side app must = perform) behind an API exposed as user-defined functions that return = query results for SELECT operations and outcome statuses (e.g. = "success", "This nickname is taken. Try a different one", "Unexpected = error. Report incident ID NNNNN to Support"). JSON is a convenient = representation for all possible return values. Use a regime of users, schemas, and privilege grants (functions having = "security definer" mode) to implement the functionality. Create a = dedicated user-and-schema to expose the API and nothing else. This will = own only functions that are thin jackets to invoke the real work-doing = functions that are hidden from the client. Allow clients to authorize = ONLY as the API-owning user. Grant "execute" on its functions to what's = needed elsewhere. I've prototyped this scheme. It seems to work as designed. A client that = connects with psql (or any other tool) can list the API functions and = whatever \df and \sf show. (notice that \d will reveal nothing.)But = doing this reveals only the names of the functions that are called = (which will be identical to the jacket names=E2=80=94so no risk here) = and the name(s) of the schema(s) where they live (so a minor theoretical = risk here).=20 Full disclosure: I've never done this in anger. Note: I believe this approach to be nothing other than the application = of the time-honored principles (decades old) of modular software = construction (where the entire database is a top-level module in the = over all app's decomposition). It brings the security benefit that I = sketched along with all the other famous benefits of modular = programming=E2=80=94esp. e.g. the client is shielded from table design = changes.=