vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
|
215f8aeb
Keenan Nemetz
2d ago
|
1 | //go:build unix |
| 2 | ||
| 3 | package secure | |
| 4 | ||
| 5 | import ( | |
| 6 | "fmt" | |
| 7 | "os" | |
| 8 | ) | |
| 9 | ||
| 10 | // tightenFile forces an existing secret file to FileMode and reports whether it | |
| 11 | // had to change anything. | |
| 12 | func tightenFile(path string, had os.FileMode) (bool, error) { | |
| 13 | if had == FileMode { | |
| 14 | return false, nil | |
| 15 | } | |
| 16 | if err := os.Chmod(path, FileMode); err != nil { | |
| 17 | return false, fmt.Errorf("%s is %04o and cannot be tightened to %04o: %w", path, had, FileMode, err) | |
| 18 | } | |
| 19 | return true, nil | |
| 20 | } | |
| 21 | ||
| 22 | // tightenDir removes world access from an existing directory and reports whether | |
| 23 | // it had to change anything. | |
| 24 | func tightenDir(path string, mode os.FileMode) (bool, error) { | |
| 25 | if mode&0o007 == 0 { | |
| 26 | return false, nil | |
| 27 | } | |
| 28 | want := mode &^ 0o007 | |
| 29 | if err := os.Chmod(path, want); err != nil { | |
| 30 | return false, fmt.Errorf("%s is %04o and cannot be tightened to %04o: %w", path, mode, want, err) | |
| 31 | } | |
| 32 | return true, nil | |
| 33 | } |