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

Can zap support dedicate file permission for log? #860

Open
iamjackhu opened this issue Aug 31, 2020 · 4 comments
Open

Can zap support dedicate file permission for log? #860

iamjackhu opened this issue Aug 31, 2020 · 4 comments

Comments

@iamjackhu
Copy link

When set logpath for zap, it always to create with file mode 0644 for log file.

Does it support dedicate file permission mode, such as 0664?

@prashantv
Copy link
Collaborator

It's not possible to customize the permissions used for creating the file. However, this permission is only used if the file doesn't exist, so if you want a custom file permission, create the file beforehand with the permission you want, and then zap will use the existing file.

@jcorbin
Copy link
Contributor

jcorbin commented Aug 31, 2020

It's not possible to customize the permissions used for creating the file. However, this permission is only used if the file doesn't exist, so if you want a custom file permission, create the file beforehand with the permission you want, and then zap will use the existing file.

So, this isn't quite right:

  • the typical way of customizing, especially in a scenario where one wants group write, is via umask
  • the correct thing for an application that doesn't care per-se about file permissions is to pass 0666 or 0777 to syscalls like os.OpenFile and os.Mkdir
  • the OS then applies umask and you end up with 0644 or 0755 typically
  • only security sensitive apps typically pass otherwise, and then it's things like 0700 or 0600 for something like a private key file
  • usually when you see os.OpenFile with 0644, the developer didn't actually care, and their intent was "standard / default behavior", which should have been 0666

@prashantv
Copy link
Collaborator

Sorry, I meant it's not possible to customize the permission value used by zap, it's hard-coded today and we don't have an easy way to customize it.

We can definitely change it to 0666 and rely on the umask.

@jcorbin
Copy link
Contributor

jcorbin commented Aug 31, 2020

Also, look no further than os.Create for "what should the defaults be?" The only reason that zap doesn't uses os.Create is due to wanting append semantics rather than truncation, but it shouldn't be over-specifying the mode like this

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

No branches or pull requests

3 participants