jcmturner / gokrb5

Pure Go Kerberos library for clients and services
Apache License 2.0
717 stars 243 forks source link

API to get default config/ccache/keytab path #499

Open viacheslavka opened 1 year ago

viacheslavka commented 1 year ago

The MIT krb5 implementation provides a set of defaults for various values, e.g. port numbers, config file paths and so on. Many of these defaults can be overridden with user-provided environment variables, which is a convenient way to avoid telling each program where their keytabs and credentials caches are placed.

While it is possible for applications to check all the necessary environment variables and default values themselves, it would probably be much simpler for everyone if the library provided such functionality out of the box. Even better, the library could provide a way to create a "default" client using nothing but these default values.

To implement this, I suggest adding a pair of functions names GetDefaultPath and LoadDefault (or similar) to each of the following packages: config, keytab, credentials. A default client could be created with a function called NewFromDefaults.

I understand that the code needs to be platform-agnotic, but I believe that environment variables are ubiquitous enough and the new API should not prevent the library from working on platforms where it's hard to find a default path, as it can simply return an error if it encounters any issues or runs on an unsupported platform.