Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CF_GMSA_OU environment variable #86

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ journalctl -u credentials-fetcher
| :-------------------------- | ---------------------------------------- | :------------------------------------------------------------------------------------------- |
| `CF_CRED_SPEC_FILE` | '/var/credentials-fetcher/my-credspec.json' | Path to a credential spec file used as input. (Lease id default: credspec) |
| | '/var/credentials-fetcher/my-credspec.json:myLeaseId' | An optional lease id specified after a colon
| `CF_GMSA_OU` | 'CN=Managed Service Accounts' | Component of GMSA distinguished name (see docs/cf_gmsa_ou.md) |

## Compatibility

Expand Down
9 changes: 7 additions & 2 deletions auth/kerberos/src/krb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Active Directory uses NetBIOS computer names that do not exceed 15 characters.
// https://learn.microsoft.com/en-us/troubleshoot/windows-server/identity/naming-conventions-for-computer-domain-site-ou
#define HOST_NAME_LENGTH_LIMIT 15
#define ENV_CF_GMSA_OU "CF_GMSA_OU"

static const std::string install_path_for_decode_exe =
"/usr/sbin/credentials_fetcher_utf16_private.exe";
Expand Down Expand Up @@ -661,9 +662,13 @@ std::pair<int, std::string> get_gmsa_krb_ticket( std::string domain_name,
* Accounts,DC=contoso,DC=com' -s sub "(objectClass=msDs-GroupManagedServiceAccount)"
* msDS-ManagedPassword
*/
std::string gmsa_ou = std::string( ",CN=Managed Service Accounts," );
if ( getenv(ENV_CF_GMSA_OU) != NULL)
{
gmsa_ou = std::string( "," ) + std::string( getenv(ENV_CF_GMSA_OU) ) + std::string( "," );
}
std::string cmd = std::string( "ldapsearch -H ldap://" ) + fqdn;
cmd += std::string( " -b 'CN=" ) + gmsa_account_name +
std::string( ",CN=Managed Service Accounts," ) + base_dn + std::string( "'" ) +
cmd += std::string( " -b 'CN=" ) + gmsa_account_name + gmsa_ou + base_dn + std::string( "'" ) +
std::string( " -s sub \"(objectClass=msDs-GroupManagedServiceAccount)\" "
" msDS-ManagedPassword" );

Expand Down
5 changes: 5 additions & 0 deletions docs/cf_gmsa_ou.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Active Directory administrator can create the GMSA account with any distinguished name format.

credentials-fetcher uses the GMSA distinguished name format "CN=${GMSA_ACCOUNT_NAME},${CF_GMSA_OU},DC=example,DC=com" where ",DC=example,DC=com" is generated depending on the domain. The environment variable CF_GMSA_OU default value is "CN=Managed Service Accounts". Users should change it to match their directory format.

For example, GMSA account "BobSponge" in domain "example.com" results in GMSA distinguished name "CN=BobSponge,CN=Managed Service Accounts,DC=example,DC=com". When the user defines CF_GMSA_OU='OU=DA Managed Service Accounts,OU=DA' results in GMSA distinguished name "CN=BobSponge,OU=DA Managed Service Accounts,OU=DA,DC=example,DC=com"