ldap

package
v1.52.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Overview

Copyright 2025 SGNL.ai, Inc.

Copyright 2025 SGNL.ai, Inc.

Index

Constants

View Source
const (
	ErrorMsgAttributeTypeDoesNotMatchFmt = "Attribute '%s' was returned from the " +
		"configured datasource as type %s; wanted type %s"
)

Variables

This section is empty.

Functions

func BytesToOctetString

func BytesToOctetString(data []byte) *string

func DefaultEntityConfig

func DefaultEntityConfig() map[string]*EntityConfig

defaultEntityConfig: if entityConfig is nil, defaulting to values that pull data from ActiveDirectory.

func EntryToObject

func EntryToObject(e *ldap_v3.Entry, attrConfig map[string]*framework.AttributeConfig) (
	map[string]interface{}, *framework.Error)

func GetTLSConfig added in v1.39.0

func GetTLSConfig(request *Request) (*tls.Config, *framework.Error)

GetTLSConfig creates a TLS config using certchain from the request.

func NewAdapter

func NewAdapter(client grpc_proxy_v1.ProxyServiceClient, ttl, cleanupInterval time.Duration) framework.Adapter[Config]

NewAdapter instantiates a new Adapter. It is used to connect to a LDAP server and execute search queries. The client is not proxied by default. If you want to use a proxied client, you need to provide a grpc_proxy_v1.ProxyServiceClient instance. The adapter also manages a session pool to reuse LDAP connections.

func OctetStringToBytes

func OctetStringToBytes(octalString string) ([]byte, error)

func ProcessLDAPSearchResult added in v1.39.0

func ProcessLDAPSearchResult(result *ldap_v3.SearchResult, response *Response, request *Request) *framework.Error

func SetFilters

func SetFilters(request *Request) (string, *framework.Error)

SetFilters configures the LDAP search filters based on the inputs received in entityConfig.

func StringAttrValuesToRequestedType

func StringAttrValuesToRequestedType(
	attr *ldap_v3.EntryAttribute,
	isList bool,
	attrType framework.AttributeType,
) (any, *framework.Error)

Types

type Adapter

type Adapter struct {
	ADClient Client
}

Adapter implements the framework.Adapter interface to query pages of objects from datasources.

func (*Adapter) GetPage

func (a *Adapter) GetPage(ctx context.Context, request *framework.Request[Config]) framework.Response

GetPage is called by SGNL's ingestion service to query a page of objects from a datasource.

func (*Adapter) RequestPageFromDatasource

func (a *Adapter) RequestPageFromDatasource(
	ctx context.Context, request *framework.Request[Config],
) framework.Response

RequestPageFromDatasource requests a page of objects from a datasource.

func (*Adapter) ValidateGetPageRequest

func (a *Adapter) ValidateGetPageRequest(ctx context.Context, request *framework.Request[Config]) *framework.Error

ValidateGetPageRequest validates the fields of the GetPage Request.

type Client

type Client interface {
	GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)
}

Client is a client that allows querying the datasource which contains JSON objects.

func NewClient

func NewClient(proxy grpc_proxy_v1.ProxyServiceClient, pool *SessionPool) Client

NewClient returns a Client to query the datasource.

type Config

type Config struct {
	// Common configuration
	*config.CommonConfig

	BaseDN string `json:"baseDN"`

	// CertificateChain is a base64 encoded Certificates
	CertificateChain string `json:"certificateChain,omitempty"`

	// EntityConfigMap is an map containing the config required for each entity associated with this
	// datasource. The key is the entity's external_name and value is EntityConfig.
	EntityConfigMap map[string]*EntityConfig `json:"entityConfig"`
}

func (*Config) Validate

func (c *Config) Validate(_ context.Context) error

ValidateConfig validates that a Config received in a GetPage call is valid.

type ConnectionParams

type ConnectionParams struct {
	// Host is the Hostname of the datasource to query.
	Host string `json:"host"`

	// BaseDN is the Base DN of the datasource to query.
	BaseDN string `json:"baseDN"`

	// BindDN is the Bind DN of the datasource to query.
	BindDN string `json:"bindDN"`

	// BindPassword is the password of the datasource to query.
	BindPassword string `json:"bindPassword"`

	// IsLDAPS flag to check if connection is secured
	IsLDAPS bool `json:"isLDAPS"`

	// CertificateChain contains certificate chain to use for ldaps connection
	CertificateChain string `json:"certificateChain,omitempty"`
}

type Datasource

type Datasource struct {
	Client Dispatcher
}

Datasource directly implements a Client interface to allow querying an external datasource.

func (*Datasource) GetPage

func (d *Datasource) GetPage(ctx context.Context, request *Request) (*Response, *framework.Error)

type Dispatcher added in v1.39.0

type Dispatcher interface {
	IsProxied() bool
	Proxy
	Requester
}

Dispatcher is an interface that combines Proxy and Requester. It is used to determine if the LDAP request should be proxied or sent directly to the LDAP server. The IsProxied method checks if the LDAP request is proxied.

type EntityConfig

type EntityConfig struct {
	Query                     string  `json:"query"`
	CollectionAttribute       *string `json:"collectionAttribute"`
	MemberUniqueIDAttribute   *string `json:"memberUniqueIdAttribute,omitempty"`
	MemberOfUniqueIDAttribute *string `json:"memberOfUniqueIdAttribute,omitempty"`
	MemberOf                  *string `json:"memberOf,omitempty"`
}

EntityConfig holds attributes which are used to create LDAP search filter.

type PageInfo

type PageInfo struct {
	// Collection is a map of the attributes of the collection entity.
	Collection map[string]any `json:"collection"`

	// NextPageCursor is the cursor to the next page of results.
	NextPageCursor *string `json:"nextPageCursor"`
}

func DecodePageInfo

func DecodePageInfo(cursor *string) (*PageInfo, *framework.Error)

func ParseResponse

func ParseResponse(searchResult *ldap_v3.SearchResult, attributes map[string]*framework.AttributeConfig) (
	objects []map[string]any, pageInfo *PageInfo, err *framework.Error)

type Proxy added in v1.41.0

type Proxy interface {
	ProxyRequest(ctx context.Context, ci *connector.ConnectorInfo, request *Request) (*Response, *framework.Error)
}

Proxy is an interface for LDAP proxy requests. It is used to send LDAP requests to a remote connector via the SGNL connector proxy.

type Request

type Request struct {
	// ConnectionParams contains LDAP specific params
	ConnectionParams `json:"connectionParams"`

	// BaseURL is the Base URL of the datasource to query.
	BaseURL string `json:"baseURL"`

	// PageSize is the maximum number of objects to return from the entity.
	PageSize int64 `json:"pageSize"`

	// EntityExternalID is the external ID of the entity.
	// The external ID should match the API's resource name.
	EntityExternalID string `json:"entityExternalID"`

	// Cursor identifies the first object of the page to return, as returned by
	// the last request for the entity.
	// nil in the request for the first page.
	Cursor *pagination.CompositeCursor[string] `json:"cursor,omitempty"`

	// UniqueIDAttribute is a attribute which can be used to uniquely identify the Entity.
	// This is specific to ldap server implementation
	UniqueIDAttribute string `json:"uniqueIDAttribute"`

	// EntityConfigMap is an map containing the config required for each entity associated with this
	// datasource. The key is the entity's external_name and value is EntityConfig.
	EntityConfigMap map[string]*EntityConfig `json:"entityConfigMap,omitempty"`

	// Attributes contains the list of attributes to request along with the current request.
	Attributes []*framework.AttributeConfig `json:"attributes,omitempty"`

	// RequestTimeoutSeconds is the timeout duration for requests made to datasources.
	// This should be set to the number of seconds to wait before timing out.
	RequestTimeoutSeconds int `json:"requestTimeoutSeconds"`
}

Request is a request to the datasource.

type Requester added in v1.41.0

type Requester interface {
	Request(ctx context.Context, request *Request) (*Response, *framework.Error)
}

Requester is an interface for LDAP requests. It is used to send LDAP requests directly to a publicly accessible LDAP server.

func NewLDAPRequester added in v1.41.0

func NewLDAPRequester(ttl time.Duration, cleanupInterval time.Duration) Requester

NewLDAPRequester creates a new LDAP Requester instance. It is used to create a new LDAP client for making LDAP search requests. It also manages a session pool to reuse LDAP connections.

type Response

type Response struct {
	// TODO: Update the comment once we support LDAP status with adapter-framework
	// StatusCode is an HTTP status code.
	StatusCode int `json:"statusCode"`

	// RetryAfterHeader is the Retry-After response HTTP header, if set.
	RetryAfterHeader string `json:"retryAfterHeader"`

	// Objects is the list of
	// May be empty.
	Objects []map[string]any `json:"objects,omitempty"`

	// NextCursor is the cursor that identifies the first object of the next page.
	// nil if this is the last page in this full sync.
	NextCursor *pagination.CompositeCursor[string] `json:"nextCursor"`
}

Response is a response returned by the datasource.

type Session added in v1.43.0

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

func (*Session) GetOrCreateConn added in v1.43.0

func (s *Session) GetOrCreateConn(
	address string,
	tlsConfig *tls.Config,
	bindDN, bindPassword string,
) (*ldap_v3.Conn, error)

type SessionPool added in v1.43.0

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

func NewSessionPool added in v1.43.0

func NewSessionPool(ttl, cleanupInterval time.Duration) *SessionPool

func (*SessionPool) Delete added in v1.43.0

func (sp *SessionPool) Delete(key string)

func (*SessionPool) Get added in v1.43.0

func (sp *SessionPool) Get(key string) (*Session, bool)

func (*SessionPool) SessionCount added in v1.43.0

func (sp *SessionPool) SessionCount() int

func (*SessionPool) Set added in v1.43.0

func (sp *SessionPool) Set(key string, session *Session)

func (*SessionPool) UpdateKey added in v1.43.0

func (sp *SessionPool) UpdateKey(oldKey, newKey string)

Jump to

Keyboard shortcuts

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