Merge lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts into lp:charms/postgresql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 57
Proposed branch: lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts
Merge into: lp:charms/postgresql
Prerequisite: lp:~stub/charms/precise/postgresql/charm-helpers
Diff against target: 52 lines (+13/-0)
2 files modified
README.markdown (+4/-0)
hooks/hooks.py (+9/-0)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql/bug-1187508-allowed-hosts
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+174771@code.launchpad.net

Description of the change

This is a resubmission of https://code.launchpad.net/~davidpbritton/charms/precise/postgresql/trunk/+merge/171906, conflicts resolved and suggestions implemented.

This is to address Bug #1187508, where a client charm has no way of knowing if the credentials it has will actually work for it yet.

Simple change to set and export an "allowed-units" relation setting. This will show if you can connect to the database or not. Since the relations run asynchronously, there is no way to determine this otherwise. If your host is in the allowed_host setting, your client IP has been added to the hba conf file.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :
Revision history for this message
David Britton (dpb) wrote :

Stub: looks great! thanks for re-implementing.

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.markdown'
2--- README.markdown 2013-04-10 13:54:05 +0000
3+++ README.markdown 2013-07-15 14:23:49 +0000
4@@ -118,6 +118,8 @@
5 - `user`: a regular user authorized to read the database
6 - `password`: the password for `user`
7 - `state`: 'standalone', 'master' or 'hot standby'.
8+- `allowed-units`: space separated list of allowed clients (unit name).
9+ You should check this to determine if you can connect to the database yet.
10
11 ## During db-admin-relation-changed
12
13@@ -128,3 +130,5 @@
14 - `user`: a created super user
15 - `password`: the password for `user`
16 - `state`: 'standalone', 'master' or 'hot standby'
17+- `allowed-units`: space separated list of allowed clients (unit name).
18+ You should check this to determine if you can connect to the database yet.
19
20=== modified file 'hooks/hooks.py'
21--- hooks/hooks.py 2013-07-08 10:52:59 +0000
22+++ hooks/hooks.py 2013-07-15 14:23:49 +0000
23@@ -440,6 +440,7 @@
24 # It's not an IP address.
25 return addr
26
27+ allowed_units = set()
28 relation_data = []
29 relids = hookenv.relation_ids('db') + hookenv.relation_ids('db-admin')
30 for relid in relids:
31@@ -477,6 +478,7 @@
32 raise RuntimeError(
33 'Unknown relation type {}'.format(repr(relid)))
34
35+ allowed_units.add(unit)
36 relation['private-address'] = munge_address(
37 relation['private-address'])
38 relation_data.append(relation)
39@@ -523,6 +525,13 @@
40 owner="postgres", group="postgres", perms=0600)
41 postgresql_reload()
42
43+ # Loop through all db relations, making sure each knows what are the list
44+ # of allowed hosts that were just added. lp:#1187508
45+ # We sort the list to ensure stability, probably unnecessarily.
46+ for relid in hookenv.relation_ids('db') + hookenv.relation_ids('db-admin'):
47+ hookenv.relation_set(
48+ relid, {"allowed-units": " ".join(unit_sorted(allowed_units))})
49+
50
51 def install_postgresql_crontab(postgresql_ident):
52 '''Create the postgres user's crontab'''

Subscribers

People subscribed via source and target branches