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

PostgreSQL credentials not being escaped properly #581

Closed
jeffreyguenther opened this issue Sep 4, 2014 · 5 comments
Closed

PostgreSQL credentials not being escaped properly #581

jeffreyguenther opened this issue Sep 4, 2014 · 5 comments
Labels

Comments

@jeffreyguenther
Copy link

It looks like the gzip is failing because of something happening in the postgres dump:

[2014/09/04 18:38:54][info] Database::PostgreSQL Started...
[2014/09/04 18:38:54][info] Using Compressor::Gzip for compression.
[2014/09/04 18:38:54][info]   Command: '/bin/gzip'
[2014/09/04 18:38:54][info]   Ext: '.gz'
[2014/09/04 18:38:54][warn]   Pipeline STDERR Messages:
[2014/09/04 18:38:54][warn]   (Note: may be interleaved if multiple commands returned error messages)
[2014/09/04 18:38:54][warn]
[2014/09/04 18:38:54][warn]   sh: 1: Syntax error: Unterminated quoted string
[2014/09/04 18:38:54][info] Database::PostgreSQL Finished!

When I check the backups folder, the archive is not compressed.

Here is my model.

Model.new(:production, 'Backup the sustainabilityassessment') do
  archive :nginx_config do |archive|
    # Run the `tar` command using `sudo`
    # archive.use_sudo
    # add nginx configs
    archive.add "/etc/nginx/sites-available/"
    # add environment variable script
    archive.add "/etc/profile.d/embeddingsustainability.sh"
  end

  ##
  # PostgreSQL [Database]
  #
  database PostgreSQL do |db|
    # To dump all databases, set `db.name = :all` (or leave blank)
    db.name               = "sustainabilityassessment"
    db.username           = "sustainabilityassessment"
    db.password           = "[password]"
    db.host               = "localhost"
    db.port               = 5432
    db.socket             = "/tmp/pg.sock"
    db.additional_options = ["-xc", "-E=utf8"]
  end

  ##
  # Gzip [Compressor]
  #
  compress_with Gzip

  ##
  # Local (Copy) [Storage]
  #
  store_with Local do |local|
    local.path       = "~/backups/"
    local.keep       = 10
  end

  ##
  # Mail [Notifier]
  #
  # The default delivery method for Mail Notifiers is 'SMTP'.
##
  # Mail [Notifier]
  #
  # The default delivery method for Mail Notifiers is 'SMTP'.
  # See the documentation for other delivery options.
  #
  notify_by Mail do |mail|
    ...
  end

end
@jeffreyguenther
Copy link
Author

The cause of the issue is because there was an apostrophe in my password. It is not being escaped when the shell script is generated.

To allow passwords with any sort of characters I think sh and bash reserved characters should be escaped.

@tombruijn
Copy link
Member

We've had a similar issue in #552 recently. I pushed the postgres_escaped_params branch on this repo, could you try it out @jrguenther and let me know if it worked?

Add this to your Gemfile instead of the gem 'backup' line:

gem "backup", git: "https://github.com/meskyanichi/backup.git", ref: "postgres_escaped_params"

@jeffreyguenther
Copy link
Author

I confirm your fix works as expected.

@tombruijn
Copy link
Member

Fix is included in the just released v4.0.5

@tombruijn tombruijn changed the title Getting an warning using Gzip compressor PostgreSQL credentials not being escaped properly Sep 8, 2014
@jeffreyguenther
Copy link
Author

Awesome! I'll update my server,

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

No branches or pull requests

2 participants