Skip to content

Commit 0dbd349

Browse files
committed
fix: ssp krb5 v8 compatibility
1 parent 82b2c90 commit 0dbd349

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

ssp/credential/ccache.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import (
99
v8_credentials "github.com/jcmturner/gokrb5/v8/credentials"
1010
)
1111

12+
type CCacheV8 interface {
13+
Credential
14+
// CCache V8.
15+
CCache() *v8_credentials.CCache
16+
}
17+
1218
type CCache interface {
1319
Credential
1420
// CCache.

ssp/credential/credential.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,35 @@ func parseUser(un string, opts ...Option) userCred {
2525
// the domain name, user name, and workstation.
2626
func parseDomainUserWorkstation(un string, opts ...Option) (string, string, string) {
2727

28-
wkst := ""
28+
wkst, dn := "", ""
2929

3030
for _, opt := range opts {
3131
switch v := opt.(type) {
3232
case wkstOpt:
3333
wkst = string(v)
34+
case domainOpt:
35+
dn = string(v)
3436
}
3537
}
3638

3739
// down-level logon name.
3840
if strings.Contains(un, "\\") {
3941
un := strings.SplitN(un, "\\", 2)
42+
if dn != "" {
43+
return dn, un[1], wkst
44+
}
4045
return un[0], un[1], wkst
4146
}
4247

4348
if strings.Contains(un, "@") {
4449
un := strings.SplitN(un, "@", 2)
50+
if dn != "" {
51+
return dn, un[0], wkst
52+
}
4553
return un[1], un[0], wkst
4654
}
4755

48-
return "", un, wkst
56+
return dn, un, wkst
4957
}
5058

5159
// DomainName function returns the domain name from the user name.
@@ -66,3 +74,18 @@ func NewFromString(s string, opts ...Option) Password {
6674
}
6775
return NewFromPassword(s, "", append(opts, AllowEmptyPassword())...)
6876
}
77+
78+
func V8ToV9(cred Credential) Credential {
79+
80+
if cred, ok := (any)(cred).(KeytabV8); ok {
81+
return NewFromKeytabV8(cred.UserName(), cred.Keytab(),
82+
Workstation(cred.Workstation()), Domain(cred.DomainName()))
83+
}
84+
85+
if cred, ok := (any)(cred).(CCacheV8); ok {
86+
return NewFromCCacheV8(cred.UserName(), cred.CCache(),
87+
Workstation(cred.Workstation()), Domain(cred.DomainName()))
88+
}
89+
90+
return cred
91+
}

ssp/credential/keytab.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import (
99
v8_keytab "github.com/jcmturner/gokrb5/v8/keytab"
1010
)
1111

12+
type KeytabV8 interface {
13+
Credential
14+
// Keytab.
15+
Keytab() *v8_keytab.Keytab
16+
}
17+
1218
// Keytab interface defines the Kerberos 5 Keytab credential.
1319
type Keytab interface {
1420
Credential

ssp/credential/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ func (allowEmptyPassword) is_CredentialOption() {}
2121
func AllowEmptyPassword() Option {
2222
return allowEmptyPassword{}
2323
}
24+
25+
type domainOpt string
26+
27+
func (domainOpt) is_CredentialOption() {}
28+
29+
func Domain(s string) Option {
30+
return domainOpt(s)
31+
}

ssp/krb5/authentifier.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ type SecurityService struct {
4949
}
5050

5151
func (a *Authentifier) makeService(ctx context.Context) (*service.Settings, error) {
52-
kt, _ := a.Config.Credential.(credential.Keytab)
52+
kt, ok := credential.V8ToV9(a.Config.Credential).(credential.Keytab)
53+
if !ok {
54+
return nil, fmt.Errorf("krb5: make service: invalid credential type: %T", a.Config.Credential)
55+
}
5356
return service.NewSettings(kt.Keytab(), a.Config.ServiceSettings()...), nil
5457
}
5558

@@ -106,7 +109,7 @@ func (a *Authentifier) makeClient(ctx context.Context) (*client.Client, error) {
106109
a.Config.GetKRB5Config(), a.Config.ClientSettings()...)
107110
}
108111

109-
switch cred := a.Config.Credential.(type) {
112+
switch cred := credential.V8ToV9(a.Config.Credential).(type) {
110113
case credential.Password:
111114
cli.Credentials = creds.WithPassword(cred.Password())
112115
case credential.Keytab:

ssp/krb5/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ func parseETypes(s []string, w bool) []int32 {
182182

183183
func IsValidCredential(cred any) bool {
184184

185+
if genericCred, ok := cred.(credential.Credential); ok {
186+
cred = credential.V8ToV9(genericCred)
187+
}
188+
185189
if _, ok := cred.(credential.Keytab); ok {
186190
return true
187191
}

0 commit comments

Comments
 (0)