Skip to content

ssl key mode 400 can not used #1257

@tl321

Description

@tl321

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions