Skip to content

[expired-registration-cleaner] Use dedicated security group for accessing Postgres#1708

Merged
jacobwinch merged 1 commit intomainfrom
jw-expired-reg-cleaner-sg
Mar 4, 2026
Merged

[expired-registration-cleaner] Use dedicated security group for accessing Postgres#1708
jacobwinch merged 1 commit intomainfrom
jw-expired-reg-cleaner-sg

Conversation

@jacobwinch
Copy link
Contributor

@jacobwinch jacobwinch commented Feb 26, 2026

What does this change?

The Notifications VPC has a “default group”. Prior to this PR, expired-registration-cleaner used this group to gain access to the RDS database (via the RDS proxy). This approach to networking does not follow the principle of least privilege, as any network interface in the VPC can implicitly reach the CODE and PROD databases.

In #1636 a new security group was created, with the intention of services joining it only if they need database access. This will ultimately allow us to remove the “default group”, thus improving our security posture by moving towards the principle of least privilege.

This PR updates expired-registration-cleaner to use the new security group / approach1.

How has this change been tested?

This Lambda runs once a day at 23:04:00 UTC:

DailyEvent:
Type: AWS::Events::Rule
Properties:
Description: Event sent to process the previous day of data
ScheduleExpression: cron(4 23 * * ? *)
Targets:
- Id: Lambda
Arn: !GetAtt Lambda.Arn

It looks for old tokens and deletes them from the DB:

def handleRequest(): Unit = {
val olderThanDays = 300
val rowCount = registrationService.deleteByDate(olderThanDays).unsafeRunSync()
logger.info(s"Deleted $rowCount rows older than $olderThanDays days")
}
}

I have deployed to CODE and invoked the Lambda manually.

Unfortunately I don't think there is any test data for the Lambda to delete, although the logs look the same as those from last night, which suggests that it could run the query as normal.

How can we measure success?

This is a step towards removing the "default group", which improves our security posture and allows us to standardise on a single approach following the changes made in #1636.

Have we considered potential risks?

I don't think there are any significant risks in this case. As mentioned above, I wasn't able to test token deletion due to the state of the CODE DB, so I will also double check the logs for this one in PROD after merging.

Footnotes

  1. Note that all of the above applies regardless of whether the application connects to the RDS instance directly or whether it goes via the RDS proxy, because the RDS instance and the RDS proxy share the same security group (created here).

@jacobwinch jacobwinch added the maintenance Departmental tracking: maintenance work, not a fix or a feature label Feb 26, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

@jacobwinch jacobwinch force-pushed the jw-expired-reg-cleaner-sg branch from eae25b0 to 6d95de2 Compare February 26, 2026 16:39
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

@jacobwinch jacobwinch marked this pull request as ready for review February 26, 2026 16:52
@jacobwinch jacobwinch requested a review from a team as a code owner February 26, 2026 16:52
@jacobwinch jacobwinch force-pushed the jw-expired-reg-cleaner-sg branch from 6d95de2 to fafb85e Compare March 4, 2026 11:46
@jacobwinch jacobwinch enabled auto-merge (squash) March 4, 2026 11:47
@jacobwinch jacobwinch merged commit fdedca0 into main Mar 4, 2026
10 checks passed
@jacobwinch jacobwinch deleted the jw-expired-reg-cleaner-sg branch March 4, 2026 11:50
@jacobwinch
Copy link
Contributor Author

As mentioned above, I wasn't able to test token deletion due to the state of the CODE DB, so I will also double check the logs for this one in PROD after merging.

This was deployed successfully yesterday morning and it seems to have run correctly late last night.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Departmental tracking: maintenance work, not a fix or a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants