Compare commits

...

1 Commits

Author SHA1 Message Date
eb76daaaba fix: redact sandbox token and enable CI lint (#104)
All checks were successful
submodules sync / sync (push) Successful in 44s
build / build (push) Successful in 1m47s
build / trigger-build-image (push) Successful in 6s
Reviewed-on: #104
Co-authored-by: Boming Zhang <bomingzh@sjtu.edu.cn>
Co-committed-by: Boming Zhang <bomingzh@sjtu.edu.cn>
2026-08-03 18:31:36 +08:00
3 changed files with 36 additions and 2 deletions

View File

@ -19,8 +19,8 @@ jobs:
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519.pub
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub chmod 600 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222 ssh -o StrictHostKeyChecking=accept-new -T git@focs.gc.sjtu.edu.cn -p 2222
# - name: Lint - name: Lint
# run: make lint run: make lint
- name: Build - name: Build
run: make build run: make build
- name: Version - name: Version

View File

@ -1,8 +1,10 @@
package conf package conf
import ( import (
"bytes"
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"log/slog"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -10,6 +12,26 @@ import (
"testing" "testing"
) )
func TestConfLogValueRedactsSandboxToken(t *testing.T) {
var output bytes.Buffer
logger := slog.New(slog.NewJSONHandler(&output, nil))
conf := &Conf{
Name: "test",
SandboxToken: "top-secret-token",
}
logger.Info("config", "conf", conf)
got := output.String()
if strings.Contains(got, "top-secret-token") {
t.Fatalf("configuration log exposed sandbox token: %s", got)
}
if !strings.Contains(got, "[REDACTED]") || !strings.Contains(got, `"Name":"test"`) {
t.Fatalf("configuration log lost expected diagnostic fields: %s", got)
}
if conf.SandboxToken != "top-secret-token" {
t.Fatalf("logging mutated the runtime configuration: %q", conf.SandboxToken)
}
}
func TestGetSHA256(t *testing.T) { func TestGetSHA256(t *testing.T) {
path := filepath.Join(t.TempDir(), "input") path := filepath.Join(t.TempDir(), "input")
content := []byte("joj3") content := []byte("joj3")

View File

@ -1,6 +1,8 @@
package conf package conf
import ( import (
"log/slog"
"github.com/joint-online-judge/JOJ3/internal/stage" "github.com/joint-online-judge/JOJ3/internal/stage"
) )
@ -32,6 +34,16 @@ type Conf struct {
PostStages []ConfStage PostStages []ConfStage
} }
// LogValue preserves the configuration's diagnostic value without writing the
// sandbox credential to text or structured logs.
func (c Conf) LogValue() slog.Value {
type logConf Conf
if c.SandboxToken != "" {
c.SandboxToken = "[REDACTED]"
}
return slog.AnyValue(logConf(c))
}
type OptionalCmd struct { type OptionalCmd struct {
Args *[]string Args *[]string
Env *[]string Env *[]string