Skip to content

Commit

Permalink
fix(krb5): use uuid as user keytab name
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghuagang committed Jan 9, 2025
1 parent 280d56c commit 97d4211
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pkg/kerberos/kadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package kerberos
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"os/exec"
"path"
"strings"
"sync"

"github.com/google/uuid"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand Down Expand Up @@ -123,17 +126,8 @@ func (k *Kadmin) Query(query string) (result string, err error) {
// Ktadd generates a keytab file for the given principals
// Usage: ktadd [-k[eytab] keytab] [-q] [-e keysaltlist] [-norandkey] [principal | -glob princ-exp] [...]
func (k *Kadmin) Ktadd(principals ...string) ([]byte, error) {
// Create a temporary file for the keytab
tmpFile, err := os.CreateTemp("", "*.keytab")
if err != nil {
logger.Error(err, "Failed to create temporary keytab file")
return nil, err
}
keytab := tmpFile.Name()
keytab := path.Join(os.TempDir(), fmt.Sprintf("%s.keytab", uuid.New().String()))
defer func() {
if closeErr := tmpFile.Close(); closeErr != nil {
logger.Error(closeErr, "Failed to close temporary keytab file")
}
if err := os.RemoveAll(keytab); err != nil {
logger.Error(err, "Failed to remove keytab")
}
Expand Down

0 comments on commit 97d4211

Please sign in to comment.