Skip to content

feat(auth): add LDAP auth server - #630

Merged
tjovicic merged 3 commits into
mainfrom
feat/ldap-auth-sidecar
Nov 20, 2026
Merged

tjovicic merged 3 commits into
mainfrom
feat/ldap-auth-sidecar

Conversation

@tjovicic

Copy link
Copy Markdown
Contributor

Add auth sidecar server that supports search+bind LDAP operation. Group support, CRD integration will be done in the next PRs.

Add auth sidecar server that supports search+bind LDAP operation.
Group support, CRD integration will be done in the next PRs.
@tjovicic
tjovicic requested review from moredure and a balanced review from Copilot November 19, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Empty credentials or nonexistent usernames can be reported as valid without a successful user bind, creating a critical authentication bypass.

3 open issues
What changed in this PR

Adds a standalone LDAP authentication sidecar for Dragonfly using search-and-bind authentication. Group support and CRD integration remain deferred to later PRs.

Changes:

  • Adds HTTP validation and health endpoints with graceful shutdown.
  • Adds environment-based LDAP configuration, TLS support, and search-and-bind authentication.
  • Moves the operator entry point and tests into cmd/operator, updates build paths, and adds LDAP dependencies.
File Description
Makefile Updates operator build and run paths.
go.sum Adds LDAP dependency checksums.
go.mod Declares LDAP client dependencies.
Dockerfile Builds the relocated operator entry point.
cmd/​operator/​main.go Relocates the operator entry point.
cmd/​operator/​main_test.go Relocates operator tests.
cmd/​auth-sidecar/​search.go Implements LDAP user lookup and credential binding.
cmd/​auth-sidecar/​main.go Adds HTTP endpoints and server lifecycle handling.
cmd/​auth-sidecar/​config.go Loads and validates HTTP and LDAP configuration.
cmd/​auth-sidecar/​auth.go Adds LDAP connections and TLS configuration.

Review effort: Balanced

Comment thread cmd/auth-sidecar/main.go Resolved
Comment thread cmd/auth-sidecar/auth.go Resolved
Comment thread cmd/auth-sidecar/auth.go Resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Tihomir Jovičić <tiho.dev@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The validation handler accepts empty credentials or nonexistent users without a successful user bind, creating a critical authentication bypass.

3 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity LDAP operations can hang indefinitely after connection

cmd/​auth-sidecar/​auth.go:45

The dialer timeout only bounds connection establishment, and the search time limit does not bound client-side LDAP I/O; go-ldap's inspected default branch initializes its request timeout to zero (not the pinned v3.4.15). A directory that accepts TCP but stops replying can therefore retain handlers and connections indefinitely, since the initial context check and HTTP write timeout do not interrupt LDAP operations. Install a client-side LDAP timeout before StartTLS/binding and propagate request cancellation so it closes the connection.

Medium severity Reject incomplete client certificate and key configuration

cmd/​auth-sidecar/​auth.go:65

If only LDAP_TLS_CERT or LDAP_TLS_KEY is configured, this condition silently skips the client certificate, and startup validation still succeeds because it calls this same function. A partially configured mTLS identity therefore produces connections without the intended certificate and fails authentication only at request time. Reject an unmatched certificate/key pair during configuration loading.

1 resolved since last review

Review effort: Balanced

Comment thread cmd/auth-sidecar/main.go Resolved
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

LDAP searches returning zero or multiple users are treated as successful authentication, allowing nonexistent usernames with any nonempty password to bypass authentication.

1 open issue
3 previously missed issues

In code that hasn't changed since last review

High severity Require exactly one LDAP user match before authenticating

cmd/​auth-sidecar/​search.go:58

A zero- or multiple-entry search returns a nil error, which handler treats as successful authentication (main.go:98–99). A nonexistent username with any nonempty password therefore receives {"valid":true} without a user bind. Return an authentication failure when the search does not identify exactly one user, and add regression cases for zero and multiple matches.

Medium severity Apply client-side deadlines and cancellation to LDAP operations

cmd/​auth-sidecar/​auth.go:45

An LDAP peer that stops replying during StartTLS or either bind can leave handlers and connections stuck indefinitely because neither HTTP WriteTimeout nor the search's server-side time limit interrupts that work. No client-side LDAP timeout is configured here; the inspected go-ldap default-branch source initializes it to zero. Apply client-side deadlines covering LDAP operations and the TLS handshake, and thread the request context into connect so cancellation closes the connection.

Medium severity Reject incomplete LDAP client certificate/key configuration

cmd/​auth-sidecar/​auth.go:65

Supplying only LDAP_TLS_CERT or only LDAP_TLS_KEY silently skips loading client credentials. Since cfg.validate() relies on this function, that incomplete configuration passes startup validation, but authentication against a directory requiring mutual TLS then fails on every request. Reject configurations where exactly one half of the certificate/key pair is present instead of silently ignoring it.

2 resolved since last review

Review effort: Balanced

Comment thread cmd/auth-sidecar/auth.go Resolved
Comment thread cmd/auth-sidecar/auth.go
}
if cfg.UseStartTLS && endpoint.Scheme == "ldap" {
if err = connection.StartTLS(tlsConfig); err != nil {
connection.Close()

@moredure moredure Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth packing it with if err != nil inside defer to survive potential panics inside starttls, but I don't feel too strongly about that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have a few connection improvements that i'll handle in the next PR. Will consider this as well

Comment thread cmd/auth-sidecar/main.go Resolved
@tjovicic
tjovicic force-pushed the feat/ldap-auth-sidecar branch from c1c13ce to bc2a222 Compare November 20, 2026 13:44
Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The sidecar cannot build because its config literal uses promoted fields, and malformed StartTLS settings can silently disable encryption and expose LDAP credentials over plaintext.

3 open issues
1 resolved since last review

Review effort: Balanced

SearchScope searchScope
}

func loadConfig() (config, error) {
Comment on lines +87 to +88
cfg := config{
Port: getEnvString("HTTP_PORT", "8080"),
Comment thread cmd/auth-sidecar/auth.go
}
tlsConfig.RootCAs = roots
}
if cert != "" && key != "" {
Add auth sidecar server that supports search+bind LDAP operation.
Group support, CRD integration will be done in the next PRs.
@tjovicic
tjovicic force-pushed the feat/ldap-auth-sidecar branch from bc2a222 to 7a85f66 Compare November 20, 2026 13:54
Copilot AI balanced review requested due to automatic review settings November 20, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The configuration literal fails compilation, and invalid StartTLS settings silently disable encryption, exposing LDAP credentials to plaintext transmission.

4 open issues

Review effort: Balanced

}

func loadConfig() (config, error) {
cfg := config{
@tjovicic
tjovicic merged commit 379c4d9 into main Nov 20, 2026
6 checks passed
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.

3 participants