Skip to content

Commit e07f2bf

Browse files
review-changes
1 parent 28b4797 commit e07f2bf

3 files changed

Lines changed: 10 additions & 38 deletions

File tree

internal/params/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ 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.conf file for Kerberos (default: /etc/krb5.conf)"
83+
KerberosKrb5ConfFlagUsage = "Path to krb5 configuration file for Kerberos (default: /etc/krb5.conf)"
8484
KerberosCcacheFlagUsage = "Path to Kerberos credential cache (optional, uses KRB5CCNAME env or default)"
8585
BaseURIFlagUsage = "The base system URI"
8686
BaseAuthURIFlag = "base-auth-uri"

internal/wrappers/client.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ func kerberosProxyClient(timeout uint, proxyStr string) *http.Client {
217217

218218
// Validate required SPN parameter
219219
if proxySPN == "" {
220-
logger.PrintIfVerbose("ERROR: Kerberos SPN is required for Kerberos proxy authentication.")
221-
logger.Print("ERROR: Kerberos SPN is required for the Kerberos proxy authentication.")
220+
logger.PrintIfVerbose("Error: Kerberos SPN is required for Kerberos proxy authentication.")
221+
logger.Print("Error: Kerberos SPN is required for the 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
@@ -229,19 +229,20 @@ func kerberosProxyClient(timeout uint, proxyStr string) *http.Client {
229229
if krb5ConfPath == "" {
230230
krb5ConfPath = kerberos.GetDefaultKrb5ConfPath()
231231
}
232+
232233
ccachePath := viper.GetString(commonParams.ProxyKerberosCcacheKey)
233234

234235
// Early validation: Check Kerberos setup before creating client
235236
// This ensures errors are caught immediately during client creation, not during HTTP requests
236237
if err := kerberos.ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN); err != nil {
237238
logger.PrintIfVerbose("Error: Kerberos proxy authentication setup failed: " + err.Error())
238-
fmt.Println(fmt.Sprintf("Error: Kerberos proxy authentication setup failed: %v", err.Error()))
239+
logger.Printf("Error: Kerberos proxy authentication setup failed: %v", err.Error())
239240
os.Exit(0)
240241
}
241242

242243
logger.PrintIfVerbose("Creating HTTP client using Kerberos Proxy using: " + proxyStr)
243244
logger.PrintIfVerbose("Kerberos SPN: " + proxySPN)
244-
logger.PrintIfVerbose("Kerberos krb5.conf: " + krb5ConfPath)
245+
logger.PrintIfVerbose("Kerberos krb5 configuration file: " + krb5ConfPath)
245246

246247
kerberosConfig := kerberos.KerberosConfig{
247248
ProxySPN: proxySPN,

internal/wrappers/kerberos/proxy-kerberos.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ func NewKerberosProxyDialContext(dialer *net.Dialer, proxyURL *url.URL,
6666
}
6767

6868
func dialAndNegotiate(addr string, kerberosConfig KerberosConfig, baseDial func() (net.Conn, error)) (net.Conn, error) {
69-
// Validate required SPN parameter early
70-
if kerberosConfig.ProxySPN == "" {
71-
log.Printf("Kerberos SPN is required but not provided")
72-
return nil, errors.New("Kerberos SPN is required. Use --proxy-kerberos-spn flag or CX_PROXY_KERBEROS_SPN env var")
73-
}
7469

7570
conn, err := baseDial()
7671
if err != nil {
@@ -80,36 +75,16 @@ func dialAndNegotiate(addr string, kerberosConfig KerberosConfig, baseDial func(
8075

8176
// Use default krb5.conf path if not specified
8277
krb5ConfPath := kerberosConfig.Krb5ConfPath
83-
if krb5ConfPath == "" {
84-
krb5ConfPath = GetDefaultKrb5ConfPath()
85-
}
86-
87-
// Check if krb5.conf exists before trying to load it
88-
if _, err := os.Stat(krb5ConfPath); os.IsNotExist(err) {
89-
log.Printf("Kerberos configuration file not found at %s", krb5ConfPath)
90-
return conn, errors.New("Kerberos configuration file not found. Please ensure krb5.conf is properly configured")
91-
}
9278

9379
// Load krb5.conf
9480
krb5cfg, err := config.Load(krb5ConfPath)
9581
if err != nil {
96-
log.Printf("Failed to load krb5.conf from %s: %s", krb5ConfPath, err)
97-
return conn, errors.New("failed to load Kerberos configuration. Please check the krb5.conf file")
82+
log.Printf("Failed to load krb5 configuration file from %s: %s", krb5ConfPath, err)
83+
return conn, errors.New("failed to load Kerberos configuration. Please check the krb5 configuration file")
9884
}
9985

10086
// Load credential cache
10187
ccPath := kerberosConfig.CcachePath
102-
if ccPath == "" {
103-
ccPath = getDefaultCCachePath()
104-
}
105-
106-
// Check if credential cache exists before trying to load it
107-
if ccPath != "" {
108-
if _, err := os.Stat(ccPath); os.IsNotExist(err) {
109-
log.Printf("Kerberos credential cache not found at %s", ccPath)
110-
return conn, errors.New("Kerberos credential cache not found. Please run 'kinit' to obtain Kerberos tickets first")
111-
}
112-
}
11388

11489
cc, err := credentials.LoadCCache(ccPath)
11590
if err != nil {
@@ -191,10 +166,6 @@ func dialAndNegotiate(addr string, kerberosConfig KerberosConfig, baseDial func(
191166
// This function performs all the same checks as dialAndNegotiate but without actually
192167
// making network connections, allowing early detection of configuration problems
193168
func ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN string) error {
194-
// Validate SPN
195-
if proxySPN == "" {
196-
return errors.New("Kerberos SPN is required. Use --proxy-kerberos-spn flag or CX_PROXY_KERBEROS_SPN env var")
197-
}
198169

199170
// Use default krb5.conf path if not specified
200171
if krb5ConfPath == "" {
@@ -203,13 +174,13 @@ func ValidateKerberosSetup(krb5ConfPath, ccachePath, proxySPN string) error {
203174

204175
// Check if krb5.conf exists
205176
if _, err := os.Stat(krb5ConfPath); os.IsNotExist(err) {
206-
return errors.New("Kerberos configuration file not found. Please ensure krb5.conf is properly configured")
177+
return errors.New("Kerberos configuration file not found. Please ensure krb5 configuration file is properly configured")
207178
}
208179

209180
// Load krb5.conf to validate it's readable
210181
_, err := config.Load(krb5ConfPath)
211182
if err != nil {
212-
return errors.New("failed to load Kerberos configuration. Please check the krb5.conf file")
183+
return errors.New("failed to load Kerberos configuration. Please check the krb5 configuration file")
213184
}
214185

215186
// Get default credential cache path if not specified

0 commit comments

Comments
 (0)