gssapi icon indicating copy to clipboard operation
gssapi copied to clipboard

Fix dynamic GSSAPI lib path detection on macOS for kerberos

Open VikasShavi opened this issue 9 months ago • 0 comments

Description

This PR fixes an issue where the GSSAPI library path for kerberos auth was hardcoded to /usr/lib/libgssapi_krb5.dylib on macOS in lib_gssapi_loader.rb.
This caused failures when GSSAPI was installed via Homebrew, as the actual path differs or does not come by default.

Issue

When using the GSSAPI library for Kerberos authentication with WinRM, authentication fails due to the hardcoded libgssapi_krb5.dylib path.
The error occurs because users with Homebrew-installed Kerberos have the library in /opt/homebrew/Cellar/krb5/....

Error Screenshot

errorbundle

errorproxychains

Fix

  • Instead of a hardcoded path in lib_gssapi_loader.rb, this PR dynamically detects the correct GSSAPI library location:
    • Uses brew --prefix to find the Homebrew installation directory.
    • Falls back to /usr/lib/ if Homebrew is not installed.
  • This ensures compatibility across both system-installed and Homebrew-installed Kerberos libraries.
when /darwin/
  brew_lib = `brew --prefix krb5 2>/dev/null`.chomp
  gssapi_lib = File.exist?("#{brew_lib}/lib/libgssapi_krb5.dylib") ? "#{brew_lib}/lib/libgssapi_krb5.dylib" : '/usr/lib/libgssapi_krb5.dylib'
  ffi_lib gssapi_lib, FFI::Library::LIBC

After fixing code

successbundle

successproxychains

Why This Fix is Needed

  • Recent macOS versions do not include libgssapi_krb5.dylib by default.
  • Users installing Kerberos via Homebrew (krb5 package) have libgssapi_krb5.dylib in /opt/homebrew/Cellar/....
  • The previous hardcoded path caused FFI::Library::ffi_lib to fail, making GSSAPI unusable.
  • This fix allows the library to work seamlessly on macOS regardless of installation method.

Notes for Users

📌 If you are on macOS and do not have libgssapi_krb5.dylib, install it using:

brew install krb5

VikasShavi avatar Mar 09 '25 11:03 VikasShavi