Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow access to Postgres from the office (and VPN) #216

Merged
merged 1 commit into from
Jun 14, 2023

Conversation

akash1810
Copy link
Member

@akash1810 akash1810 commented Jun 14, 2023

What does this change?

Add an ingress rule to the Postgres security group, allowing connection from the Engineering subnet.

The CloudFormation diff is quite big, however that's largely due to one change - we're now explicitly creating a security group for the database, rather than letting AWS CDK create one. This change has a cascading effect across most other resources in the stack.

As noted, a bastion host might be a better option here as it means we're not reliant on the network to limit access. Thoughts on whether this is blocking welcomed. See also guardian/cdk#1786.

Why?

This means we can connect to the database from the office network, as it is sometimes easier to run queries outside of Grafana.

We had previously added this ingress rule manually (i.e. introduced drift); this change encodes it.

How one connects is down to preference. Personally, I'd be recommending using the AWS Toolkit for JetBrains as it allows one to authenticate via IAM credentials, i.e. credentials issued by Janus.

How has it been verified?

I have performed the following steps:

  • Confirmed I can access Postgres locally when connected to the VPN
  • Removed drift
  • Deployed main
  • Confirmed I can no longer access Postgres locally
  • Deployed this branch
  • Confirmed I can access Postgres locally when connected to the VPN

@akash1810 akash1810 requested review from a team as code owners June 14, 2023 12:43
],
"SecurityGroupIngress": [
{
"CidrIp": "10.0.0.4/22",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an ingress rule to the Postgres security group,
allowing connection from the Engineering subnet.

This means we can connect to the database from the office network,
as it is sometimes easier to run queries outside of Grafana.
@akash1810
Copy link
Member Author

akash1810 commented Jun 14, 2023

Summarising a discussion with @itsibitzi about this:

Location based trust is terrible, however we're maintaining DB auth, so not so bad. Generally speaking, we should consider the office network as good as compromised. A bastion host removes the network trust layer, so would be an improvement here.

Also worth noting that the ingress rule of 10.X.X.X is only possible for accounts using Direct Connect, meaning this repository cannot be used as a reference implementation. Moving to a bastion host would change that1.

I'll merge this, and look at adding a bastion host soon after.

Footnotes

  1. Though actually, the creation of a bastion host should be abstracted into GuCDK.

@akash1810 akash1810 merged commit f999066 into main Jun 14, 2023
@akash1810 akash1810 deleted the aa/office-access branch June 14, 2023 13:28
@akash1810
Copy link
Member Author

akash1810 commented Jun 14, 2023

I'll merge this, and look at adding a bastion host soon after.

UPDATE: Attempts to use the AWS CDK bastion host results in:

Error: Resolution error: Resolution error: Found an encoded list token string in a scalar string context. Use 'Fn.select(0, list)' (not 'list[0]') to extract elements from token lists...

I think we'd need to update https://github.com/guardian/aws-account-setup to export the values of the VPC, and we can then use importListValue to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants