@@ -8,12 +8,10 @@ package object
8
8
9
9
import (
10
10
"encoding/base64"
11
- "encoding/binary"
12
11
"fmt"
13
12
"github.com/jcmturner/gokrb5/v8/keytab"
14
13
"os"
15
14
"os/user"
16
- "path/filepath"
17
15
"strings"
18
16
19
17
krb "github.com/jcmturner/gokrb5/v8/client"
@@ -35,30 +33,26 @@ func getKerberosClient() (*krb.Client, error) {
35
33
// Try to authenticate with keytab file first.
36
34
keytabPath := os .Getenv ("KRB5KEYTAB" )
37
35
keytabBase64 := os .Getenv ("KRB5KEYTAB_BASE64" )
36
+ principal := os .Getenv ("KRB5PRINCIPAL" )
37
+
38
+ var kt * keytab.Keytab
38
39
if keytabBase64 != "" {
39
40
decodedKeytab , err := base64 .StdEncoding .DecodeString (keytabBase64 )
40
41
if err != nil {
41
42
return nil , fmt .Errorf ("error decoding Base64 encoded data %s" , err )
42
43
}
43
- decodedKeytabPath := filepath .Join (os .TempDir (), "decodedKeytab" )
44
- decodedKeytabFile , err := os .Create (decodedKeytabPath )
45
- if err != nil {
46
- return nil , fmt .Errorf ("failed to create %s" , decodedKeytabPath )
47
- }
48
- defer decodedKeytabFile .Close ()
49
- // keytab file format uses network byte order
50
- err = binary .Write (decodedKeytabFile , binary .BigEndian , decodedKeytab )
44
+ kt = new (keytab.Keytab )
45
+ err = kt .Unmarshal (decodedKeytab )
51
46
if err != nil {
52
- return nil , fmt . Errorf ( "failed to write %s" , decodedKeytabPath )
47
+ return nil , err
53
48
}
54
- keytabPath = decodedKeytabPath
55
- }
56
- principal := os .Getenv ("KRB5PRINCIPAL" )
57
- if keytabPath != "" && principal != "" {
58
- kt , err := keytab .Load (keytabPath )
49
+ } else if keytabPath != "" {
50
+ kt , err = keytab .Load (keytabPath )
59
51
if err != nil {
60
52
return nil , err
61
53
}
54
+ }
55
+ if kt != nil {
62
56
// e.g. KRB5PRINCIPAL="primary/instance@realm"
63
57
sp := strings .Split (principal , "@" )
64
58
if len (sp ) != 2 {
0 commit comments