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 1lSkbZ-0006F5-Vo for pgsql-general@arkaria.postgresql.org; Sat, 03 Apr 2021 18:02:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lSkbY-0008P4-SU for pgsql-general@arkaria.postgresql.org; Sat, 03 Apr 2021 18:02:40 +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 1lSkbY-0008Oq-B8 for pgsql-general@lists.postgresql.org; Sat, 03 Apr 2021 18:02:40 +0000 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lSkbV-0001qA-Gt for pgsql-general@postgresql.org; Sat, 03 Apr 2021 18:02:39 +0000 Received: by mail-qt1-x82d.google.com with SMTP id i19so5761261qtv.7 for ; Sat, 03 Apr 2021 11:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joeconway.com; s=google; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=ETC0c+gLa8qr8SVkEBDql6Jh58u+Fxt/b2NfbM/zYho=; b=STKiZkt8N7ENwppIBXyYTeWOtTB0zUZafFj9tB/tPAAEoha819SQ47qyVxCJHJZRa2 oL8lYqyYW+B35/HA6kJNpe5koQ2HnfjCT5ZhCJnbufVcmbYZ0/44khHx603OP3Rgz5be Lmcp5AyhbCt5/4zICLOzhahhKqZY170cwyLyGAKzSonuxweX79baZUzeUI9whZQJwna1 5rMl8kbYjxS1ej9jBX5wLw5DXGeSTov+hVYVl9H70VrUiSq9Wq4eBe6BkGU0OnxN5tq6 mgpMwU1aAEzOwESBssEGz8L6jdFKDkp7lvRlFxOc3pU/FfAbl0y9WbOdO0aW2Xoja5YN NjIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ETC0c+gLa8qr8SVkEBDql6Jh58u+Fxt/b2NfbM/zYho=; b=t0smafso4wyygutQcptEbOW/s+8HE1lpH3UKr3eGiSJa9P6ZkShWjPSWPxiDNu4CUJ mzr8UM2hUG1iUdC0WZM5IV1HvnlPqMzdtykWzrBXr2HQPEeYYpeksYtKZI1++HXjlCTZ nBlGJDNH7xlihpSPqQEK4b6JO/g0AkjhusjhdFhM2ICVdYTsuRjJMEVdopEmBtu2gJCW ChdMNrQ//O31tjxBAeqatfLYREWMUfdsnp0a5JCHyq2fOrffxRwtGlP+fV7U76/awksb BXrw3jyh0+VpCAB/WzJ9P6fz+YNmJsS7wgEI52YXdsmEGYpepKRu21b5baXPe/1nXFar mIAw== X-Gm-Message-State: AOAM532R2+NVLHTJI+rINsjUe7/ttQAfbrVkPfuobIxR8Rv9T1mSmmYx Q01vni4yLEci+yNW7FS0gJgRBjOcle4e7vAoJTxm9r9ChCqQO/7K1hfwcV2WEMK04dcNdLg53nO hwDgEiirw2cFn8S/+Iai1ANq8IoB+rtTgrxF9eAurgZHYACBiH3iHyI53XEa9mNLR9yyx9tAsXD Adt5U= X-Google-Smtp-Source: ABdhPJwgxb4YSlGh6WSQ7PK0Yb6jZ1Hfs/SmRWjwMVbBuDiqlFEa059i+1+SZFjXO1PSfAwboD6epg== X-Received: by 2002:ac8:6c57:: with SMTP id z23mr1794299qtu.155.1617472956208; Sat, 03 Apr 2021 11:02:36 -0700 (PDT) Received: from [192.168.4.41] (072-017-018-098.res.spectrum.com. [72.17.18.98]) by smtp.gmail.com with ESMTPSA id v7sm9901037qkv.86.2021.04.03.11.02.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Apr 2021 11:02:35 -0700 (PDT) Subject: Re: How to deny access to Postgres when connected from host/non-local To: "A. Reichstadt" , pgsql-general@postgresql.org References: <7CFC6367-B1D5-4FEF-9578-825A07D9AF81@me.com> From: Joe Conway Message-ID: Date: Sat, 3 Apr 2021 14:02:35 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <7CFC6367-B1D5-4FEF-9578-825A07D9AF81@me.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/2/21 7:06 PM, A. Reichstadt wrote: > Hello, > > I try to deny access to all databases on my server if the user “postgres" tries > to connect from a non-local host. Here is what I did in pg_hba.conf: > > > # TYPE  DATABASE        USER            ADDRESS                 METHOD > > # "local" is for Unix domain socket connections only > local   all             all                                     md5 > # IPv4 local connections: > host    all             all             127.0.0.1/32            md5 > # IPv6 local connections: > host    all             all             ::1/128                 md5 > # Allow replication connections from localhost, by a user with the > # replication privilege. > local   replication     all                                     md5 > host    replication     all             127.0.0.1/32            md5 > host    replication     all             ::1/128                 md5 > host    all             all             0.0.0.0/0               md5 > local   all             postgres                                trust > host    all             postgres        0.0.0.0/0               reject > > > But it continues to allow for Postgres to connect from anywhere through PGAdmin > but also as a direct connection to port 5432. I also relaunched the server. This > is version 12. > > What else do I have to do? > > Thanks for any help. See: https://www.postgresql.org/docs/13/auth-pg-hba-conf.html In particular: "Each record specifies a connection type, a client IP address range (if relevant for the connection type), a database name, a user name, and the authentication method to be used for connections matching these parameters. The first record with a matching connection type, client address, requested database, and user name is used to perform authentication." So your reject line is never being reached. HTH, Joe -- Crunchy Data - http://crunchydata.com PostgreSQL Support for Secure Enterprises Consulting, Training, & Open Source Development