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

pass PGPASSWORD via env directly, not via shell #939

Closed
wants to merge 4 commits into from

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Oct 15, 2024

No description provided.

@evgeni
Copy link
Member Author

evgeni commented Oct 15, 2024

with this, nothing uses hidden_patterns anymore. should we drop it, so that this bad design doesn't creep up on us again?

and one more thing: technically hidden_patterns also replaces the pattern in stdout, but I would not expect Postgres to ever print the password, so 🤷‍♀️

@evgeni evgeni force-pushed the env-pass branch 2 times, most recently from 88d642b to f71c81d Compare October 15, 2024 12:15
Copy link
Member

@ehelms ehelms left a comment

Choose a reason for hiding this comment

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

Agreed on cleaning up hidden_patterns if it's not used.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Overall I think this is OK, but the whole module looks rather inconsistent.

Comment on lines +130 to +132
cmd, env = psql_command(config)
cmd += ' -c "SHOW server_version" -t -A'
version_string = execute!(cmd, :env => env)
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this should use psql('SHOW server_version'), but you probably also saw that and considered it out of scope.

And as always, I think it should have used --no-align instead of -A to make the comment above it redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe, but I also didn't feel like actually touching the code here

test/lib/utils/command_runner_test.rb Outdated Show resolved Hide resolved
@evgeni
Copy link
Member Author

evgeni commented Oct 15, 2024

I've just realized that while this fixes one issue with the passwords, it doesn't fix the one in the report. 🤦‍♀️
That is about us parsing pulp's settings.py wrongly

@ekohl
Copy link
Member

ekohl commented Oct 15, 2024

I wonder if it could wrap django's dbshell command to run queries somehow

@evgeni
Copy link
Member Author

evgeni commented Oct 15, 2024

Don't give me ideas

@evgeni
Copy link
Member Author

evgeni commented Oct 15, 2024

PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/etc/pulp python -c 'import yaml; import settings; print(yaml.safe_dump(settings.DATABASES["default"]))'

@ekohl
Copy link
Member

ekohl commented Oct 15, 2024

My biggest issue is that the Rails equivalent needs to load the entire Rails env, which is slow. And there is none (that I know of) for Candlepin. Not that we need queries on that after we merge #940, but there's still the backup/restore part.

@ekohl
Copy link
Member

ekohl commented Oct 15, 2024

PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=/etc/pulp python -c 'import yaml; import settings; print(yaml.safe_dump(settings.DATABASES["default"]))'

Nit: I'd prefer JSON and you can use pulpcore-admin shell to get a Python shell with guaranteed the correct Python version.

@evgeni
Copy link
Member Author

evgeni commented Oct 15, 2024

sure, why not:

# PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager shell --command 'from django.conf import settings; import json; print(json.dumps(settings.DATABASES["default"]))'
{"ENGINE": "django.db.backends.postgresql", "NAME": "pulpcore", "USER": "pulp", "PASSWORD": "sdfsfds\"dssdfdsf", "HOST": "remotedb", "PORT": "5432", "ATOMIC_REQUESTS": false, "AUTOCOMMIT": true, "CONN_MAX_AGE": 0, "CONN_HEALTH_CHECKS": false, "OPTIONS": {}, "TIME_ZONE": null, "TEST": {"CHARSET": null, "COLLATION": null, "MIGRATE": true, "MIRROR": null, "NAME": null}}

@ekohl
Copy link
Member

ekohl commented Oct 15, 2024

The reason I bring it up is that it's probably easier to reuse this once we start using containers. If we start using env vars or secrets, that'll work at runtime but it'll be complex to parse all the options.

@evgeni
Copy link
Member Author

evgeni commented Oct 16, 2024

#941

@evgeni
Copy link
Member Author

evgeni commented Oct 17, 2024

dropped the (empty) command runner tests and added a bunch of base_database tests instead

@evgeni evgeni requested review from ekohl and ehelms October 17, 2024 09:47
@ekohl
Copy link
Member

ekohl commented Oct 17, 2024

I wanted to know how I'd structure it and in #945 there are the results of my refactor.

The biggest change is that instead of composing complex commands I pass all PG connection params via env vars which simplifies a lot of the code.

I can add your tests if you'd like (and adopt where needed).

@evgeni
Copy link
Member Author

evgeni commented Oct 17, 2024

I can add your tests if you'd like (and adopt where needed).

I think that'd be a good idea, but maybe just merge this and then use yours as further improvement?

@ekohl
Copy link
Member

ekohl commented Oct 17, 2024

I can add your tests if you'd like (and adopt where needed).

This is done now.

maybe just merge this and then use yours as further improvement?

I'm not sure I like refactoring it twice shortly after each other.

@evgeni
Copy link
Member Author

evgeni commented Oct 17, 2024

Strictly speaking this one was never intended as refactoring, just fixing the bug we have when the password contains quotes ;)

@evgeni
Copy link
Member Author

evgeni commented Oct 21, 2024

closing in favor of #945

@evgeni evgeni closed this Oct 21, 2024
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.

3 participants