ldapsrv

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseDN is used when the internal directory is enabled and no
	// base DN has been set.
	DefaultBaseDN = "dc=factum,dc=local"
	// DefaultListen is the plain LDAP listen address.
	DefaultListen = ":389"
	// ServiceCN is the RDN of the search bind account. It is not a person.
	ServiceCN = "svc-factum"
	// MatchingRuleInChain is Active Directory's LDAP_MATCHING_RULE_IN_CHAIN.
	// A filter (member:1.2.840.113556.1.4.1941:=dn) matches a group when dn
	// is a direct or nested member. memberOf walks the other way.
	MatchingRuleInChain = "1.2.840.113556.1.4.1941"
)
View Source
const Command = "ldap"

Command is the worker.commands name that starts the LDAP listener.

Variables

This section is empty.

Functions

func LegoCertStem

func LegoCertStem(domain string) (string, error)

LegoCertStem is the file name lego uses for a certificate domain, without an extension. It matches lego's sanitizedDomain: ":" becomes "-", "*" becomes "_", then the name is converted to ASCII. The result is one path segment.

func Port

func Port(listen string) uint16

Port returns the TCP port of a listen address. 0 if it cannot be read.

func Run

func Run(ctx context.Context, opt Options) error

Run refreshes the snapshot and serves LDAP until ctx ends.

func ServiceBindDN

func ServiceBindDN(base string) string

ServiceBindDN is the search account for BaseDN.

func StatePath

func StatePath(override string) string

StatePath is the on-disk directory snapshot. Empty uses the default. The file holds password hashes and the search-account password.

func ValidBaseDN

func ValidBaseDN(dn string) bool

ValidBaseDN reports whether dn is a usable base DN.

func ValidOUName

func ValidOUName(name string) bool

ValidOUName is a folder name that can be an RDN.

func ValidateListen

func ValidateListen(s string) error

ValidateListen accepts an empty address or host:port.

Types

type Config

type Config struct {
	Enabled   bool   `json:"enabled"`
	Listen    string `json:"listen"`
	TLSListen string `json:"tls_listen,omitempty"`
	// TLSCertificate is the certificate-store name. TLSDomain is its
	// first domain, which is the lego file stem before sanitizing.
	// Both empty means LDAPS uses the worker hub certificate.
	TLSCertificate string      `json:"tls_certificate,omitempty"`
	TLSDomain      string      `json:"tls_domain,omitempty"`
	BaseDN         string      `json:"base_dn"`
	BindDN         string      `json:"bind_dn"`
	BindPassword   string      `json:"bind_password,omitempty"`
	Entries        []WireEntry `json:"entries"`
}

Config is the snapshot a worker persists and serves.

func (Config) Directory

func (c Config) Directory() *Directory

Directory rebuilds a snapshot into a searchable directory.

type Directory

type Directory struct {
	BaseDN       string
	BindDN       string
	BindPassword string
	// RoleDN maps a role id to the DN it was published at. OUDN does the
	// same for folders. Both are empty for a snapshot loaded from disk.
	RoleDN map[uint]string
	OUDN   map[uint]string
	// contains filtered or unexported fields
}

Directory is an immutable snapshot.

func Build

func Build(in Input) *Directory

Build turns people, roles, and folders into LDAP entries.

func (*Directory) Snapshot

func (d *Directory) Snapshot(enabled bool, listen, tlsListen, bindPassword string) Config

Snapshot copies the directory into a config the worker can store.

type Entry

type Entry struct {
	DN             string
	Attrs          map[string][]string
	Password       string
	DirectMembers  []string
	DirectMemberOf []string
	// contains filtered or unexported fields
}

Entry is one object served over LDAP. Password is checked on bind and is never returned as an attribute. DirectMembers and DirectMemberOf are the unexpanded edges used by the Active Directory in-chain rule. memberOf in Attrs is already expanded, so a plain equality filter sees nested groups.

type Input

type Input struct {
	BaseDN string
	OUs    []OU
	Users  []User
	Roles  []Role
}

Input is the directory the hub snapshot is built from.

type OU

type OU struct {
	ID       uint
	ParentID *uint
	Name     string
}

OU is one folder. ID 0 is not used. ParentID nil is the base DN.

type Options

type Options struct {
	StatePath string
	// TLSCert and TLSKey are the worker hub certificate. LDAPS uses them
	// when the snapshot does not name a certificate from the store.
	TLSCert string
	TLSKey  string
	// LegoStorage is this worker's lego data directory (worker.paths
	// lego_storage). A chosen certificate is read from certificates/
	// under that directory.
	LegoStorage string
	Fetch       func(ctx context.Context) ([]byte, error)
}

Options wires the listener to the hub. Fetch may fail while factum2 is down; the last snapshot on disk keeps answering.

type Role

type Role struct {
	ID          uint
	Name        string
	Description string
	OUID        *uint
	MemberIDs   []uint
}

Role is a group. MemberIDs are roles that are direct members of this role.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server answers LDAP. The snapshot is swapped as a whole.

type User

type User struct {
	ID       uint
	Username string
	Name     string
	Email    string
	Mobile   string
	Password string
	OUID     *uint
	RoleIDs  []uint
}

User is a person published in the directory. Password is a bcrypt hash. Accounts without a bcrypt hash are left out. ID is the factum user id and is not part of the DN.

type WireEntry

type WireEntry struct {
	DN         string              `json:"dn"`
	Attributes map[string][]string `json:"attributes"`
	Password   string              `json:"password,omitempty"`
	Members    []string            `json:"members,omitempty"`
	MemberOf   []string            `json:"member_of,omitempty"`
}

WireEntry is one object in the snapshot. Password is a bcrypt hash. Members and MemberOf are the direct edges. The memberof attribute is the expanded list.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL