This commit is contained in:
Mateusz Gruszczyński committed 2026-10-22 19:20:57 +02:00
1 parent 58c7d63194
commit 5a0a063031
15 files changed
+124 -53

No files matched your search

+2
View File
@@ -104,3 +104,5 @@ The API is `GET /v1/inventory` with `Authorization: Bearer <token>`; `GET /healt
- Cannot reach port `9876`: check `RUSTPROXY_DOCKER_AGENT_LISTEN`, listening socket, firewall, and that HTTPS is used.
`RUSTPROXY_DOCKER_ADVERTISE_IP` adds a preferred host address without suppressing automatic address discovery. `RUSTPROXY_DOCKER_PUBLIC_IP_URL` controls the optional externally observed public IP. The agent's Docker socket access remains privileged; isolate the Docker host and network accordingly.
Default `technical_name` uses the sanitized Docker container name (including Docker Compose container names), not the image or a port suffix. Each published TCP port still has an independent stable service key.
+6 -17
View File
@@ -54,13 +54,9 @@ func dockerContainers(ctx context.Context, sock string) ([]dockerContainer, erro
func cleanName(names []string) string {
if len(names) == 0 {
return "container"
return ""
}
name := strings.TrimPrefix(names[0], "/")
if name == "" {
return "container"
}
return name
return strings.TrimPrefix(names[0], "/")
}
func dnsLabel(value string) string {
@@ -78,9 +74,6 @@ func dnsLabel(value string) string {
}
}
out := strings.Trim(b.String(), "-")
if out == "" {
out = "app"
}
if len(out) > 48 {
out = strings.Trim(out[:48], "-")
}
@@ -92,22 +85,15 @@ func serviceIdentity(c dockerContainer, p dockerPort) (key, technical string) {
project := c.Labels["com.docker.compose.project"]
composeService := c.Labels["com.docker.compose.service"]
replica := c.Labels["com.docker.compose.container-number"]
suffix := strconv.Itoa(int(p.PrivatePort))
if project != "" && composeService != "" {
if replica == "" {
replica = name
}
key = fmt.Sprintf("compose:%s/%s/%s:%d/%s", project, composeService, replica, p.PrivatePort, p.Type)
technicalBase := project + "-" + composeService
if replica != "1" {
technicalBase += "-" + replica
}
technical = dnsLabel(technicalBase + "-" + suffix)
} else {
key = fmt.Sprintf("container:%s:%d/%s", name, p.PrivatePort, p.Type)
technical = dnsLabel(name + "-" + suffix)
}
return key, technical
return key, dnsLabel(name)
}
func servicesFrom(containers []dockerContainer) []service {
@@ -115,6 +101,9 @@ func servicesFrom(containers []dockerContainer) []service {
bindingSeen := make(map[string]map[string]struct{})
for _, c := range containers {
name := cleanName(c.Names)
if dnsLabel(name) == "" {
continue
}
for _, p := range c.Ports {
if p.PublicPort == 0 || p.Type != "tcp" {
continue
+13 -1
View File
@@ -41,7 +41,7 @@ func TestServicesFromUsesStableComposeIdentity(t *testing.T) {
if len(got) != 1 {
t.Fatalf("got %d services", len(got))
}
if got[0].Key != "compose:lab/web/1:8080/tcp" || got[0].TechnicalName != "lab-web-8080" {
if got[0].Key != "compose:lab/web/1:8080/tcp" || got[0].TechnicalName != "web-1" {
t.Fatalf("unexpected service %#v", got[0])
}
if len(got[0].Bindings) != 1 || got[0].Bindings[0].PublicPort != 18080 {
@@ -64,6 +64,9 @@ func TestServicesFromKeepsComposeReplicasAndAllBindings(t *testing.T) {
if got[0].Key != "compose:lab/web/1:8080/tcp" || got[1].Key != "compose:lab/web/2:8080/tcp" {
t.Fatalf("unexpected replica keys %#v", got)
}
if got[0].TechnicalName != "lab-web-1" || got[1].TechnicalName != "lab-web-2" {
t.Fatalf("expected container-based hostnames, got %#v", got)
}
if len(got[0].Bindings) != 3 {
t.Fatalf("expected all published bindings, got %#v", got[0].Bindings)
}
@@ -243,3 +246,12 @@ func TestTLSInventoryReportsServingCertificateFingerprint(t *testing.T) {
t.Fatalf("inventory fingerprint = %q, want %q", got.CertificateSHA256, fingerprint)
}
}
func TestTechnicalNameIgnoresImageAndPort(t *testing.T) {
c := dockerContainer{Names: []string{"/My_App"}, Image: "registry.example.com/image:latest"}
one := servicesFrom([]dockerContainer{{Names: c.Names, Image: c.Image, Ports: []dockerPort{{PrivatePort: 80, PublicPort: 8080, Type: "tcp"}}}})
two := servicesFrom([]dockerContainer{{Names: c.Names, Image: "changed", Ports: []dockerPort{{PrivatePort: 8080, PublicPort: 9000, Type: "tcp"}}}})
if len(one) != 1 || len(two) != 1 || one[0].TechnicalName != "my-app" || two[0].TechnicalName != "my-app" {
t.Fatalf("technical names must use the container name: %#v %#v", one, two)
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
package main
var version = "1.0.0" // overridden by the package builder using -ldflags -X main.version
var version = "1.0.1" // overridden by the package builder using -ldflags -X main.version
type config struct {
Listen string