-
Notifications
You must be signed in to change notification settings - Fork 4
Add LDAP-based git identity and SSSD config for immediate git config setup #274
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
Merged
+78
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6229f03
Add LDAP-based git identity and SSSD config
cmyers-mieweb acda133
Add LDAP-based git identity and SSSD config
cmyers-mieweb d16a353
Improve git identity discovery & LDAP base resolution
cmyers-mieweb faab59c
Merge branch 'cmyers_wazuh-int' of https://github.com/mieweb/opensour…
cmyers-mieweb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/env bash | ||
| # Automatically configures git user.name and user.email from the user's LDAP | ||
| # profile on first interactive login to a container. Subsequent logins skip | ||
| # this entirely once git config is set. | ||
| # | ||
| # The name is read from the NSS gecos field (mapped from LDAP cn via sssd.conf). | ||
| # The email is read from LDAP via an anonymous ldapsearch (REQUIRE_AUTH_FOR_SEARCH | ||
| # is disabled on the internal ldap-gateway, so no bind credentials are needed). | ||
|
|
||
| # Only run for interactive shells | ||
| [[ $- != *i* ]] && return | ||
|
|
||
| # Only if git is available | ||
| command -v git >/dev/null 2>&1 || return | ||
| command -v ldapsearch >/dev/null 2>&1 || return | ||
|
|
||
| # Skip if already configured — user-set values always take precedence | ||
| [ -n "$(git config --global user.email 2>/dev/null)" ] && [ -n "$(git config --global user.name 2>/dev/null)" ] && return | ||
|
|
||
| _GIT_SETUP_USER="${USER:-$(id -un 2>/dev/null)}" | ||
| [ -z "$_GIT_SETUP_USER" ] && return | ||
| [ "$_GIT_SETUP_USER" = "root" ] && return | ||
|
|
||
| # Full name from NSS (SSSD reads the LDAP gecos attribute by default via ldap_user_gecos) | ||
| _GIT_SETUP_NAME=$(getent passwd "$_GIT_SETUP_USER" 2>/dev/null | cut -d: -f5) | ||
|
|
||
| # Email from LDAP anonymous query | ||
| _GIT_SETUP_LDAP_HOST="${LDAP_URI:-ldaps://ldap1:636}" | ||
|
|
||
| # Resolve baseDN the same way SSSD does: rootDSE namingContexts autodiscovery. | ||
| # Use LDAP_BASE_DN if explicitly set; otherwise query rootDSE. | ||
| # - Single namingContexts entry -> use it directly | ||
| # - Multiple namingContexts -> use defaultNamingContext | ||
| # - Neither resolvable -> abort | ||
| if [ -n "${LDAP_BASE_DN:-}" ]; then | ||
| _GIT_SETUP_LDAP_BASE="$LDAP_BASE_DN" | ||
| else | ||
| _GIT_SETUP_ROOTDSE=$(ldapsearch -x -H "$_GIT_SETUP_LDAP_HOST" -b "" -s base namingContexts defaultNamingContext 2>/dev/null) | ||
| _GIT_SETUP_NC_COUNT=$(echo "$_GIT_SETUP_ROOTDSE" | grep -c '^namingContexts:') | ||
| if [ "$_GIT_SETUP_NC_COUNT" -eq 1 ]; then | ||
| _GIT_SETUP_LDAP_BASE=$(echo "$_GIT_SETUP_ROOTDSE" | awk '/^namingContexts:/{print $2; exit}') | ||
| elif [ "$_GIT_SETUP_NC_COUNT" -gt 1 ]; then | ||
| _GIT_SETUP_LDAP_BASE=$(echo "$_GIT_SETUP_ROOTDSE" | awk '/^defaultNamingContext:/{print $2; exit}') | ||
| fi | ||
| unset _GIT_SETUP_ROOTDSE _GIT_SETUP_NC_COUNT | ||
| fi | ||
| [ -z "${_GIT_SETUP_LDAP_BASE:-}" ] && return | ||
|
|
||
| _GIT_SETUP_EMAIL=$(ldapsearch -x \ | ||
| -H "$_GIT_SETUP_LDAP_HOST" \ | ||
| -b "$_GIT_SETUP_LDAP_BASE" \ | ||
| "(uid=${_GIT_SETUP_USER})" mail 2>/dev/null \ | ||
| | awk '/^mail:/{print $2; exit}') | ||
|
|
||
| if [ -n "$_GIT_SETUP_NAME" ]; then | ||
| git config --global user.name "$_GIT_SETUP_NAME" | ||
| fi | ||
|
|
||
| if [ -n "$_GIT_SETUP_EMAIL" ]; then | ||
| git config --global user.email "$_GIT_SETUP_EMAIL" | ||
| fi | ||
|
|
||
| unset _GIT_SETUP_USER _GIT_SETUP_NAME _GIT_SETUP_EMAIL _GIT_SETUP_LDAP_HOST _GIT_SETUP_LDAP_BASE _GIT_SETUP_ROOTDSE _GIT_SETUP_NC_COUNT | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # OpenLDAP client configuration for containers. | ||
| # Mirrors the TLS check level used by SSSD (ldap_tls_reqcert = allow) so that | ||
| # ldapsearch and other ldap-utils tools accept the internal certificate without | ||
| # additional flags. | ||
| TLS_REQCERT allow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.