krb5test

package module
v0.0.0-...-97bb4b0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

README

krb5test

This project provides a mock Kerberos Domain Controller (KDC) suitable for testing.

The mock KDC does not provide all KDC funcationality but it does cover the basics of:

  • Responding to the initial login to obtain a TGT via an AS exchange
  • Granting a service ticket in response to a TGS exchange

Usage

  1. Create a logger that the KDC will log to:
l := log.New(os.Stderr, "KDC Test Server: ", log.LstdFlags)
  1. Create a map of principals (both user and service principals). The keys of the map are the principal names and the values are the groups each is a member of.
p := make(map[string][]string)
p["testuser1"] = []string{"testgroup1"}
p["HTTP/host.test.realm.com"] = []string{}
  1. Create the KDC test instance:
kdc, err := NewKDC(p, l)
  1. Start the KDC server and defer its closure:
kdc.Start()
defer kdc.Close()

The KDC dynamically creates credentials for the principals specified. These can be accessed in the form of a keytab from the KDC:

kdc.Keytab

A krb5.conf that can be used for a client can also be obtained from the KDC instance:

kdc.KRB5Conf

The KDC instance will dynamically pick available ports to use on localhost. Use of this krb5.conf will automatically wire up any client to use this connection.

The Realm name used is also available from the KDC instance:

kdc.Realm

You can also customize the mock KDC by Option like below code:

kdc, err := NewKDC(
    p, l,
    WithEncType("aes256-cts-hmac-sha1-96"), // customize encrypt type supported in mock KDC
    WithSrvAddr("127.0.0.1:0"),             // customize server addr of mock KDC
    WithRealm("TEST.REALM.COM"),            // customize realm of mock KDC
    WithDomain("test.realm.com"),           // customize domain of mock KDC
)

Documentation

Index

Constants

View Source
const (
	DEFAULT_ENC_TYPE = "aes256-cts-hmac-sha1-96" // default encrypt type supported in KDC
	DEFAULT_ADDR     = "127.0.0.1:0"             // default server address of KDC
	DEFAULT_REALM    = "TEST.REALM.COM"          // default Realm of KDC
	DEFAULT_DOMAIN   = "test.realm.com"          // default Domain of KDC
)

Variables

This section is empty.

Functions

This section is empty.

Types

type KDC

type KDC struct {
	Realm      string
	KRB5Conf   *config.Config
	SName      types.PrincipalName
	Principals map[string]PrincipalDetails
	Keytab     *keytab.Keytab
	Logger     *log.Logger

	TCPListener net.Listener
	UDPListener net.PacketConn
	// contains filtered or unexported fields
}

func NewKDC

func NewKDC(principals map[string][]string, l *log.Logger, opts ...KDCOption) (*KDC, error)

func (*KDC) Close

func (k *KDC) Close()

func (*KDC) Start

func (k *KDC) Start()

type KDCOption

type KDCOption = func(*kdcConfig)

func WithDomain

func WithDomain(domain string) KDCOption

func WithEncType

func WithEncType(encType string) KDCOption

func WithRealm

func WithRealm(realm string) KDCOption

func WithSrvAddr

func WithSrvAddr(srvAddr string) KDCOption

type PrincipalDetails

type PrincipalDetails struct {
	Password string
	Groups   []string
	Client   *client.Client
}

Jump to

Keyboard shortcuts

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