Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

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.

Code

527 commit(s) on main

Put job execution behind an interface Keenan Nemetz · 2h ago de3eec16
history blame raw 863 B
1//go:build unix
2
3package secure
4
5import (
6 "fmt"
7 "os"
8)
9
10// tightenFile forces an existing secret file to FileMode and reports whether it
11// had to change anything.
12func 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.
24func 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}
34