Skip to content

Commit

Permalink
Merge pull request #39 from ConductorOne/ggreer/anon-bind
Browse files Browse the repository at this point in the history
Do unauthenticated binding if no password is supplied.
  • Loading branch information
ggreer authored May 23, 2024
2 parents 6d2a511 + 283af35 commit 9e98afa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cmd/baton-ldap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/conductorone/baton-sdk/pkg/cli"
"github.com/go-ldap/ldap/v3"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/spf13/cobra"
)

Expand All @@ -22,6 +23,8 @@ type config struct {

// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
func validateConfig(ctx context.Context, cfg *config) error {
l := ctxzap.Extract(ctx)

if cfg.Domain == "" {
return fmt.Errorf("domain is required")
}
Expand All @@ -37,7 +40,7 @@ func validateConfig(ctx context.Context, cfg *config) error {
}

if cfg.Password == "" {
return fmt.Errorf("password is required")
l.Warn("No password supplied. Will do unauthenticated binding.")
}

return nil
Expand Down
8 changes: 7 additions & 1 deletion pkg/ldap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ func getConnection(ctx context.Context, serverAddr string, password string, user
return nil, err
}

err = conn.Bind(userDN, password)
if password == "" {
l.Debug("Binding to LDAP server unauthenticated")
err = conn.UnauthenticatedBind(userDN)
} else {
l.Debug("Binding to LDAP server authenticated")
err = conn.Bind(userDN, password)
}
if err != nil {
l.Error("Failed to bind to LDAP server", zap.Error(err))
return nil, err
Expand Down

0 comments on commit 9e98afa

Please sign in to comment.