mirror of
https://github.com/zebrajr/ollama.git
synced 2025-12-06 00:19:51 +01:00
auth: check the permissions on the private key to see if it's readable (#12336)
This commit is contained in:
parent
ceac416ec2
commit
eb0a5d4459
18
auth/auth.go
18
auth/auth.go
|
|
@ -19,16 +19,28 @@ import (
|
|||
const defaultPrivateKey = "id_ed25519"
|
||||
|
||||
func keyPath() (string, error) {
|
||||
fileExists := func(fp string) bool {
|
||||
fileIsReadable := func(fp string) bool {
|
||||
info, err := os.Stat(fp)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
|
||||
// Check that it's a regular file, not a directory or other file type
|
||||
if !info.Mode().IsRegular() {
|
||||
return false
|
||||
}
|
||||
|
||||
// Try to open it to check readability
|
||||
file, err := os.Open(fp)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
file.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
systemPath := filepath.Join("/usr/share/ollama/.ollama", defaultPrivateKey)
|
||||
if fileExists(systemPath) {
|
||||
if fileIsReadable(systemPath) {
|
||||
return systemPath, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user