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

Use environment instead of pgpass file #6328

Merged
merged 2 commits into from
Jul 14, 2016
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Jan 25, 2016

blocked on: ManageIQ/awesome_spawn#34

  • removes potential threading conflicts
  • no longer writes passwords to text files
  • no longer tied to root user
  • no longer blows away customer created .pgpass file.
  • now can run tasks on password protected databases.
  • now works on mac, linux, and appliances.
  • less code

/cc @Fryguy @jrafanie @carbonin

@Fryguy would it be ok to release awesome_spawn? feature was added there in August THANKS

UPDATE: allow passwords to be specified and database dumps to work. Added testing instructions below

File.delete(PGPASS_FILE) if opts[:password]
AwesomeSpawn.run!(cmd_str, :params => params, :env => {
"PGUSER" => opts[:username],
"PGPASSWORD" => opts[:password]}).output
Copy link
Member

Choose a reason for hiding this comment

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

If this works, 👍

Copy link
Member

Choose a reason for hiding this comment

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

I see we aren't using the opts[:dbname], will this work if the dbname for the cmd_str is ambiguous?

Copy link
Member Author

Choose a reason for hiding this comment

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

Before:
The command line arguments (cmd_str and params) needs to specify the username and dbname.
The dbname in .pgpass helps libpg determine which password to use.

After:
The command line still needs to specify the username and database name.
The environment variables helps libpg determine which password to use.

It looks like PGUSER will not be read because we are specifying the username on the command line.
We could specify PGDATABASE, but it would not be read because we are specifying that too on the command line.

@jrafanie Those 2 fields are redundant. I can:

  1. add PGDATABASE
  2. remove PGUSER
  3. OR leave as is

I'm more than happy with any of those 3 solutions.

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 suggest we change the callers to do the right thing if we're not... specify everything we need to specific. I believe it's isolated to just a handful of locations. I don't remember if there was a reason I did a pgpass file instead of environment variables.

Either way, if you are able to do a backup and restore from an appliance using your changes, I think we can fix the fallout in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm leaning towards option 3.

@kbrock kbrock changed the title Use environment instead of pgpass file [WIP] Use environment instead of pgpass file Jan 26, 2016
@chessbyte chessbyte added the wip label Jan 26, 2016
@kbrock kbrock removed the wip label Jan 27, 2016
@kbrock kbrock changed the title [WIP] Use environment instead of pgpass file Use environment instead of pgpass file Jan 27, 2016
@chessbyte
Copy link
Member

@gtanzillo please review

@chessbyte
Copy link
Member

@kbrock @jrafanie what is the status of this PR?

@kbrock
Copy link
Member Author

kbrock commented Feb 11, 2016

@jrafanie I'm not sure what you wanted to do here. Remove the PGUSER?

@jrafanie
Copy link
Member

Either way, if you are able to do a backup and restore from an appliance using your changes, I think we can fix the fallout in the future.

To clarify, if you can run these rake tasks on an appliance, I'm fine with the changes. These should cover the use cases I was concerned about:

rake evm:db:backup:local
rake evm:db:backup:remote
rake evm:db:gc
rake evm:db:restore:local
rake evm:db:restore:remote

The backup/restore args are documented in the rake task here

If you have ideas on how to unit test these, I'm all 👂

@gtanzillo
Copy link
Member

@kbrock I'm ok with these changes as long as you are able to verify that it does not break the rake tasks that @jrafanie mentioned above. Have you been able to test them?

@miq-bot
Copy link
Member

miq-bot commented Mar 23, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@chessbyte
Copy link
Member

@kbrock any interest in completing this?

@kbrock
Copy link
Member Author

kbrock commented Apr 27, 2016

Thanks - I'll test the rake tasks here and rebase

@chriskacerguis
Copy link
Contributor

@kbrock can you please rebase?

@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@kbrock
Copy link
Member Author

kbrock commented Jun 21, 2016

@jrafanie so I started digging into this

  1. change pg_hba.conf s/trust/md5/g meaning, require password from everyone.
  2. run bundle exec rake evm:db:backup:local

I can't figure out how to even get a password into the system to backup the database.

Since most appliances are setup to trust, this problem is not evident.
I had expected to type --password or for it to parse database.yml

So we have a few options:

  1. delete the password handling all together
  2. allow password to be passed in
  3. just default the values from database.yml

@kbrock kbrock changed the title Use environment instead of pgpass file [WIP] Use environment instead of pgpass file Jul 11, 2016
@kbrock kbrock added the wip label Jul 11, 2016
@kbrock
Copy link
Member Author

kbrock commented Jul 11, 2016

WIPing: this functionality is never used. no password can be passed in

kbrock and others added 2 commits July 11, 2016 16:48
- no potential conflicts
- not writing passwords to text files
- no longer tied to root user
- now works on mac
- less code
@kbrock kbrock removed the wip label Jul 11, 2016
@kbrock kbrock changed the title [WIP] Use environment instead of pgpass file Use environment instead of pgpass file Jul 11, 2016
@kbrock
Copy link
Member Author

kbrock commented Jul 11, 2016

@jrafanie let me know if your now good with this.

@miq-bot
Copy link
Member

miq-bot commented Jul 11, 2016

Checked commits kbrock/manageiq@0dcef4f~...2a1402b with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
3 files checked, 0 offenses detected
Everything looks good. 🍪

@gtanzillo
Copy link
Member

@carbonin @jrafanie Are you guys ok with this change?

@jrafanie
Copy link
Member

@kbrock can you confirm you tested this?

@kbrock
Copy link
Member Author

kbrock commented Jul 13, 2016

@jrafanie I did the following on a mac:

  1. modified pg_hba.conf to require a password for vmdb_development
  2. bundle exec rake evm:db:backup:local # fails
  3. git checkout pr/6328
  4. bundle exec rake evm:db:backup:local # succeeds

@jrafanie
Copy link
Member

jrafanie commented Jul 13, 2016

Thanks @kbrock. I'm ok with this. Since @carbonin is in this neck of the woods with HA/replication... I'll wait for his 👍 before merging.

@carbonin
Copy link
Member

Looks good 👍

@jrafanie jrafanie merged commit 9a714af into ManageIQ:master Jul 14, 2016
@jrafanie jrafanie added this to the Sprint 44 Ending Aug 1, 2016 milestone Jul 14, 2016
@kbrock kbrock deleted the pgpass_be_gone branch July 14, 2016 14:22
@simaishi
Copy link
Contributor

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

Successfully merging this pull request may close these issues.

None yet

8 participants