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

Figure out how to get access to the FPDCC’s GIS Database from heroku #59

Closed
fgregg opened this issue Nov 22, 2021 · 11 comments · Fixed by #91
Closed

Figure out how to get access to the FPDCC’s GIS Database from heroku #59

fgregg opened this issue Nov 22, 2021 · 11 comments · Fixed by #91
Assignees

Comments

@fgregg
Copy link
Collaborator

fgregg commented Nov 22, 2021

Depends on #58

@fgregg fgregg self-assigned this Nov 22, 2021
@hancush hancush self-assigned this Dec 3, 2021
@hancush
Copy link
Collaborator

hancush commented Dec 3, 2021

It seems like you can whitelist IPs to specified users with passwords in the usual way on MediaOcean's managed Postgres service. Whoops, it seems that way because it's documentation about how to do it in the usual way, lol.

It does actually look like you can whitelist specific IPs in the settings of the managed Postgres instance. Not sure about a per-user control, but I'll look into it. Could just naively accept connections as any user from the specified sources.

So, I think we should be able to assign static IPs to our Heroku instances with QuotaGuard or Fixie, then ask them to allow inbound connections from our IPs and provide us credentials. We should also make sure to enable SSL for the fp_postgis database.

Anything raise your hackles about that, @fgregg?

@hancush
Copy link
Collaborator

hancush commented Dec 3, 2021

How to create a new user: https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/

New users will receive the permissions of the doadmin user by default. You can’t change these permissions from the control panel, but you can modify user privileges using third-party tools like psql.

Pretty crazy new users receive admin privileges by default, lol. I would recommend clearing default privs and granting us readonly access to the schemas/tables we need.

@hancush
Copy link
Collaborator

hancush commented Dec 3, 2021

@hancush
Copy link
Collaborator

hancush commented Dec 3, 2021

We could get 20k (QuotaGuard) or 25k (Fixie) requests per month for $20. But, does that mean, like, all requests to and from our app, or can we selectively proxy only the GIS database outbound requests?

@fgregg
Copy link
Collaborator Author

fgregg commented Dec 4, 2021 via email

@hancush
Copy link
Collaborator

hancush commented Dec 6, 2021

Ooh, great idea, @fgregg!

@hancush
Copy link
Collaborator

hancush commented Dec 6, 2021

It looks like managed Postgres instances are open to any inbound connection by default. So, we should find out if CCFP has locked it down or maintains the default open setting. If it is open, then we should just be able to connect over SSL with a username and password.

If it is not open, then I don't see a way around whitelisting, either a fixed Heroku IP, or some passthrough server we maintain. @fgregg What do you think?

@hancush
Copy link
Collaborator

hancush commented Dec 9, 2021

Got creds from Garret. Unfortunately, not able to connect from the staging app dyno using psql as I would expect. I think this is because Fixie proxies HTTP requests, but Postgres doesn't make HTTP requests to the specified hosts, it uses sockets.

If you’re using PostgreSQL, by default (empty HOST), the connection to the database is done through UNIX domain sockets (‘local’ lines in pg_hba.conf). If your UNIX domain socket is not in the standard location, use the same value of unix_socket_directory from postgresql.conf. If you want to connect through TCP sockets, set HOST to ‘localhost’ or ‘127.0.0.1’ (‘host’ lines in pg_hba.conf). On Windows, you should always define HOST, as UNIX domain sockets are not available.

I'm at the edge of my networking knowledge here, but there is a Heroku add-on called Fixie Socks that can proxy TCP connections. @fgregg Are you available to discuss/troubleshoot with me next week?

@fgregg
Copy link
Collaborator Author

fgregg commented Dec 10, 2021 via email

@hancush
Copy link
Collaborator

hancush commented Dec 15, 2021

K, I've set up Fixie Socks. We think that we'll be able to use a library like pysocks to create a socket connected to the Fixie Socks relay, then configure Django to use that socket, but we can't find a good example, so we'll pair on this from the Heroku shell once Garret whitelists the new IPs.

@hancush
Copy link
Collaborator

hancush commented Dec 20, 2021

Summary of the ultimate approach from #91:


Outside of version control, I provisioned a QuotaGuard Static add-on for the staging app, asked Garret to whitelist the provided IPs as trusted traffic sources for GIS database, then configured the tunnel following these instructions. The resulting config is committed to version control in this PR to remove our dependency on the QuotaGuard site. I also added the GIS_DATABASE_URL to review app config vars in the Heroku UI.

As this approach relies on static IPs being available, it will only work for apps to which we've attached the QuotaGuard Static add-on. By default, this excludes review apps, and if it's possible, I think it's probably a good idea to write the GIS integration such that the app is resilient enough for testing without access to the GIS database.

For scenarios where we do want GIS access for a review app, QuotaGuard Static instances can be shared between apps, so we can do heroku:attach -a ${REVIEW_APP} quotaguardstatic after the app is initialized. I've gone ahead and tested this approach with the review app created by this PR. Worked as expected!

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