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

move PGPASSWORD to env #990

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open

move PGPASSWORD to env #990

wants to merge 4 commits into from

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Oct 18, 2024

@evgeni evgeni marked this pull request as draft October 18, 2024 10:47
hooks/pre/10-reset_data.rb Outdated Show resolved Hide resolved
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.

Btw, if we don't need to ensure we've escaped the Puppet Ruby env we don't need to format the command and you could use Open3 directly

def pg_sql_statement(config, statement)
pg_command_base(config, 'psql', "-d #{config[:database]} -t -c \"#{statement}\"")
def pg_sql_statement(statement)
"psql -t -c \"#{statement}\""
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to pass in the statement via stdin but wonder if that works well with runuser (if we do that)

Copy link
Member Author

Choose a reason for hiding this comment

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

runuser is only used for local sql, and there we don't need statements.

Copy link
Member Author

Choose a reason for hiding this comment

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

that said, our execute helpers don't do stdin right now, so it'd need more refactoring.

"PGPASSWORD='#{config[:password]}' #{command} -U #{config[:username]} -h #{config[:host]} -p #{config[:port]} #{args}"
def pg_env(config)
{
'PGHOST' => config.fetch(:host, 'localhost'),
Copy link
Member

Choose a reason for hiding this comment

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

Do we need a default or can we trust psql to figure it out?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea, copied from your fm patch ;)

Copy link
Member

Choose a reason for hiding this comment

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

There I had it because local? compares to localhost and I didn't want to change that. Perhaps we should make it more robust so it can parse any postgresql url. I'd like to be able to use unix sockets and ident auth but now we'd break foreman-maintain

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we have remote_host?(hostname) which does something very similar.

The old code just assumed config[:host] is set (the command would be wrong if it were unset), which we can do here too?

@evgeni
Copy link
Member Author

evgeni commented Oct 18, 2024

Btw, if we don't need to ensure we've escaped the Puppet Ruby env we don't need to format the command and you could use Open3 directly

Yeah, but our helpers incorporate the escaping and I like helpers ;)

@ekohl
Copy link
Member

ekohl commented Oct 18, 2024

You can pass an array and avoid any escaping

@evgeni
Copy link
Member Author

evgeni commented Oct 21, 2024

You can pass an array and avoid any escaping

I meant the "escaping from Puppet ruby env".

My point is:

  • We have those helpers exactly to escape the Puppet ruby env, because we need it sometimes.
  • They also have logging and stuff wired in, which is nice
  • Our code is standardized on using those helpers
  • I do not want to have a special code that does not use the helpers, just because I don't need puppet-env-escaping.

So if we can drop the "puppet-env-escaping" all together, cool (but I think we can't, as we call f-m and f-rake, which need system ruby), but scope-creep. Here I just want to pass in PG things via env :)

@evgeni
Copy link
Member Author

evgeni commented Oct 21, 2024

/packit build

expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true)
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true, {})
Copy link
Member Author

Choose a reason for hiding this comment

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

runuser -l clears the environment, so that's why I did not use the env stuff here too.

@evgeni evgeni marked this pull request as ready for review October 21, 2024 09:17
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
# We don't want to list psych since that updates the bundled version
gem 'rdoc', '< 6.4'

gem 'kafo', '>= 7.3', '< 8'
gem 'kafo', github: 'theforeman/kafo'
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs updating once Kafo 7.6 is released with the feature (see theforeman/kafo#380), but other than that this is ready for review

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