6042955498
build / build (push) Successful in 1m59s
现象:CI run 347 / job 362 在 security-secrets 失败,指向 cmd/object-gateway/main_test.go:30 的 pg-url 类别。 根因:该 DSN 只用于 127.0.0.1:1 故意不可达连接,验证启动能越过 配置阶段到达 journal/后端准入,本身不需要任何口令,却写成了带口令形式。 取舍:直接换成合法无口令 URL,不拆秘密字符串隐藏检测、不改扫描器/基线/ 必需项范围。产品代码与测试行为不变。 证据:check_secrets.py 由 exit 1(指向该行)转为 exit 0;go test ./cmd/object-gateway 通过;umask 022 下 make verify 16 项本地必需全 success。
83 lines
2.9 KiB
Go
83 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/base64"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// startErrorMessage builds the addressed binary and runs it long enough to
|
|
// observe why the real entry point refused to listen.
|
|
func startErrorMessage(t *testing.T, extra ...string) (string, int) {
|
|
t.Helper()
|
|
bin := filepath.Join(t.TempDir(), "object-gateway")
|
|
build := exec.Command("go", "build", "-o", bin, ".")
|
|
if out, err := build.CombinedOutput(); err != nil {
|
|
t.Fatalf("build gateway: %v\n%s", err, out)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
cmd := exec.CommandContext(ctx, bin)
|
|
cmd.Env = append([]string{
|
|
"PATH=" + os.Getenv("PATH"),
|
|
"HOME=" + os.Getenv("HOME"),
|
|
"OBJECT_GATEWAY_LISTEN=127.0.0.1:0",
|
|
"OBJECT_GATEWAY_DATABASE_URL=postgres://gateway@127.0.0.1:1/gateway?sslmode=disable&connect_timeout=2",
|
|
"OBJECT_GATEWAY_PROVIDER=minio",
|
|
"OBJECT_GATEWAY_ENDPOINT=http://127.0.0.1:19100",
|
|
"OBJECT_GATEWAY_BUCKET=maintenance-fixture-bucket",
|
|
"OBJECT_GATEWAY_REGION=us-east-1",
|
|
"OBJECT_GATEWAY_ACCESS_KEY=fixture-access-key",
|
|
"OBJECT_GATEWAY_SECRET_KEY=fixture-secret-key",
|
|
"OBJECT_GATEWAY_DATA_TOKEN=" + strings.Repeat("d", 32),
|
|
"OBJECT_GATEWAY_CONTROL_TOKEN=" + strings.Repeat("c", 32),
|
|
}, extra...)
|
|
out, err := cmd.CombinedOutput()
|
|
if ctx.Err() != nil {
|
|
t.Fatalf("gateway did not terminate; output=%s", out)
|
|
}
|
|
code := 0
|
|
if exit, ok := err.(*exec.ExitError); ok {
|
|
code = exit.ExitCode()
|
|
} else if err != nil {
|
|
t.Fatalf("run gateway: %v", err)
|
|
}
|
|
return string(out), code
|
|
}
|
|
|
|
// The default shared-bucket path must not require a whole-bucket exclusive
|
|
// writer attestation. Only the journal/backend admission gate may refuse it,
|
|
// and a stale attestation file left behind by an older deployment must not
|
|
// gate the default path either.
|
|
func TestGatewayEntrypointDoesNotRequireBucketAttestation(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
env []string
|
|
}{
|
|
{name: "no_audit_configured"},
|
|
{name: "stale_audit_file_ignored", env: []string{
|
|
"OBJECT_GATEWAY_ID=retired-gateway",
|
|
"OBJECT_GATEWAY_AUDIT_FILE=/nonexistent/expired-attestation.json",
|
|
"OBJECT_GATEWAY_AUDIT_PUBLIC_KEY=" + base64.StdEncoding.EncodeToString(make([]byte, 32)),
|
|
}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
out, code := startErrorMessage(t, tc.env...)
|
|
if code == 0 {
|
|
t.Fatalf("gateway exited 0 instead of reporting its admission state: %s", out)
|
|
}
|
|
if strings.Contains(out, "gateway_auditor_key_required") || strings.Contains(out, "gateway_exclusive_writer_evidence_unverified") {
|
|
t.Fatalf("shared-bucket admission still gated by whole-bucket attestation: %s", out)
|
|
}
|
|
if !strings.Contains(out, "gateway_persistence_unavailable") && !strings.Contains(out, "gateway_backend_not_ready") {
|
|
t.Fatalf("gateway did not reach journal/backend admission: %s", out)
|
|
}
|
|
})
|
|
}
|
|
}
|