Skip to content

Commit 64e3e8f

Browse files
author
Federico Ceratto
committed
Deploy pg_hba.conf
1 parent e926cd1 commit 64e3e8f

File tree

2 files changed

+114
-6
lines changed

2 files changed

+114
-6
lines changed

ansible/roles/postgresql11/tasks/main.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@
3838
- postgresql-11
3939
- prometheus-postgres-exporter
4040

41-
- name: Trust localhost IPv4 access on postgresql
42-
lineinfile:
41+
- name: Overwrite pg_hba.conf
42+
template:
43+
src: templates/pg_hba.conf
4344
dest: /etc/postgresql/11/main/pg_hba.conf
44-
regexp: '^host\s+all\s+all+\s+127\.0\.0\.1/32\s+trust'
45-
insertafter: '^# IPv4 local connections:'
46-
line: "host all all 127.0.0.1/32 trust"
47-
state: present
45+
mode: 0644
46+
owner: root
4847

4948
- name: Overwrite postgresql.conf
5049
template:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Managed by ansible
2+
# roles/postgresql11/templates/pg_hba.conf
3+
4+
5+
# PostgreSQL Client Authentication Configuration File
6+
# ===================================================
7+
#
8+
# Refer to the "Client Authentication" section in the PostgreSQL
9+
# documentation for a complete description of this file. A short
10+
# synopsis follows.
11+
#
12+
# This file controls: which hosts are allowed to connect, how clients
13+
# are authenticated, which PostgreSQL user names they can use, which
14+
# databases they can access. Records take one of these forms:
15+
#
16+
# local DATABASE USER METHOD [OPTIONS]
17+
# host DATABASE USER ADDRESS METHOD [OPTIONS]
18+
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
19+
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
20+
#
21+
# (The uppercase items must be replaced by actual values.)
22+
#
23+
# The first field is the connection type: "local" is a Unix-domain
24+
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
25+
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
26+
# plain TCP/IP socket.
27+
#
28+
# DATABASE can be "all", "sameuser", "samerole", "replication", a
29+
# database name, or a comma-separated list thereof. The "all"
30+
# keyword does not match "replication". Access to replication
31+
# must be enabled in a separate record (see example below).
32+
#
33+
# USER can be "all", a user name, a group name prefixed with "+", or a
34+
# comma-separated list thereof. In both the DATABASE and USER fields
35+
# you can also write a file name prefixed with "@" to include names
36+
# from a separate file.
37+
#
38+
# ADDRESS specifies the set of hosts the record matches. It can be a
39+
# host name, or it is made up of an IP address and a CIDR mask that is
40+
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
41+
# specifies the number of significant bits in the mask. A host name
42+
# that starts with a dot (.) matches a suffix of the actual host name.
43+
# Alternatively, you can write an IP address and netmask in separate
44+
# columns to specify the set of hosts. Instead of a CIDR-address, you
45+
# can write "samehost" to match any of the server's own IP addresses,
46+
# or "samenet" to match any address in any subnet that the server is
47+
# directly connected to.
48+
#
49+
# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
50+
# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
51+
# Note that "password" sends passwords in clear text; "md5" or
52+
# "scram-sha-256" are preferred since they send encrypted passwords.
53+
#
54+
# OPTIONS are a set of options for the authentication in the format
55+
# NAME=VALUE. The available options depend on the different
56+
# authentication methods -- refer to the "Client Authentication"
57+
# section in the documentation for a list of which options are
58+
# available for which authentication methods.
59+
#
60+
# Database and user names containing spaces, commas, quotes and other
61+
# special characters must be quoted. Quoting one of the keywords
62+
# "all", "sameuser", "samerole" or "replication" makes the name lose
63+
# its special character, and just match a database or username with
64+
# that name.
65+
#
66+
# This file is read on server startup and when the server receives a
67+
# SIGHUP signal. If you edit the file on a running system, you have to
68+
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
69+
# or execute "SELECT pg_reload_conf()".
70+
#
71+
# Put your actual configuration here
72+
# ----------------------------------
73+
#
74+
# If you want to allow non-local connections, you need to add more
75+
# "host" records. In that case you will also need to make PostgreSQL
76+
# listen on a non-local interface via the listen_addresses
77+
# configuration parameter, or via the -i or -h command line switches.
78+
79+
80+
81+
82+
# DO NOT DISABLE!
83+
# If you change this first entry you will need to make sure that the
84+
# database superuser can access the database using some other method.
85+
# Noninteractive access to all databases is required during automatic
86+
# maintenance (custom daily cronjobs, replication, and similar tasks).
87+
#
88+
# Database administrative login by Unix domain socket
89+
local all postgres peer
90+
91+
# TYPE DATABASE USER ADDRESS METHOD
92+
93+
# Unix domain socket: allow all local connections without password
94+
local all all trust
95+
96+
# IPv4 local connections:
97+
host all all 127.0.0.1/32 md5
98+
host all all 127.0.0.1/32 md5
99+
# IPv6 local connections:
100+
host all all ::1/128 md5
101+
# Allow replication connections from localhost, by a user with the
102+
# replication privilege.
103+
local replication all peer
104+
host replication all 127.0.0.1/32 md5
105+
host replication all ::1/128 md5
106+
107+
# Allow incoming SSL connections without password
108+
# protected by filtering on source ipaddr using nftables
109+
hostssl all all 0.0.0.0/0 trust

0 commit comments

Comments
 (0)