-
-
Notifications
You must be signed in to change notification settings - Fork 941
Open
Description
https://github.com/lib/pq/blob/master/internal/pqutil/perm.go
func checkPermissions(fi os.FileInfo) error {
// The maximum permissions that a private key file owned by a regular user
// is allowed to have. This translates to u=rw. Regardless of if we're
// running as root or not, 0600 is acceptable, so we return if we match the
// regular user permission mask.
if fi.Mode().Perm()&os.FileMode(0777)^0600 == 0 {
return nil
}
// We need to pull the Unix file information to get the file's owner.
// If we can't access it, there's some sort of operating system level error
// and we should fail rather than attempting to use faulty information.
sys, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
return ErrSSLKeyUnknownOwnership
}
// if the file is owned by root, we allow 0640 (u=rw,g=r) to match what
// Postgres does.
if sys.Uid == 0 {
// The maximum permissions that a private key file owned by root is
// allowed to have. This translates to u=rw,g=r.
if fi.Mode().Perm()&os.FileMode(0777)^0640 != 0 {
return ErrSSLKeyHasWorldPermissions
}
return nil
}
return ErrSSLKeyHasWorldPermissions
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels