Skip to content

Conversation

l00ptr
Copy link
Collaborator

@l00ptr l00ptr commented Jan 24, 2025

We add an option / configuration item to define the permissions for the dumps created with pg_back. We reuse / configure the 0600 permissions by default to ensure some compatibility with the old (non configurable) approach.

We probably need to discuss and improve what we should do for the parent directory when using 'd' for the dump format. Currently we still apply the 0700 mode in such situation, but maybe we should define a specific option or reuse the one we add right now.

@l00ptr l00ptr force-pushed the add-option-for-file-or-dump-permissions branch from 8c02a6a to fe5219b Compare January 24, 2025 17:06
@l00ptr l00ptr marked this pull request as draft January 24, 2025 17:07
@l00ptr
Copy link
Collaborator Author

l00ptr commented Jan 24, 2025

Hi @orgrim,

This MR try to implement #132

I still want to improve it before some feedback about the code itself, but I think we should discuss about what we should do whith the parent directory when using the 'd' format and also we should also handle the situation where pg_back users simply want pg_back to use/respect the umask. What do you think we should do about those cases ?

Best regards,
Julian

@l00ptr l00ptr force-pushed the add-option-for-file-or-dump-permissions branch 2 times, most recently from d6e4304 to e774640 Compare January 24, 2025 17:31
@orgrim
Copy link
Owner

orgrim commented Jan 25, 2025

Hi @l00ptr, thanks a lot for taking care of this.

After a quick look: some lead on the default mode and how to "handle umask" would be to keep the current 0o600 mode for compatibility and use a negative value use to let the umask apply, since it ends up being store as a integer. What do you think?

On the directory format, I need to confirm if we are currently consistent on the permissions of all extra files, as this question applies to checksum files and others as well. I would expect the mode to be set once and applied everywhere.

While I need to test the patch, it looks promising.

Regards

@l00ptr
Copy link
Collaborator Author

l00ptr commented Jan 27, 2025

After a quick look: some lead on the default mode and how to "handle umask" would be to keep the current 0o600 mode for compatibility and use a negative value use to let the umask apply, since it ends up being store as a integer. What do you think?

Hi @l00ptr, thanks a lot for taking care of this.

After a quick look: some lead on the default mode and how to "handle umask" would be to keep the current 0o600 mode for compatibility and use a negative value use to let the umask apply, since it ends up being store as a integer. What do you think?

good idea, done within the fixup.

On the directory format, I need to confirm if we are currently consistent on the permissions of all extra files, as this question applies to checksum files and others as well. I would expect the mode to be set once and applied everywhere.

I'll also look into how checksums (files) are generated and written (and how file permissions are set for them).

While I need to test the patch, it looks promising.

Regards

@l00ptr l00ptr force-pushed the add-option-for-file-or-dump-permissions branch 3 times, most recently from afc72d0 to 274c33d Compare February 6, 2025 15:38
@l00ptr l00ptr marked this pull request as ready for review February 6, 2025 15:39
@l00ptr
Copy link
Collaborator Author

l00ptr commented Feb 6, 2025

i have done some modification to also handle changing permission on hash and encrypted files. directory permission still probably need some improvement. @orgrim could you make a first overall review on this ?

Best regards,

@l00ptr
Copy link
Collaborator Author

l00ptr commented Mar 10, 2025

Hi @orgrim

How can i help to test and integrate that MR ? What can I provide to help you on this ?

Best regards,
J.

Copy link
Owner

@orgrim orgrim left a comment

Choose a reason for hiding this comment

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

This looks good, please

  • Use backup_file_mode for the name of the config option to match the cli option
  • Handle the mode of the directory format

main.go Outdated
// directory, this won't make the contents executable
// we keep this for compatibility reason, but since file mode is under
// user control, we should probably remove this
mode = 0700
Copy link
Owner

Choose a reason for hiding this comment

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

The directory format should be handled as best as possible. I'd imagine a user would expect that if mode is set to 0640, the directory would be chmod to 0750 and its contents to 0640.

On the file, it's ease, just walk the contents of the directory and os.Chmod to the given mode.

Deducing the mode of the directory is trickier. What do you think of "grant x when r or w is present in the mode for each category of users"?

I mean:

if (mode & 0o400 > 0) || (mode & 0o200 > 0) {
	mode = mode | 0o100
}

/// and os on to add 0o010 and 0o001

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done this way, i think it's a first good approach... but may be we should add a specific settings to configure the permission on the root directory when using the directory format.

Copy link
Owner

Choose a reason for hiding this comment

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

The update of the mode should be done also for the "group" and "other" bits, in a similar way. Apart from that, LGTM.

Copy link
Owner

Choose a reason for hiding this comment

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

IMO, just updating the permission for the directory like this (for the group and other as well) is enough to have something that work for the vast majority of use cases. So no need to add an extra configuration parameter for the directory format.

@orgrim
Copy link
Owner

orgrim commented Apr 20, 2025

This fixes #132

Also, do not hesitate to rebase, the CI is fixed in the master branch

@orgrim orgrim linked an issue Apr 20, 2025 that may be closed by this pull request
@l00ptr l00ptr force-pushed the add-option-for-file-or-dump-permissions branch 3 times, most recently from 261c57d to 1020c86 Compare April 22, 2025 20:41
Add an option / configuration item to define the permissions for the
dumps and hash files created by pg_back. The 0600 permissions mode is
defined by default to ensure compatibility with the old (non configurable)
approach.

pg_back adds appropriate (+x) permission for parent directory when using
the 'd' (AKA directory) dump format, files under the parent directory use
the permission configured by the user (though backup_file_mode).
@l00ptr l00ptr force-pushed the add-option-for-file-or-dump-permissions branch from 1020c86 to a7e92a7 Compare April 23, 2025 06:54
@orgrim orgrim merged commit f3bcdc0 into orgrim:master May 1, 2025
9 checks passed
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.

Set permission for dump files
2 participants