gss

package
v1.23.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GSS (Kerberos) authentication

go-hdb can authenticate to a HANA database with Kerberos via the GSS-API. The user authenticates once to a Key Distribution Center (KDC) at login (kinit, or a Windows domain logon) and obtains a ticket; the driver presents a service ticket for the database, and HANA maps the Kerberos principal to a database user. No password travels on the wire.

Design goals

go-hdb's default build is pure Go, with no CGO and no third-party runtime dependencies. Producing a Kerberos ticket is in tension with this: it requires a GSS library — the system libgssapi_krb5 (Linux/macOS) or SSPI (Windows) — and go-hdb does not want to pull such a dependency, or bless one particular third-party Kerberos package, onto every consumer whether or not they use Kerberos.

So go-hdb ships no built-in GSS mechanism in its default build. It defines a small Initiator interface and lets the application bring its own implementation wrapping whatever GSS library fits its platform and dependency requirements. If no initiator is configured, the driver behaves exactly as before — no Kerberos, no extra dependencies. A CGO reference implementation for Linux is included but gated behind a build tag, so it never reaches the default build.

The driver itself does no Kerberos cryptography. It speaks the HANA authentication protocol and shuttles opaque GSS tokens between the server and the application's Initiator.

The Initiator interface

type Initiator interface {
    SrcName() string
    InitSecContext(ctx context.Context, targetName string, inputToken []byte) (outputToken []byte, established bool, err error)
}
  • The application sets ConnectorConfig.GSS to a func() (Initiator, error); the driver calls it once per connection, so each connection owns its own GSS security context. There is no shared mutable state, hence no locking requirement on the application.
  • SrcName returns the client principal (user@REALM).
  • InitSecContext advances the context and is called in a loop until established is true: inputToken is nil on the first call and the server's latest token thereafter, outputToken is sent to the server. Raw Kerberos needs one round beyond the first; SPNEGO may need several.
Mapping to the native GSS API

The interface uses GSS-API vocabulary so the mapping to the native call is direct on every platform:

Initiator Unix GSS (gss_init_sec_context) Windows SSPI (InitializeSecurityContext)
InitSecContext gss_init_sec_context InitializeSecurityContext
targetName target_name pszTargetName
inputToken (in) input_token (empty first call) pInput
outputToken (out) output_token pOutput
established GSS_S_COMPLETE vs GSS_S_CONTINUE_NEEDED SEC_E_OK vs SEC_I_CONTINUE_NEEDED
SrcName gss_inquire_cred / gss_display_name QueryCredentialsAttributes (names)

The credential (for delegation) and the request flags (mutual auth, integrity, confidentiality, replay) are internal to the implementation — the driver has no surface for them.

Usage

Enable GSS on the connector and supply an Initiator factory:

cfg := driver.NewConnectorConfig()
cfg.Host = "hana:39017"
cfg.AuthMethods = driver.AuthGSS // offer GSS (omit to offer all methods)
cfg.GSS = gss.NewInitiator       // or your own func() (gss.Initiator, error)

gss.NewInitiator is the tag-gated Linux reference (build with gssapi); for other platforms supply your own factory. No username or password is set: the server maps the Kerberos principal to a database user. On success HANA may return a session cookie, which the driver stores and replays for fast reconnect — handled automatically, no caller action.

Security

  • Request mutual authentication. An implementation MUST request mutual authentication (and integrity and replay detection) when it builds the context. With mutual auth the server proves its identity with an AP-REP that only the holder of the service keytab can produce; without it the server is not authenticated. Unlike LDAP, the driver cannot enforce this — the flags live in the application's implementation — so it is the implementation's responsibility.
  • GSS authenticates, it does not encrypt the SQL traffic. Kerberos secures the login only. As with every other method, use TLS for confidentiality of the data on the wire.

Delegation

A middle-tier service can connect to HANA as the end user (constrained delegation) by having its Initiator use a forwarded credential — it passes that credential's handle to the native call instead of the default ticket cache. This needs no driver support: the application's implementation owns which credential it uses.

Reference implementation

The package includes a reference Initiator for Linux backed by the system libgssapi_krb5 (MIT Kerberos), guarded by the gssapi build tag (gss.NewInitiator), so neither CGO nor libgssapi are dependencies of the default build. It requests mutual authentication, integrity, confidentiality and replay detection, and uses raw Kerberos V5 (not SPNEGO).

SPNEGO and other platforms (Windows SSPI, macOS) are bring-your-own: the interface supports them — SPNEGO is just more InitSecContext rounds — but go-hdb ships only the raw-Kerberos Linux reference. For production, provide an Initiator that fits your platform, dependency and security requirements.

Documentation

Overview

Package gss defines the interface for Kerberos authentication via GSS-API. See the package README for rationale, the mapping to the native GSS API, and implementation notes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Initiator

type Initiator interface {
	// SrcName returns the initiator (client) name - the Kerberos client
	// principal (user@REALM) in practice. The GSS term is used here because
	// the interface is mechanism-neutral; a Windows/SSPI implementor reads it
	// as the client credential's name.
	SrcName() string
	// InitSecContext advances the security context, mirroring
	// gss_init_sec_context. targetName is the service name the server
	// announced; inputToken is the server's latest token, nil on the first
	// call; the returned outputToken is sent to the server. established
	// reports that the context is complete (GSS_S_COMPLETE vs
	// GSS_S_CONTINUE_NEEDED); the driver calls InitSecContext in a loop until
	// then.
	InitSecContext(ctx context.Context, targetName string, inputToken []byte) (outputToken []byte, established bool, err error)
}

Initiator drives one connection's GSS-API context establishment. The driver never calls the GSS API itself; the application wraps the native API (gss_init_sec_context on Linux/macOS, InitializeSecurityContext on Windows SSPI) behind this interface. The driver obtains a fresh Initiator per connection from ConnectorConfig.GSS, so each connection owns its own GSS security context and no locking is required.

Jump to

Keyboard shortcuts

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