Skip to content

Commit beb3d6b

Browse files
msgs-txt-reviewed
1 parent e07f2bf commit beb3d6b

3 files changed

Lines changed: 15 additions & 24 deletions

File tree

internal/params/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const (
6767
IgnoreProxyFlag = "ignore-proxy"
6868
IgnoreProxyFlagUsage = "Ignore proxy configuration"
6969
ProxyTypeFlag = "proxy-auth-type"
70-
ProxyTypeFlagUsage = "Proxy authentication type, (basic, ntlm, or kerberos)"
70+
ProxyTypeFlagUsage = "Proxy authentication type (supported types: basic, ntlm or Kerberos)"
7171
TimeoutFlag = "timeout"
7272
TimeoutFlagUsage = "Timeout for network activity, (default 5 seconds)"
7373
NtlmProxyDomainFlag = "proxy-ntlm-domain"
@@ -80,8 +80,8 @@ const (
8080
SastRecommendedExclusionsFlags = "sast-recommended-exclusions"
8181
NtlmProxyDomainFlagUsage = "Window domain when using NTLM proxy"
8282
KerberosProxySPNFlagUsage = "Service Principal Name (SPN) for Kerberos proxy authentication"
83-
KerberosKrb5ConfFlagUsage = "Path to krb5 configuration file for Kerberos (default: /etc/krb5.conf)"
84-
KerberosCcacheFlagUsage = "Path to Kerberos credential cache (optional, uses KRB5CCNAME env or default)"
83+
KerberosKrb5ConfFlagUsage = "Path to Kerberos configuration file(default: /etc/krb5.conf on linux and C:\\Windows\\krb5.ini on windows)"
84+
KerberosCcacheFlagUsage = "Path to Kerberos credential cache (optional, default uses KRB5CCNAME env or OS default)"
8585
BaseURIFlagUsage = "The base system URI"
8686
BaseAuthURIFlag = "base-auth-uri"
8787
BaseAuthURIFlagUsage = "The base system IAM URI"

internal/wrappers/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func kerberosProxyClient(timeout uint, proxyStr string) *http.Client {
218218
// Validate required SPN parameter
219219
if proxySPN == "" {
220220
logger.PrintIfVerbose("Error: Kerberos SPN is required for Kerberos proxy authentication.")
221-
logger.Print("Error: Kerberos SPN is required for the Kerberos proxy authentication.")
221+
logger.Print("Error: Kerberos SPN is required for Kerberos proxy authentication.")
222222
logger.PrintIfVerbose("Please provide SPN using: --proxy-kerberos-spn 'HTTP/proxy.example.com' or set CX_PROXY_KERBEROS_SPN environment variable")
223223
logger.PrintIfVerbose("Falling back to basic proxy authentication")
224224
// Return a basic client that will fail gracefully

internal/wrappers/kerberos/proxy-kerberos.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"github.com/pkg/errors"
2121
)
2222

23+
const osWindows = "windows"
24+
2325
// NonRetryableError represents an error that should not trigger HTTP request retries
2426
type NonRetryableError struct {
2527
Message string
@@ -66,7 +68,6 @@ func NewKerberosProxyDialContext(dialer *net.Dialer, proxyURL *url.URL,
6668
}
6769

6870
func dialAndNegotiate(addr string, kerberosConfig KerberosConfig, baseDial func() (net.Conn, error)) (net.Conn, error) {
69-
7071
conn, err := baseDial()
7172
if err != nil {
7273
log.Printf("Could not call dial context with proxy: %s", err)
@@ -166,21 +167,19 @@ func dialAndNegotiate(addr string, kerberosConfig KerberosConfig, baseDial func(
166167
// This function performs all the same checks as dialAndNegotiate but without actually
167168
// making network connections, allowing early detection of configuration problems
168169
func ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN string) error {
169-
170-
// Use default krb5.conf path if not specified
171170
if krb5ConfPath == "" {
172-
krb5ConfPath = GetDefaultKrb5ConfPath()
171+
krb5ConfPath = GetDefaultKrb5ConfPath() // Use default krb5.conf path if not specified
173172
}
174173

175174
// Check if krb5.conf exists
176175
if _, err := os.Stat(krb5ConfPath); os.IsNotExist(err) {
177-
return errors.New("Kerberos configuration file not found. Please ensure krb5 configuration file is properly configured")
176+
return errors.New("Kerberos proxy authentication setup failed because no valid Kerberos config file was found. Please ensure that a properly configured krb5.conf/krb5.ini file is available at the specified location.")
178177
}
179178

180179
// Load krb5.conf to validate it's readable
181-
_, err := config.Load(krb5ConfPath)
180+
krb5cfg, err := config.Load(krb5ConfPath)
182181
if err != nil {
183-
return errors.New("failed to load Kerberos configuration. Please check the krb5 configuration file")
182+
return errors.New("Kerberos proxy authentication setup failed because no valid Kerberos config file was found. Please ensure that a properly configured krb5.conf/krb5.ini file is available at the specified location.")
184183
}
185184

186185
// Get default credential cache path if not specified
@@ -191,25 +190,19 @@ func ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN string) error {
191190
// Check if credential cache exists
192191
if ccachePath != "" {
193192
if _, err := os.Stat(ccachePath); os.IsNotExist(err) {
194-
return errors.New("Kerberos credential cache not found. Please run 'kinit' to obtain Kerberos tickets first")
193+
return errors.New("Kerberos proxy authentication setup failed because no Kerberos credential cache was found. Make sure to run 'kinit' to populate the cache before running this command.")
195194
}
196195
}
197196

198197
// Try to load credential cache to validate it's usable
199198
cc, err := credentials.LoadCCache(ccachePath)
200199
if err != nil {
201-
return errors.New("failed to load Kerberos credential cache. Please run 'kinit' to obtain valid Kerberos tickets")
202-
}
203-
204-
// Try to create Kerberos client to validate tickets are valid
205-
krb5cfg, err := config.Load(krb5ConfPath)
206-
if err != nil {
207-
return errors.New("failed to reload Kerberos configuration")
200+
return errors.New("Kerberos proxy authentication setup failed because no Kerberos credential cache was found. Make sure to run 'kinit' to populate the cache before running this command.")
208201
}
209202

210203
_, err = client.NewFromCCache(cc, krb5cfg)
211204
if err != nil {
212-
return errors.New("failed to create Kerberos client. Please check your Kerberos tickets with 'klist'")
205+
return errors.New("Failed to create Kerberos client. Please check your Kerberos tickets with 'klist'")
213206
}
214207

215208
return nil
@@ -218,7 +211,7 @@ func ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN string) error {
218211
// GetDefaultKrb5ConfPath returns the default krb5.conf path for the current platform
219212
func GetDefaultKrb5ConfPath() string {
220213
switch runtime.GOOS {
221-
case "windows":
214+
case osWindows:
222215
// Windows typically uses krb5.ini
223216
if windir := os.Getenv("WINDIR"); windir != "" {
224217
return filepath.Join(windir, "krb5.ini")
@@ -248,9 +241,7 @@ func getDefaultCCachePath() string {
248241
}
249242

250243
switch runtime.GOOS {
251-
case "windows":
252-
// On Windows, use the default credential cache managed by the system
253-
// The gokrb5 library should handle this automatically with empty string
244+
case osWindows:
254245
return ""
255246
default:
256247
// Linux, macOS, and other Unix-like systems

0 commit comments

Comments
 (0)