10 changed files with 106 additions and 11 deletions
+1 -1
View File
@@ -157,7 +157,7 @@ export async function publishInstallation(options) {
chmodSync(join(bundle, 'bin', executable), 0o755); chmodSync(join(bundle, 'bin', executable), 0o755);
} }
// Resolve source-independent resource/config shape without any operator credentials. // Resolve source-independent resource/config shape without any operator credentials.
await run('docker', ['compose', '-f', join(bundle, 'compose.yaml'), '-f', join(bundle, 'deploy/compose.local.yaml'), 'config', '--no-interpolate', '--no-env-resolution', '--format', 'json']); await run('docker', ['compose', '-f', join(bundle, 'compose.yaml'), '-f', join(bundle, 'deploy/compose.local.yaml'), '--profile', 'catalog-maintenance', '--profile', 'workspace-maintenance', 'config', '--no-interpolate', '--no-env-resolution', '--format', 'json']);
const archive = join(options.output, name + '.tar.gz'); const archive = join(options.output, name + '.tar.gz');
await run('tar', ['-czf', archive, '-C', options.output, name]); await run('tar', ['-czf', archive, '-C', options.output, name]);
assets.push({ name: basename(archive), path: archive, bytes: statSync(archive).size, sha256: sha256(readFileSync(archive)) }); assets.push({ name: basename(archive), path: archive, bytes: statSync(archive).size, sha256: sha256(readFileSync(archive)) });
+6 -1
View File
@@ -128,7 +128,7 @@ must exist. It starts no services and does not implicitly generate passwords.
`secrets/pi-auth.json`. Existing files are retained; invalid ones stop the command. `secrets/pi-auth.json`. Existing files are retained; invalid ones stop the command.
The initial administrator is `admin`; its password stays in private The initial administrator is `admin`; its password stays in private
`secrets/admin-password` and is never printed. The default is local authentication `secrets/admin-password` and is never printed. The default is local authentication
at `http://localhost:8080`: review and edit `auth/auth.yaml` before validation. at `http://127.0.0.1:8080`: review and edit `auth/auth.yaml` before validation.
This increment does not validate offline OIDC bootstrap for the existing path. This increment does not validate offline OIDC bootstrap for the existing path.
5. Fill the provider key in `secrets/secrets.env` and create the DWH password file. 5. Fill the provider key in `secrets/secrets.env` and create the DWH password file.
For Git HTTPS supply the referenced credentials and CA files; empty credentials For Git HTTPS supply the referenced credentials and CA files; empty credentials
@@ -215,6 +215,11 @@ existing stack with incompatible volume ownership.
endpoints, **not** readiness to query a database. Binding import, workspace activation endpoints, **not** readiness to query a database. Binding import, workspace activation
and preprocessing, and a model smoke test are subsequent steps. The three curated and preprocessing, and a model smoke test are subsequent steps. The three curated
example databases remain deferred. example databases remain deferred.
With the default configuration, open `http://127.0.0.1:8080` to sign in. The browser
origin must match `publicUrl`; do not substitute `localhost` for `127.0.0.1`.
For HTTPS Git, supply the server's specific CA in PEM format, within the 64 KiB
protected-file limit. A complete operating-system CA bundle may exceed that limit.
After a failure, correct the cause and repeat `apply`. The private journal under After a failure, correct the cause and repeat `apply`. The private journal under
`.tht/<installation>/installation-apply.json` records stages; actual service state is `.tht/<installation>/installation-apply.json` records stages; actual service state is
+6 -1
View File
@@ -130,12 +130,14 @@ deve esistere. Non avvia servizi e non genera implicitamente password.
e `secrets/pi-auth.json`. I file esistenti vengono conservati; se non validi, il e `secrets/pi-auth.json`. I file esistenti vengono conservati; se non validi, il
comando si ferma. L'amministratore iniziale è `admin`, la password è nel file comando si ferma. L'amministratore iniziale è `admin`, la password è nel file
privato `secrets/admin-password` e non viene stampata. Il default è autenticazione privato `secrets/admin-password` e non viene stampata. Il default è autenticazione
locale con URL pubblico `http://localhost:8080`: verificare e, se necessario, locale con URL pubblico `http://127.0.0.1:8080`: verificare e, se necessario,
modificare `auth/auth.yaml` prima del controllo. Questo incremento non valida il modificare `auth/auth.yaml` prima del controllo. Questo incremento non valida il
bootstrap OIDC del percorso esistente. bootstrap OIDC del percorso esistente.
5. Inserire la chiave del provider in `secrets/secrets.env` e creare il file della 5. Inserire la chiave del provider in `secrets/secrets.env` e creare il file della
password DWH. Per HTTPS Git fornire i file referenziati per credenziali e CA: password DWH. Per HTTPS Git fornire i file referenziati per credenziali e CA:
credenziali vuote sono ammesse per un remoto pubblico, la CA deve essere disponibile. credenziali vuote sono ammesse per un remoto pubblico, la CA deve essere disponibile.
Fornire la CA specifica del server in PEM, entro 64 KiB; l'intero bundle CA del
sistema può superare il limite dei file protetti.
Per SSH fornire chiave e known_hosts, scegliendo il relativo override nel descrittore. Per SSH fornire chiave e known_hosts, scegliendo il relativo override nel descrittore.
I provider `pi_auth` richiedono credenziali Pi già preparate. Conservare tutti I provider `pi_auth` richiedono credenziali Pi già preparate. Conservare tutti
questi file fuori dal repository workspace e proteggere l'accesso al solo utente questi file fuori dal repository workspace e proteggere l'accesso al solo utente
@@ -221,6 +223,9 @@ Il risultato `platform_ready: true, workspace_ready: false` certifica l'avvio de
piattaforma e la protezione degli endpoint, **non** la possibilità di interrogare piattaforma e la protezione degli endpoint, **non** la possibilità di interrogare
già il database. Import dei binding, attivazione/preprocessing dei workspace e già il database. Import dei binding, attivazione/preprocessing dei workspace e
prova modello sono i passi successivi. I tre database di esempio restano differiti. prova modello sono i passi successivi. I tre database di esempio restano differiti.
Con il valore predefinito, aprire `http://127.0.0.1:8080` per l'accesso: l'origine
del browser deve coincidere con `publicUrl`, quindi non sostituire `127.0.0.1` con
`localhost`.
In caso di errore, correggere la causa e ripetere `apply`: il journal privato in In caso di errore, correggere la causa e ripetere `apply`: il journal privato in
`.tht/<installazione>/installation-apply.json` registra gli stadi, mentre lo stato `.tht/<installazione>/installation-apply.json` registra gli stadi, mentre lo stato
+33 -4
View File
@@ -15,6 +15,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -713,7 +714,7 @@ func parseConfigure(args []string) (configureRequest, error) {
*target, args = args[0], args[1:] *target, args = args[0], args[1:]
seen[option] = true seen[option] = true
} }
if request.mode != "local" && request.mode != "oidc" || !validPublicURL(request.publicURL) { if request.mode != "local" && request.mode != "oidc" || !ValidPublicURL(request.publicURL) {
return configureRequest{}, errCommandRefused return configureRequest{}, errCommandRefused
} }
if request.mode == "local" { if request.mode == "local" {
@@ -1173,9 +1174,19 @@ func rolesToStrings(roles []Role) []string {
return values return values
} }
func validPublicURL(value string) bool { // ValidPublicURL follows the backend policy: HTTP requires canonical literal loopback.
func ValidPublicURL(value string) bool {
parsed, err := url.Parse(value) parsed, err := url.Parse(value)
return err == nil && (parsed.Scheme == "http" || parsed.Scheme == "https") && parsed.Host != "" && parsed.User == nil && parsed.Path == "" && parsed.RawQuery == "" && parsed.Fragment == "" if err != nil || parsed.Hostname() == "" || strings.Contains(parsed.Hostname(), "%") || parsed.User != nil || (parsed.Path != "" && parsed.Path != "/") || parsed.RawQuery != "" || parsed.Fragment != "" {
return false
}
if port := parsed.Port(); port != "" {
n, err := strconv.Atoi(port)
if err != nil || n < 0 || n > 65535 {
return false
}
}
return parsed.Scheme == "https" || parsed.Scheme == "http" && isLoopbackURL(value)
} }
func validOIDCURL(value string) bool { func validOIDCURL(value string) bool {
@@ -1191,10 +1202,28 @@ func isHTTPS(value string) bool {
return err == nil && parsed.Scheme == "https" return err == nil && parsed.Scheme == "https"
} }
func isLoopbackURL(value string) bool { func isLoopbackURL(value string) bool {
if !strings.HasPrefix(value, "http://") {
return false
}
parsed, err := url.Parse(value) parsed, err := url.Parse(value)
if err != nil { if err != nil {
return false return false
} }
host := parsed.Hostname() host := parsed.Hostname()
return host == "localhost" || net.ParseIP(host) != nil && net.ParseIP(host).IsLoopback() ip := net.ParseIP(host)
if ip == nil || !ip.IsLoopback() || ip.String() != host {
return false
}
authority := host
if strings.Contains(host, ":") {
authority = "[" + host + "]"
}
if port := parsed.Port(); port != "" {
n, err := strconv.Atoi(port)
if err != nil || n < 0 || n > 65535 || strconv.Itoa(n) != port {
return false
}
authority += ":" + port
}
return parsed.Host == authority
} }
@@ -0,0 +1,29 @@
package authconfig
import "testing"
func TestLocalHTTPOriginMatchesBackendLiteralLoopbackPolicy(t *testing.T) {
for _, origin := range []string{"http://127.0.0.1:8080", "http://127.0.0.2", "http://[::1]:8080"} {
if !isLoopbackURL(origin) {
t.Errorf("canonical origin refused: %s", origin)
}
}
for _, origin := range []string{"http://localhost:8080", "http://127.1:8080", "http://[::ffff:127.0.0.1]:8080", "http://127.0.0.1:08080", "http://127.0.0.1:", "http://127.0.0.1:99999"} {
if isLoopbackURL(origin) {
t.Errorf("backend-incompatible origin accepted: %s", origin)
}
}
}
func TestPublicOriginMatchesBackendURLContract(t *testing.T) {
for _, origin := range []string{"http://127.0.0.1:8080/", "https://example.com/", "https://example.com:443", "http://[::1]:8080/"} {
if !ValidPublicURL(origin) {
t.Errorf("runtime-valid origin refused: %s", origin)
}
}
for _, origin := range []string{"https://:443", "https://[fe80::1%25eth0]", "https://example.com:99999", "http://localhost:8080", "HTTP://127.0.0.1:8080", "https://example.com/path", "http://example.com", "https://user:password@example.com"} {
if ValidPublicURL(origin) {
t.Errorf("runtime-invalid origin accepted: %s", origin)
}
}
}
@@ -104,6 +104,9 @@ func (r *dockerFixture) Run(_ context.Context, args []string, input io.Reader) (
if strings.Contains(line, " config ") { if strings.Contains(line, " config ") {
services := map[string]any{} services := map[string]any{}
for service, role := range map[string]string{"core": "core", "frontend": "frontend", "catalog-db": "catalog", "catalog-migrate": "core", "workspace-maintenance": "core", "qdrant": "qdrant", "embedding": "embedding", "embedding-model-init": "embedding"} { for service, role := range map[string]string{"core": "core", "frontend": "frontend", "catalog-db": "catalog", "catalog-migrate": "core", "workspace-maintenance": "core", "qdrant": "qdrant", "embedding": "embedding", "embedding-model-init": "embedding"} {
if (service == "catalog-migrate" && !strings.Contains(line, "--profile catalog-maintenance")) || (service == "workspace-maintenance" && !strings.Contains(line, "--profile workspace-maintenance")) {
continue
}
services[service] = map[string]string{"image": "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)} services[service] = map[string]string{"image": "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)}
} }
if r.wrongImage { if r.wrongImage {
+2 -2
View File
@@ -28,13 +28,13 @@ func CheckCompose(ctx context.Context, runner Runner, installation config.Instal
} }
args = append(args, "-f", path) args = append(args, "-f", path)
} }
args = append(args, "config", "--format", "json") args = append(args, "--profile", "catalog-maintenance", "--profile", "workspace-maintenance", "config", "--format", "json")
return checkResolvedCompose(ctx, runner, args, m, platform) return checkResolvedCompose(ctx, runner, args, m, platform)
} }
// CheckInstalledCompose includes generated projections and any durable image override. // CheckInstalledCompose includes generated projections and any durable image override.
func CheckInstalledCompose(ctx context.Context, runner Runner, installation config.Installation, m Manifest, platform string) Report { func CheckInstalledCompose(ctx context.Context, runner Runner, installation config.Installation, m Manifest, platform string) Report {
return checkResolvedCompose(ctx, runner, installation.ComposeArgs("config", "--format", "json"), m, platform) return checkResolvedCompose(ctx, runner, installation.ComposeArgs("--profile", "catalog-maintenance", "--profile", "workspace-maintenance", "config", "--format", "json"), m, platform)
} }
func checkResolvedCompose(ctx context.Context, runner Runner, args []string, m Manifest, platform string) Report { func checkResolvedCompose(ctx context.Context, runner Runner, args []string, m Manifest, platform string) Report {
+23 -1
View File
@@ -29,7 +29,16 @@ func (f *fakeDocker) Run(_ context.Context, args []string, _ io.Reader) (compose
case "compose": case "compose":
if args[len(args)-1] == "json" { if args[len(args)-1] == "json" {
if f.effective != "" { if f.effective != "" {
return compose.Result{Stdout: f.effective}, nil var resolved map[string]map[string]any
_ = json.Unmarshal([]byte(f.effective), &resolved)
line := strings.Join(args, " ")
for service, profile := range map[string]string{"catalog-migrate": "catalog-maintenance", "workspace-maintenance": "workspace-maintenance"} {
if !strings.Contains(line, "--profile "+profile) {
delete(resolved["services"], service)
}
}
data, _ := json.Marshal(resolved)
return compose.Result{Stdout: string(data)}, nil
} }
return compose.Result{Stdout: `{"services":{"core":{"image":"example/core:latest"}}}`}, nil return compose.Result{Stdout: `{"services":{"core":{"image":"example/core:latest"}}}`}, nil
} }
@@ -40,6 +49,19 @@ func (f *fakeDocker) Run(_ context.Context, args []string, _ io.Reader) (compose
return compose.Result{}, errors.New("unexpected command") return compose.Result{}, errors.New("unexpected command")
} }
func TestComposeIncludesInactiveMaintenanceProfilesBeforeInstallation(t *testing.T) {
m := Manifest{Images: map[string]map[string]string{}, Compose: []string{"compose.yaml"}}
services := map[string]map[string]string{}
for service, role := range map[string]string{"core": "core", "frontend": "frontend", "catalog-db": "catalog", "catalog-migrate": "core", "workspace-maintenance": "core", "qdrant": "qdrant", "embedding": "embedding", "embedding-model-init": "embedding"} {
m.Images[role] = map[string]string{"linux/amd64": "docker.io/example/" + role + "@sha256:" + strings.Repeat("a", 64)}
services[service] = map[string]string{"image": m.Images[role]["linux/amd64"]}
}
data, _ := json.Marshal(map[string]any{"services": services})
if r := CheckCompose(context.Background(), &fakeDocker{effective: string(data)}, config.Installation{}, m, "/release/manifest.json", "linux/amd64"); !r.OK {
t.Fatalf("maintenance profiles missing: %+v", r)
}
}
func TestComposeRejectsIncompleteMutableServiceSet(t *testing.T) { func TestComposeRejectsIncompleteMutableServiceSet(t *testing.T) {
r := CheckCompose(context.Background(), &fakeDocker{}, config.Installation{ProjectDirectory: "/private", EnvFile: "/private/operator.env"}, Manifest{Compose: []string{"compose.yaml"}}, "/release/manifest.json", "linux/amd64") r := CheckCompose(context.Background(), &fakeDocker{}, config.Installation{ProjectDirectory: "/private", EnvFile: "/private/operator.env"}, Manifest{Compose: []string{"compose.yaml"}}, "/release/manifest.json", "linux/amd64")
if r.OK { if r.OK {
@@ -66,7 +66,7 @@ func Credentials(ctx context.Context, directory string) error {
return nil return nil
} }
installation := config.Installation{Authentication: config.Authentication{ConfigDirectory: authDirectory}} installation := config.Installation{Authentication: config.Authentication{ConfigDirectory: authDirectory}}
if authconfig.Run(ctx, installation, []string{"configure", "--mode", "local", "--public-url", "http://localhost:8080", "--admin-user", "admin", "--password-file", filepath.Join(secrets, "admin-password")}, strings.NewReader(""), io.Discard, io.Discard) != 0 { if authconfig.Run(ctx, installation, []string{"configure", "--mode", "local", "--public-url", "http://127.0.0.1:8080", "--admin-user", "admin", "--password-file", filepath.Join(secrets, "admin-password")}, strings.NewReader(""), io.Discard, io.Discard) != 0 {
return fmt.Errorf("cannot prepare local administrator; inspect protected auth files and retry without replacing existing credentials") return fmt.Errorf("cannot prepare local administrator; inspect protected auth files and retry without replacing existing credentials")
} }
return nil return nil
@@ -186,6 +186,8 @@ func Validate(path string) (config.Installation, Report) {
auth, users, err := authconfig.Load(installation.AuthenticationDirectory()) auth, users, err := authconfig.Load(installation.AuthenticationDirectory())
if err != nil { if err != nil {
report.Add("auth/auth.yaml", "$", "authentication_invalid", "Prepare and validate local authentication documents before setup, including the initial administrator.") report.Add("auth/auth.yaml", "$", "authentication_invalid", "Prepare and validate local authentication documents before setup, including the initial administrator.")
} else if !authconfig.ValidPublicURL(auth.PublicURL) {
report.Add("auth/auth.yaml", "publicUrl", "authentication_origin_invalid", "Use HTTPS or a canonical literal loopback HTTP origin, for example http://127.0.0.1:8080; localhost names are not accepted by the runtime.")
} else if auth.Mode == "local" { } else if auth.Mode == "local" {
admin := false admin := false
for _, user := range users.Users { for _, user := range users.Users {