This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 09:57:21 +01:00
1 parent ad0ff60632
commit 6b59434ffa
60 files changed
+7418 -732

No files matched your search

+36 -4
View File
@@ -82,7 +82,11 @@ func run(args []string, stdout, stderr io.Writer) error {
fs.StringVar(&cfg.Listen, "listen", env("RUSTPROXY_DOCKER_AGENT_LISTEN", "127.0.0.1:9876"), "listen address")
// NEVER supply a token as a flag default: `--help` would leak it into output.
tokenOverride := fs.String("token", "", "Bearer token override (prefer the protected environment file)")
fs.StringVar(&cfg.DockerSock, "docker-socket", env("RUSTPROXY_DOCKER_SOCKET", "/var/run/docker.sock"), "Docker Engine unix socket")
fs.StringVar(&cfg.DockerSock, "docker-socket", env("RUSTPROXY_DOCKER_SOCKET", env("RUSTPROXY_CONTAINER_SOCKET", "auto")), "Docker Engine or Podman API unix socket ('auto' detects Docker, then Podman)")
fs.BoolVar(&cfg.DisableSystemInfo, "no-system-info", !envBoolValue(env("RUSTPROXY_DOCKER_SYSTEM_INFO", "true"), true), "do not report host diagnostics (load, memory, network, uptime)")
staticCode := fs.Bool("static", false, "provision-code: print a reusable code with the permanent token instead of a one-time code")
codeTTL := fs.Duration("ttl", 15*time.Minute, "provision-code: lifetime of a one-time code")
endpointOverride := fs.String("endpoint-host", env("RUSTPROXY_DOCKER_ENDPOINT_HOST", ""), "host or IP placed in the provisioning code (default: advertised/route IP)")
fs.StringVar(&cfg.AdvertiseIP, "advertise-ip", env("RUSTPROXY_DOCKER_ADVERTISE_IP", ""), "preferred host IP")
fs.StringVar(&cfg.PublicIPURL, "public-ip-url", env("RUSTPROXY_DOCKER_PUBLIC_IP_URL", "https://api.ipify.org"), "public IP lookup URL")
fs.StringVar(&cfg.Hostname, "hostname", env("RUSTPROXY_DOCKER_HOSTNAME", hostname), "reported host name")
@@ -114,6 +118,7 @@ func run(args []string, stdout, stderr io.Writer) error {
if *printFingerprint {
command = "print-fingerprint"
}
cfg.DockerSock = resolveSocket(cfg.DockerSock)
cfg.Token = env("RUSTPROXY_DOCKER_AGENT_TOKEN", "")
if *tokenOverride != "" {
cfg.Token = *tokenOverride
@@ -146,7 +151,23 @@ func run(args []string, stdout, stderr io.Writer) error {
}
fmt.Fprintf(stdout, "Certificate SHA-256: %s\n", fingerprint)
}
fmt.Fprintf(stdout, "Provisioning complete. Run 'sudo rustproxy-docker-agent info --show-token' to configure RustProxy.\n")
fmt.Fprintf(stdout, "Provisioning complete. Run 'sudo rustproxy-docker-agent provision-code' and paste the code into RustProxy -> Settings -> Docker agents.\n")
return nil
case "provision-code":
if *staticCode {
code, err := provisionCode(cfg, *endpointOverride)
if err != nil {
return err
}
fmt.Fprintln(stdout, code)
return nil
}
code, expires, err := enrollmentCode(cfg, *endpointOverride, *codeTTL, time.Now())
if err != nil {
return err
}
fmt.Fprintln(stdout, code)
fmt.Fprintf(stderr, "One-time code, valid until %s. The agent service must be running to redeem it.\n", expires.Local().Format(time.RFC3339))
return nil
case "rotate-token":
if _, _, err := provisionToken(envFile, true); err != nil {
@@ -161,7 +182,15 @@ func run(args []string, stdout, stderr io.Writer) error {
fmt.Fprintln(stdout, cfg.Token) // Deliberate: an explicit administrative command.
return nil
case "info":
return printAgentInfo(stdout, cfg, envFile, *showToken, *asJSON)
if err := printAgentInfo(stdout, cfg, envFile, *showToken, *asJSON); err != nil {
return err
}
if *showToken && !*asJSON {
if code, err := provisionCode(cfg, *endpointOverride); err == nil {
fmt.Fprintf(stdout, "Provisioning code (sensitive, paste into RustProxy -> Settings -> Docker agents):\n%s\n", code)
}
}
return nil
case "cert-init":
fingerprint, created, err := ensureSelfSignedCertificate(cfg.CertFile, cfg.KeyFile, cfg.Hostname)
if err != nil {
@@ -194,6 +223,8 @@ func printUsage(w io.Writer) {
fmt.Fprintln(w, " init Generate missing token and certificate, preserve existing secrets")
fmt.Fprintln(w, " info [--show-token] Show endpoint, TLS certificate details and token status")
fmt.Fprintln(w, " show-token Print the full Bearer token (sensitive)")
fmt.Fprintln(w, " provision-code Print a one-time code (endpoint, fingerprint, enrollment secret) for the RustProxy panel")
fmt.Fprintln(w, " --ttl 15m sets its lifetime, --static prints a reusable code with the token")
fmt.Fprintln(w, " rotate-token Replace the Bearer token (service restart required)")
fmt.Fprintln(w, " cert-init Create a missing TLS certificate and key")
fmt.Fprintln(w, " print-fingerprint Print current TLS certificate SHA-256 fingerprint")
@@ -207,7 +238,7 @@ func serve(cfg config) error {
return errors.New("RUSTPROXY_DOCKER_AGENT_TOKEN must be a non-placeholder value with at least 24 characters; run 'sudo rustproxy-docker-agent init'")
}
if _, err := os.Stat(cfg.DockerSock); err != nil {
return fmt.Errorf("Docker socket unavailable: %w", err)
return fmt.Errorf("container socket unavailable (Docker or Podman): %w", err)
}
if _, _, err := net.SplitHostPort(cfg.Listen); err != nil {
return fmt.Errorf("invalid listen address: %w", err)
@@ -239,6 +270,7 @@ func serve(cfg config) error {
scheme = "https"
}
log.Printf("RustProxy Docker Agent %s listening on %s://%s; Bearer token configured (%d chars, redacted)", version, scheme, cfg.Listen, len(cfg.Token))
log.Printf("container API socket: %s", cfg.DockerSock)
var err error
if cfg.TLS {
err = server.ListenAndServeTLS(cfg.CertFile, cfg.KeyFile)