fix: apply security patches for configuration file and local executor
This commit is contained in:
parent
0a5b3bdc71
commit
0a2d783dcd
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
"github.com/koding/multiconfig"
|
"github.com/koding/multiconfig"
|
||||||
|
|
@ -183,6 +184,19 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
|
||||||
return confPath, confStat, conventionalCommit, err
|
return confPath, confStat, conventionalCommit, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check file ownership
|
||||||
|
if stat, ok := confStat.Sys().(*syscall.Stat_t); ok {
|
||||||
|
uid := int(stat.Uid)
|
||||||
|
currentUid := os.Getuid()
|
||||||
|
if uid != 0 && uid != currentUid {
|
||||||
|
err = fmt.Errorf("insecure configuration file: owned by uid %d, expected 0 or %d", uid, currentUid)
|
||||||
|
slog.Error("insecure conf file", "path", confPath, "uid", uid, "expected_uid", currentUid)
|
||||||
|
return confPath, confStat, conventionalCommit, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slog.Warn("could not determine file ownership, proceeding with caution", "path", confPath)
|
||||||
|
}
|
||||||
|
|
||||||
return confPath, confStat, conventionalCommit, err
|
return confPath, confStat, conventionalCommit, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,18 @@
|
||||||
// used for passing run time parameters.
|
// used for passing run time parameters.
|
||||||
package local
|
package local
|
||||||
|
|
||||||
import "github.com/joint-online-judge/JOJ3/internal/stage"
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
|
)
|
||||||
|
|
||||||
var name = "local"
|
var name = "local"
|
||||||
|
|
||||||
type Local struct{}
|
type Local struct{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
stage.RegisterExecutor(name, &Local{})
|
if os.Getenv("JOJ3_ENABLE_LOCAL_EXECUTOR") == "true" {
|
||||||
|
stage.RegisterExecutor(name, &Local{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user