archivault 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c3fafb7a999944ce6e513420f1e90a1f842a7460c6364d69b71a9d6158b8453
4
- data.tar.gz: 325edbcd21420a5079857f8e317a292587787579d3580e819c6da8dc93cac5ce
3
+ metadata.gz: a4ec8f7f88e54372cf70eb0e07e637c34561ddc888ec4ef4ccb53275c64d3993
4
+ data.tar.gz: 8b89b5f12ae91effaad05cf5add3ce8a0e58bd43cce1ac0d7482505f751ac464
5
5
  SHA512:
6
- metadata.gz: 7901b70a33e62c64bce142a02437a2ffbe520249b56ccc899403e2068f7e34fdb5c23189af5c9d65c9c0ba7e5844d04bcbf088a3b095bf28054b12d82edc709f
7
- data.tar.gz: e6e05ca1b5671138ad04ab9a1f349cf4401912e7c22816b49826f0a740f63105be7178b0305275be7e3505086e9adda48c75bce2ee11683b5b20e931f2f7d511
6
+ metadata.gz: 03cf209ecb7fbc7f1bb6af70ecc290d9ca302aa63bd6c4d07c07ad0605d0cccf42d44680a5ca3beb3ae80e63299aa965177b708ca1bc22015bdb041f319b0706
7
+ data.tar.gz: c3232861b94738f32449782c035df357d4ef2ab94859c848821b7ec8af450daf490a93e2a0543a79978d3c8e1628c570a48ec6421ce7fbd0848e265b5f558d6f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ - Add an unguessable random suffix to backup file names, so a PutObject-only S3 key cannot target (overwrite) existing backups
4
+ - Pass decoded PostgreSQL URL passwords to pg_dump through PGPASSWORD instead of command-line arguments, and prevent password leaks in invalid URL errors
5
+ - Allow Execute to forward environment variables and system options
6
+
3
7
  ## [0.2.1] - 2026-09-03
4
8
 
5
9
  - Allow custom database backup filename prefixes
@@ -4,8 +4,8 @@ require "English"
4
4
 
5
5
  module Archivault
6
6
  class Execute
7
- def call(command, *)
8
- status = system(command, *)
7
+ def call(command, *, env: {}, **)
8
+ status = system(env, command, *, **)
9
9
  raise ExecuteError, "#{command} could not be executed" if status.nil?
10
10
  raise ExecuteError, "#{command} failed with exit code #{$CHILD_STATUS&.exitstatus}" unless status
11
11
 
@@ -16,9 +16,8 @@ module Archivault
16
16
  @s3_setup = s3_setup
17
17
  @ping_url = ping_url
18
18
 
19
- @timestamp = Timestamp.new.timestamp
20
19
  @tmp_path = Tmp.new.path
21
- @tar_path = "#{@tmp_path}/logs-#{@timestamp}.tgz"
20
+ @tar_path = "#{@tmp_path}/#{Timestamp.new.backup_name("logs")}.tgz"
22
21
  @gpg_path = "#{@tar_path}.gpg"
23
22
  end
24
23
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # To restore a database from a dump file, use:
4
- # pg_restore --no-owner -d DATABASE_URL database.dump
4
+ # pg_restore --clean --if-exists --no-owner --no-acl --role=db-role -U postgres -d db-name /tmp/db.dump
5
5
  module Archivault
6
6
  class PgDump
7
7
  def initialize(database_url:, backup_path:)
@@ -12,8 +12,23 @@ module Archivault
12
12
  @backup_path = backup_path.to_s
13
13
  end
14
14
 
15
+ # The password goes to pg_dump through PGPASSWORD, not through the command line:
16
+ # arguments of a running process are readable by every local user (ps, /proc/<pid>/cmdline).
15
17
  def call
16
- Execute.new.call("pg_dump", "-Fc", "-f", @backup_path, @database_url)
18
+ uri = parse_database_url
19
+ password = URI.decode_uri_component(uri.password) if uri.password && !uri.password.empty?
20
+ uri.password = nil
21
+ env = password ? { "PGPASSWORD" => password } : {}
22
+ Execute.new.call("pg_dump", "-Fc", "-f", @backup_path, uri.to_s, env: env)
23
+ end
24
+
25
+ private
26
+
27
+ def parse_database_url
28
+ URI.parse(@database_url)
29
+ rescue URI::InvalidURIError
30
+ # URI::InvalidURIError quotes the whole input, password included - re-raise without it.
31
+ raise "Invalid database URL: percent-encode special characters in the password", cause: nil
17
32
  end
18
33
  end
19
34
  end
@@ -17,9 +17,8 @@ module Archivault
17
17
  @s3_setup = s3_setup
18
18
  @ping_url = ping_url
19
19
 
20
- @timestamp = Timestamp.new.timestamp
21
20
  @tmp_path = Tmp.new.path
22
- backup_filename = "#{filename || "database"}-#{@timestamp}"
21
+ backup_filename = Timestamp.new.backup_name(filename || "database")
23
22
  @backup_path = "#{@tmp_path}/#{backup_filename}.dump"
24
23
  @tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
25
24
  @gpg_path = "#{@tar_path}.gpg"
@@ -17,9 +17,8 @@ module Archivault
17
17
  @s3_setup = s3_setup
18
18
  @ping_url = ping_url
19
19
 
20
- @timestamp = Timestamp.new.timestamp
21
20
  @tmp_path = Tmp.new.path
22
- backup_filename = "#{filename || "database"}-#{@timestamp}"
21
+ backup_filename = Timestamp.new.backup_name(filename || "database")
23
22
  @backup_path = "#{@tmp_path}/#{backup_filename}.sqlite3"
24
23
  @tar_path = "#{@tmp_path}/#{backup_filename}.tgz"
25
24
  @gpg_path = "#{@tar_path}.gpg"
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
4
+
3
5
  module Archivault
4
6
  class Timestamp
5
7
  attr_reader :timestamp
@@ -7,5 +9,11 @@ module Archivault
7
9
  def initialize
8
10
  @timestamp = Time.now.strftime("%Y-%m-%d-%H-%M")
9
11
  end
12
+
13
+ # The backup S3 key may only PutObject, which can also overwrite an existing object.
14
+ # It can't list the bucket, so an unguessable suffix keeps it from targeting existing backups.
15
+ def backup_name(prefix)
16
+ "#{prefix}-#{timestamp}-#{SecureRandom.hex(8)}"
17
+ end
10
18
  end
11
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Archivault
4
- VERSION = "0.2.1"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archivault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Macuk