Skip to content

Commit 72660a8

Browse files
committed
Set permisions of encrypted files in the dir format
1 parent f3bcdc0 commit 72660a8

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func TestParseCli(t *testing.T) {
515515
[]string{"--delete-uploaded", "yes"},
516516
options{
517517
Directory: "/var/backups/postgresql",
518+
Mode: 0o600,
518519
Format: 'c',
519520
DirJobs: 1,
520521
CompressLevel: -1,
@@ -544,6 +545,7 @@ func TestParseCli(t *testing.T) {
544545
[]string{"--delete-uploaded", "true"},
545546
options{
546547
Directory: "/var/backups/postgresql",
548+
Mode: 0o600,
547549
Format: 'c',
548550
DirJobs: 1,
549551
CompressLevel: -1,

crypto.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ func encryptFile(path string, mode int, params encryptParams, keep bool) ([]stri
169169
}
170170

171171
encrypted = append(encrypted, dstFile)
172+
if mode > 0 {
173+
if err := os.Chmod(dstFile, os.FileMode(mode)); err != nil {
174+
return fmt.Errorf("could not chmod to more secure permission for encrypted file: %w", err)
175+
}
176+
}
172177

173178
if !keep {
174179
l.Verboseln("removing source file:", path)

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,20 @@ func (d *dump) dump(fc chan<- sumFileJob) error {
750750
if (mode&0o400 > 0) || (mode&0o200 > 0) {
751751
mode = mode | 0o100
752752
}
753+
754+
if (mode&0o040 > 0) || (mode&0o020 > 0) {
755+
mode = mode | 0o010
756+
}
757+
758+
if (mode&0o004 > 0) || (mode&0o002 > 0) {
759+
mode = mode | 0o001
760+
}
753761
}
762+
754763
if err := os.Chmod(file, mode); err != nil {
755764
return fmt.Errorf("could not chmod to more secure permission for %s: %w", dbname, err)
756765
}
766+
757767
if isDirFormat {
758768
// adapt mode on files on directory based on initial configured mode
759769
if err := recursiveChmod(file, os.FileMode(d.Mode)); err != nil {

pg_back.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ backup_directory = /var/backups/postgresql
1414
# disable modifying permission and let the system handle that (example when
1515
# umask is defined). When the format is set to directory, pg_back ensures
1616
# the top-level directory is traversable by adding execute (+x) permission
17-
# if read (r) or write (w) permission is set. This does not affect the
17+
# if read (r) or write (w) permission is set and it set the configured
1818
# permissions of files inside the directory.
1919
backup_file_mode = 0600
2020

0 commit comments

Comments
 (0)