fix: apply security patches for configuration file and local executor #97

Closed
蔡雨翔524370910013 wants to merge 1 commits from arthurcai/JOJ3:master into master
2 changed files with 22 additions and 2 deletions
Showing only changes of commit 0a2d783dcd - Show all commits

View File

@ -13,6 +13,7 @@ import (
"path/filepath"
"regexp"
"strings"
"syscall"
"github.com/go-git/go-git/v5"
"github.com/koding/multiconfig"
@ -183,6 +184,19 @@ func GetConfPath(confRoot, confName, fallbackConfName, msg, tag string) (
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 {

Will the conf file be owned by root?

Will the conf file be owned by root?
Review

i was wondering the same: we have student and tt. i think no other user (including root) is involved.

i was wondering the same: we have `student` and `tt`. i think no other user (including `root`) is involved.

Then uid != 0 is not needed.

Then uid != 0 is not needed.
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)

What if we just terminate it here?

What if we just terminate it here?
Review

maybe end + write logs to raise an alert on grafana?

maybe end + write logs to raise an alert on grafana?
}
return confPath, confStat, conventionalCommit, err
}

View File

@ -3,12 +3,18 @@
// used for passing run time parameters.
package local
import "github.com/joint-online-judge/JOJ3/internal/stage"
import (
"os"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
var name = "local"
type Local struct{}
func init() {
stage.RegisterExecutor(name, &Local{})
if os.Getenv("JOJ3_ENABLE_LOCAL_EXECUTOR") == "true" {

Where is it used?

Where is it used?

Just thinking that the Local executor is unsafe if conf.go is bypassed, so you can add an env for the students' executor so that it doesn't run the local executor, while other usages can still be fulfilled.

Just thinking that the Local executor is unsafe if conf.go is bypassed, so you can add an env for the students' executor so that it doesn't run the local executor, while other usages can still be fulfilled.

What does it mean by students' executor?

What does it mean by students' executor?

What does it mean by students' executor?

I found that I'm wrong. Many stages seem to use the local executor.

> What does it mean by students' executor? I found that I'm wrong. Many stages seem to use the local executor.

This part is not needed.

This part is not needed.
stage.RegisterExecutor(name, &Local{})
}
}