File tree Expand file tree Collapse file tree 3 files changed +26
-9
lines changed
lib/charms/postgresql_k8s/v0 Expand file tree Collapse file tree 3 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 36
36
37
37
# Increment this PATCH version before using `charmcraft publish-lib` or reset
38
38
# to 0 if you are raising the major API version
39
- LIBPATCH = 27
39
+ LIBPATCH = 28
40
40
41
41
INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles"
42
42
@@ -230,7 +230,10 @@ def create_user(
230
230
user_definition += f"WITH { 'NOLOGIN' if user == 'admin' else 'LOGIN' } { ' SUPERUSER' if admin else '' } ENCRYPTED PASSWORD '{ password } '{ 'IN ROLE admin CREATEDB' if admin_role else '' } "
231
231
if privileges :
232
232
user_definition += f' { " " .join (privileges )} '
233
+ cursor .execute (sql .SQL ("BEGIN;" ))
234
+ cursor .execute (sql .SQL ("SET LOCAL log_statement = 'none';" ))
233
235
cursor .execute (sql .SQL (f"{ user_definition } ;" ).format (sql .Identifier (user )))
236
+ cursor .execute (sql .SQL ("COMMIT;" ))
234
237
235
238
# Add extra user roles to the new user.
236
239
if roles :
@@ -519,11 +522,14 @@ def update_user_password(
519
522
with self ._connect_to_database (
520
523
database_host = database_host
521
524
) as connection , connection .cursor () as cursor :
525
+ cursor .execute (sql .SQL ("BEGIN;" ))
526
+ cursor .execute (sql .SQL ("SET LOCAL log_statement = 'none';" ))
522
527
cursor .execute (
523
528
sql .SQL ("ALTER USER {} WITH ENCRYPTED PASSWORD '" + password + "';" ).format (
524
529
sql .Identifier (username )
525
530
)
526
531
)
532
+ cursor .execute (sql .SQL ("COMMIT;" ))
527
533
except psycopg2 .Error as e :
528
534
logger .error (f"Failed to update user password: { e } " )
529
535
raise PostgreSQLUpdateUserPasswordError ()
Original file line number Diff line number Diff line change @@ -590,13 +590,8 @@ async def test_discourse(ops_test: OpsTest):
590
590
# Deploy Discourse and Redis.
591
591
await gather (
592
592
ops_test .model .deploy (DISCOURSE_APP_NAME , application_name = DISCOURSE_APP_NAME ),
593
- # Revision 28 is being used due to https://github.com/canonical/redis-k8s-operator/issues/87.
594
593
ops_test .model .deploy (
595
- REDIS_APP_NAME ,
596
- application_name = REDIS_APP_NAME ,
597
- channel = "latest/edge" ,
598
- revision = 28 ,
599
- series = "jammy" ,
594
+ REDIS_APP_NAME , application_name = REDIS_APP_NAME , channel = "latest/edge"
600
595
),
601
596
)
602
597
Original file line number Diff line number Diff line change 19
19
get_primary ,
20
20
get_unit_address ,
21
21
restart_patroni ,
22
+ run_command_on_unit ,
22
23
set_password ,
23
24
)
24
25
@@ -125,8 +126,8 @@ async def test_password_from_secret_same_as_cli(ops_test: OpsTest):
125
126
I.e. we're manipulating the secret we think we're manipulating.
126
127
"""
127
128
#
128
- # No way to retrieve a secet by label for now (https://bugs.launchpad.net/juju/+bug/2037104)
129
- # Therefore we take advantage of the fact, that we only have ONE single secret a this point
129
+ # No way to retrieve a secret by label for now (https://bugs.launchpad.net/juju/+bug/2037104)
130
+ # Therefore we take advantage of the fact, that we only have ONE single secret at this point
130
131
# So we take the single member of the list
131
132
# NOTE: This would BREAK if for instance units had secrets at the start...
132
133
#
@@ -176,3 +177,18 @@ async def test_no_password_change_on_invalid_password(ops_test: OpsTest) -> None
176
177
password2 = await get_password (ops_test , username = "replication" )
177
178
# The password didn't change
178
179
assert password1 == password2
180
+
181
+
182
+ @pytest .mark .group (1 )
183
+ async def test_no_password_exposed_on_logs (ops_test : OpsTest ) -> None :
184
+ """Test that passwords don't get exposed on postgresql logs."""
185
+ for unit in ops_test .model .applications [APP_NAME ].units :
186
+ try :
187
+ logs = await run_command_on_unit (
188
+ ops_test ,
189
+ unit .name ,
190
+ "grep PASSWORD /var/log/postgresql/postgresql-*.log" ,
191
+ )
192
+ except Exception :
193
+ continue
194
+ assert len (logs ) == 0 , f"Sensitive information detected on { unit .name } logs"
You can’t perform that action at this time.
0 commit comments