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 1l32Xz-0007dG-0e for pgsql-admin@arkaria.postgresql.org; Fri, 22 Jan 2021 19:56:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l32Xx-0007xB-Tu for pgsql-admin@arkaria.postgresql.org; Fri, 22 Jan 2021 19:56:41 +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 1l32Xx-0007x3-KC for pgsql-admin@lists.postgresql.org; Fri, 22 Jan 2021 19:56:41 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l32Xv-0002fl-Cd for pgsql-admin@lists.postgresql.org; Fri, 22 Jan 2021 19:56:41 +0000 Received: by mail-pj1-x1035.google.com with SMTP id u4so4569596pjn.4 for ; Fri, 22 Jan 2021 11:56:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:subject:date:in-reply-to:message-id :mime-version; bh=IYeXJ8UICodj9zEThxec2plMoRXNAwY87f27KPG4wv4=; b=AC3KsDWBQfKCps9QKwKa0kow6IR1ToOKtqr6hSzWYaHe94TP4DG4MHmSd6fKSL+fmu 2kWzsAM1roi18QZvgRil9UXbPGQztv3y8/exictyWXwXT2m9Z+3yAYk6Qzk8xXjCf2fT Vd/x7H5VpXU1dOqRNApkmFzfsnHkStzPbCJHZW7nPx4VLr7DaBQ5Dri2XhdqQXn/bbce +Q02YBFjalRzxQ5gPK/eM7CO0E+9Gxxxh+wLAF9npik3MZ9sSKWYlfxqdfcR0SxLCA67 HF7PBPjeUIFNnWQj0UQMpx6FeC30UKCBnSZR9E1K6evfFgV8j32/R8V6Ue2F6xb5QF2O DqWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:subject:date :in-reply-to:message-id:mime-version; bh=IYeXJ8UICodj9zEThxec2plMoRXNAwY87f27KPG4wv4=; b=rjN9s1sbLR5W4YcFM+B453WDK279omhbam2u9oNp9AGOIyxd/fNGNsu+FoficIBjTX NU7DtTiVJWziOxq2oYl5DKk76SxMjlsifaJq/G0XYOhfu8FrmilEvsC9dQjDP19yYnrC hqa722c8r3ZDBA99rq7RH0VbovxSZYlyr3OcqM1rUdhazU+IX4wKWPsiQhZtHxFpFlCe zeL0VfCHadiHQYVJfTROcDzpTvyi+YEPCCfxV9Cg1udsHhNC6cVWX0XEAhbv3B5OSDn3 F8NGqWeOCbuDiMc5rtxjVulf6MAEGNKvBfv22oImVYqh7E7R+Q6bQ+/5A6UST7rNbuc1 qsMw== X-Gm-Message-State: AOAM531A3Q/Dv2VKbv4vXJEsHDo0EeOpzAIcZqF0fNbPue/T9nmgLP63 KmZft4MumKsw2wdxRU1yRbZMRpZ2r5iOyg== X-Google-Smtp-Source: ABdhPJxRNDDVW7FY5jGOiNoe5keyGRHB4CetPIvAfjkir1yhbp7AiJ5Ugyt9ZdLjphcebm/WJE9Dkw== X-Received: by 2002:a17:902:b692:b029:de:43aa:6537 with SMTP id c18-20020a170902b692b02900de43aa6537mr6129698pls.65.1611345396274; Fri, 22 Jan 2021 11:56:36 -0800 (PST) Received: from tim-desktop (203-206-4-196.dyn.iinet.net.au. [203.206.4.196]) by smtp.gmail.com with ESMTPSA id l2sm8237288pga.65.2021.01.22.11.56.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 11:56:35 -0800 (PST) References: User-agent: mu4e 1.5.7; emacs 28.0.50 From: Tim Cross To: pgsql-admin@lists.postgresql.org Subject: Re: Create Read only user Date: Sat, 23 Jan 2021 06:36:16 +1100 In-reply-to: Message-ID: <87bldgbv9r.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Yambu writes: > Hello > > I created a user like this > > CREATE USER user1 WITH PASSWORD ''; > > GRANT CONNECT ON DATABASE db1 TO user1; > GRANT SELECT ON ALL TABLES IN SCHEMA public TO user1; > > What amazes me is that when I connect using user1, I'm able to create a > table and drop it. How can this be? In PG, all users by default have access to a PUBLIC schema as well as their user schema. The schema is really public, so full access to create/drop tables etc. The search path determines which schemas are searched and the search order. I rarely use the PUBLIC schema for an application. While you can revoke access at various levels, it often has unexpected consequences because different users may have different expectations with respect to the PUBLIC schema and what access users have. To have tables and other objects where you explicitly manage the access by users, your best bet is to create an application specific schema. You can then set the default grant permissions on that schema and its objects without fear of impacting on other users and manage access rights how you see fit. In fact, for more complex applications, I might have multiple schemas. In addition to enabling more flexible access control, schemas can also make it easier to backup, restore and migrate data between environments. Some people don't like using schemas because they don't like having to prefix object names with the schema name, but I find this is often a sign of not using the path and search_path settings appropriately. Personally, I prefer to be explicit and specify the schema rather than relying on individual configuration and setup of login profiles. -- Tim Cross