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

Open
wants to merge 3 commits into
base: master
Choose a base branch
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 🤷‍♀️

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.

" -p #{config['port'] || '5432'} -U #{config['username']}"
return cmd, env
Copy link
Member

Choose a reason for hiding this comment

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

I think RuboCop would prefer

Suggested change
return cmd, env
cmd, env

Copy link
Member Author

Choose a reason for hiding this comment

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

and yet it didn't complain :D
(I think it only complains on singular returns, not lists)

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

Choose a reason for hiding this comment

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

Should we just drop the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

we could, yeah. I pondered writing actual new tests, but didn't so far.

@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

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