Compare commits
1 Commits
master
...
fix/redact
| Author | SHA1 | Date | |
|---|---|---|---|
| 23b348a19c |
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user