Skip to content

fix(build): use netgo DNS resolver for release binaries - #4965

Open
dennismdejong wants to merge 1 commit into
dexidp:masterfrom
dennismdejong:fix/distroless-netgo
Open

fix(build): use netgo DNS resolver for release binaries#4965
dennismdejong wants to merge 1 commit into
dexidp:masterfrom
dennismdejong:fix/distroless-netgo

Conversation

@dennismdejong

Copy link
Copy Markdown

Overview

Build the Dex release binaries with the netgo build tag so the pure Go DNS resolver is used instead of libc-based getaddrinfo.

What this PR does / why we need it

Distroless base images do not ship the dynamic libraries required by libc's getaddrinfo (which calls dlopen). When CGO is enabled, the Go standard library uses the CGO resolver for *.local hostnames, so distroless-based Dex builds fail with:

LDAP Result Code 200 "Network Error": dial tcp: lookup ldap.openldap.svc.cluster.local: device or resource busy

Building the release binaries with -tags netgo forces the pure Go DNS resolver, which has no dependency on dynamic libraries and works on distroless images. CGO remains enabled for SQLite storage support.

Closes #2469

Special notes for your reviewer

  • Verified that CGO_ENABLED=1 go build -tags netgo ./... compiles for the main module, examples/ and api/v2.
  • Verified with GODEBUG=netdns=2 that the resulting binary reports it was "compiled without support for the cgo resolver".
  • Verified SQLite/cgo symbols (e.g. sqlite3_open) are still present in the binary.

Distroless base images do not ship the dynamic libraries required by
libc's getaddrinfo (used by the CGO DNS resolver). As a result,
distroless-based Dex builds fail to resolve *.local hostnames, e.g.
LDAP connectors addressing services via .svc.cluster.local.

Build the release binaries with the netgo build tag so that the pure Go
DNS resolver is used instead, which has no such dependency. CGO remains
enabled for SQLite storage support.

Closes dexidp#2469

Signed-off-by: dennismdejong <dennis@caberdo.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distroless container images unable to resolve *.local names

1 participant