mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-14 20:20:54 +08:00
Seal the four credential columns with AES-256-GCM (random nonce per value,
AAD "<table>.<column>"): llm_profiles.api_key and task_credentials.password
store "enc:v1:<base64(nonce||ciphertext)>"; mcp_servers.env and
notification_channels.config store {"__artex_enc":"enc:v1:..."} over the
canonical JSON. The db layer encrypts on write and decrypts on read, so agent
tools (LLM provider, MCP, notifier, test credentials) get plaintext
server-side. Decryption failure is an error, never a plaintext fallback.
Key: ARTEX_SECRET_KEY (32 bytes, base64 or hex) or keys/secret.key next to
jwt.key, generated with crypto/rand at first start (0600). Startup refuses
when encrypted values exist and no key is available, and when the key does
not decrypt them. An idempotent backfill under the schema advisory lock
encrypts legacy plaintext rows and logs only a count.
API: MCP env is masked on read and masked placeholders on write keep the
stored value; task credential passwords are masked server-side and a masked
password on write is refused. ARTEX_SECRET_KEY is scrubbed from the process
environment with the other startup secrets.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package db
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
"testing"
|
|
|
|
_ "github.com/jackc/pgx/v5/stdlib"
|
|
)
|
|
|
|
// TestMain acquires a PostgreSQL advisory lock (7337741002) for the entire
|
|
// db test suite. Packages agent and server hold the same lock, so parallel
|
|
// `go test ./...` runs serialize across packages on the shared dev DB and
|
|
// avoid cross-package cleanup races (e.g. DELETE FROM assets WHERE id > X
|
|
// from one package deleting assets created by another).
|
|
func TestMain(m *testing.M) {
|
|
// Own database per package (#80): with separate databases, packages stop
|
|
// contending on shared tables and the advisory lock below stops
|
|
// serializing go test ./... across packages.
|
|
SuffixTestDatabase("db")
|
|
box, _ := newSecretBox(testSecretKey)
|
|
activeSecretBox.Store(box)
|
|
dsn, _, err := DSN()
|
|
if err != nil {
|
|
// No DB configured — tests that need PG will skip themselves.
|
|
os.Exit(m.Run())
|
|
}
|
|
conn, err := sql.Open("pgx", dsn)
|
|
if err != nil || conn.Ping() != nil {
|
|
os.Exit(m.Run())
|
|
}
|
|
defer conn.Close()
|
|
if _, err := conn.Exec(`SELECT pg_advisory_lock(7337741002)`); err != nil {
|
|
os.Exit(m.Run())
|
|
}
|
|
defer conn.Exec(`SELECT pg_advisory_unlock(7337741002)`) //nolint:errcheck
|
|
os.Exit(m.Run())
|
|
}
|