Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Fix env cascading when invoking psql #97

Merged
merged 1 commit into from
Feb 24, 2017
Merged

Conversation

msakrejda
Copy link
Contributor

Currently we override most PG* environment variables, but there's no
good reason for this--if the user has set something, we should not
require them to override this via the URL.

With this change, they still can if they need to do so explicitly,
but we shouldn't clobber valid various from the environment with empty
ones.

We keep PGSSLMODE as a setting users cannot override (to avoid
unencrypted connections to remote databases), but account for unset
hosts (which defaults to a local connection).

Fixes #92

Currently we override most PG* environment variables, but there's no
good reason for this--if the user has set something, we should not
require them to override this via the URL.

With this change, they still *can* if they need to do so explicitly,
but we shouldn't clobber valid various from the environment with empty
ones.

We keep PGSSLMODE as a setting users cannot override (to avoid
unencrypted connections to remote databases), but account for unset
hosts (which defaults to a local connection).
@codecov-io
Copy link

Codecov Report

Merging #97 into master will increase coverage by 0.02%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
+ Coverage   95.94%   95.96%   +0.02%     
==========================================
  Files          42       42              
  Lines         986      992       +6     
==========================================
+ Hits          946      952       +6     
  Misses         40       40
Impacted Files Coverage Δ
lib/bastion.js 95% <100%> (+0.88%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63b80d5...ab0dcc6. Read the comment docs.

@msakrejda
Copy link
Contributor Author

I think this fixes #85 as well (you'll be able to either set a PGHOST env var or leave the host blank and your default host is probably Unix socket if your OS supports that).

@fnando
Copy link

fnando commented Feb 24, 2017

Looks legit! I didn't test it though.

+1

@msakrejda msakrejda merged commit e3eef8c into master Feb 24, 2017
@msakrejda msakrejda deleted the fix-env-cascading branch February 24, 2017 01:49
@michaelbaudino
Copy link
Contributor

@uhoh-itsmaciek I see at least one use-case where one would need to override PGSSLMODE: when using the official Postgres Docker image for development (which does not support SSL).

The hostname is then considered remote (it's usually a different container than the one running the app, thus usually in Docker virtual network), but cannot be access neither via Unix socket nor with SSL 😢

I'd be happy to provide a PR that makes PGSSLMODE overridable like any other PG* variables, but I'd like to know if it might be accepted before investing time in it.

Unless you have another workaround I didn't think about?

@msakrejda
Copy link
Contributor Author

@michaelbaudino yeah, okay, I think that's safe enough. Heroku Postgres will refuse unencrypted connections anyway, so it's not much of an issue. You plan to just move PGSSLMODE here, correct? That works for me...

@michaelbaudino
Copy link
Contributor

Woohoo, thanks, here is the PR: #171 😍

msakrejda pushed a commit that referenced this pull request Dec 7, 2017
All `PG*` environment variables can be overridden when using `pg:pull`
or `pg:push` since #97, except `PGSSLMODE`, probably because there was
no obvious use case to let users decide to insecurely bypass SSL.

But when using a PostgreSQL server in Docker Comnpose using the
official Postgres image, it's usually hosted on a different
container than the user app and can be reached through Docker virtual
network, and thus (rightously) considered remote.

Unfortunately, the official Postgres image does not support SSL.

It seems like a use case where it is safe to bypass SSL, even though
the server is considered remote. And it might be a growing use case
since even the official Postgres image do not intend to support SSL:
docker-library/postgres#152

Thus I'd love to be able to use `pg:pull` from my app container to
load a database in a PG server in another container 😍
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants