-
Notifications
You must be signed in to change notification settings - Fork 1.1k
RANGER-5758 : Support for Openldap service for ranger usersync in ran… #1193
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
Open
pushkargogte
wants to merge
1
commit into
apache:master
Choose a base branch
from
pushkargogte:RANGER-5758-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| #!/bin/bash | ||
|
|
||
| # ============================================================================== | ||
| # Ranger Complete Master Alignment Script (Streamlined Fallback Engine) | ||
| # Description: Synchronizes all LDAP settings across four layout layers: | ||
| # 1. Ranger Admin Install Properties | ||
| # 2. Ranger UserSync Install Properties (with Search Base Fallbacks) | ||
| # 3. Docker Compose Privilege Overrides | ||
| # 4. Dynamically Generates docker-compose.local-ldap.yml | ||
| # ============================================================================== | ||
|
|
||
| # --- Target Configuration Blueprints --- | ||
| ADMIN_PROP="./scripts/admin/ranger-admin-install-postgres.properties" | ||
| USERSYNC_PROP="./scripts/usersync/ranger-usersync-install.properties" | ||
| COMPOSE_FILE="docker-compose.ranger.yml" | ||
| LDAP_COMPOSE_FILE="docker-compose.local-ldap.yml" | ||
|
|
||
| # --- Core Top-Level Configuration Blueprint --- | ||
| AUTH_METHOD="LDAP" | ||
| LDAP_HOST="local-ldap" | ||
| LDAP_PORT="389" | ||
| LDAP_DOMAIN="example.com" | ||
| BASE_DN="dc=example,dc=com" | ||
| BIND_DN="cn=admin,dc=example,dc=com" | ||
| BIND_PASS="p@ssw0rd" | ||
| USER_BASE="ou=People,dc=example,dc=com" | ||
| GROUP_BASE="ou=People,dc=example,dc=com" | ||
| LARGE_GROUP_SYNC_ENABLED="true" | ||
|
|
||
| # Derived Values | ||
| LDAP_URL="ldap://${LDAP_HOST}:${LDAP_PORT}" | ||
| USER_PATTERN="cn={0},${USER_BASE}" | ||
| USER_FILTER="(cn={0})" | ||
| GROUP_FILTER="(member=cn={0},${GROUP_BASE})" | ||
|
|
||
| # --- Color Definitions for Logging --- | ||
| C_RESET='\033[0m' | ||
| C_GREEN='\033[0;32m' | ||
| C_YELLOW='\033[0;33m' | ||
| C_CYAN='\033[0;36m' | ||
| C_RED='\033[0;31m' | ||
|
|
||
| log_info() { echo -e "${C_CYAN}[INFO]${C_RESET} $1"; } | ||
| log_ok() { echo -e "${C_GREEN}[OK]${C_RESET} $1"; } | ||
| log_warn() { echo -e "${C_YELLOW}[WARN]${C_RESET} $1"; } | ||
| log_err() { echo -e "${C_RED}[ERROR]${C_RESET} $1"; exit 1; } | ||
|
|
||
| # --- Pre-flight Validation Checks --- | ||
| [[ ! -f "$ADMIN_PROP" ]] && log_err "Target missing: $ADMIN_PROP" | ||
| [[ ! -f "$USERSYNC_PROP" ]] && log_err "Target missing: $USERSYNC_PROP" | ||
| [[ ! -f "$COMPOSE_FILE" ]] && log_err "Target missing: $COMPOSE_FILE" | ||
|
|
||
| # Handle cross-platform in-place sed adjustments (macOS vs standard Linux) | ||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||
| sed_cmd() { sed -i '' "$@"; } | ||
| else | ||
| sed_cmd() { sed -i "$@"; } | ||
| fi | ||
|
|
||
| # Helper function for flat Key-Value file overrides | ||
| update_property() { | ||
| local key="$1" local val="$2" local file="$3" | ||
| local escaped_val=$(printf '%s\n' "$val" | sed 's/[&/\]/\\&/g') | ||
| if grep -q "^[[:space:]]*$key[[:space:]]*=" "$file"; then | ||
| sed_cmd -E "s|^([[:space:]]*$key[[:space:]]*=[[:space:]]*).*|\1$escaped_val|" "$file" | ||
| else | ||
| echo "$key = $val" >> "$file" | ||
| fi | ||
| } | ||
|
|
||
| # ============================================================================== | ||
| # Execution Lifecycle | ||
| # ============================================================================== | ||
|
|
||
| log_info "Initiating deployment update for all Ranger environment files..." | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Phase 1: Modify ranger-admin-install-postgres.properties | ||
| # ------------------------------------------------------------------------------ | ||
| log_info "Processing configuration properties inside $ADMIN_PROP..." | ||
|
|
||
| update_property "authentication_method" "$AUTH_METHOD" "$ADMIN_PROP" | ||
|
|
||
| if ! grep -q "Corporate OpenLDAP Authentication Setup" "$ADMIN_PROP"; then | ||
| echo -e "\n# ====================================================================" >> "$ADMIN_PROP" | ||
| echo "# Corporate OpenLDAP Authentication Setup" >> "$ADMIN_PROP" | ||
| echo -e "# ====================================================================\n" >> "$ADMIN_PROP" | ||
| fi | ||
|
|
||
| update_property "xa_ldap_url" "$LDAP_URL" "$ADMIN_PROP" | ||
| update_property "xa_ldap_base_dn" "$BASE_DN" "$ADMIN_PROP" | ||
| update_property "xa_ldap_bind_dn" "$BIND_DN" "$ADMIN_PROP" | ||
| update_property "xa_ldap_bind_password" "$BIND_PASS" "$ADMIN_PROP" | ||
| update_property "xa_ldap_userDNpattern" "$USER_PATTERN" "$ADMIN_PROP" | ||
| update_property "xa_ldap_userSearchFilter" "$USER_FILTER" "$ADMIN_PROP" | ||
| update_property "xa_ldap_groupSearchBase" "$GROUP_BASE" "$ADMIN_PROP" | ||
| update_property "xa_ldap_groupSearchFilter" "$GROUP_FILTER" "$ADMIN_PROP" | ||
| update_property "xa_ldap_groupRoleAttribute" "cn" "$ADMIN_PROP" | ||
| update_property "xa_ldap_referral" "ignore" "$ADMIN_PROP" | ||
|
|
||
| log_ok "Successfully updated native Admin install properties." | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Phase 2: Modify ranger-usersync-install.properties (With Lean Fallbacks) | ||
| # ------------------------------------------------------------------------------ | ||
| log_info "Processing configuration properties inside $USERSYNC_PROP..." | ||
|
|
||
| update_property "SYNC_SOURCE" "ldap" "$USERSYNC_PROP" | ||
| update_property "SYNC_LDAP_URL" "$LDAP_URL" "$USERSYNC_PROP" | ||
| update_property "SYNC_LDAP_BIND_DN" "$BIND_DN" "$USERSYNC_PROP" | ||
| update_property "SYNC_LDAP_BIND_PASSWORD" "$BIND_PASS" "$USERSYNC_PROP" | ||
|
|
||
| # The Single Source of Truth Base DN Path | ||
| update_property "SYNC_LDAP_USER_SEARCH_BASE" "$USER_BASE" "$USERSYNC_PROP" | ||
| update_property "SYNC_LDAP_USER_SEARCH_FILTER" "(objectClass=inetOrgPerson)" "$USERSYNC_PROP" | ||
|
|
||
| # Explicitly clear out broader root to enforce automated hierarchical fallback loops | ||
| update_property "SYNC_LDAP_SEARCH_BASE" "" "$USERSYNC_PROP" | ||
|
|
||
| # Group Specific Filtering Strategy | ||
| update_property "SYNC_LDAP_GROUP_SEARCH_FILTER" "(objectClass=groupOfNames)" "$USERSYNC_PROP" | ||
|
|
||
| # Normalizations & Performance Scaling Optimizations | ||
| update_property "SYNC_USERNAME_CASE_CONVERSION" "lower" "$USERSYNC_PROP" | ||
| update_property "SYNC_GROUPNAME_CASE_CONVERSION" "lower" "$USERSYNC_PROP" | ||
| update_property "LGSYNC_LDAP_LARGEGROUPSYNC_ENABLED" "$LARGE_GROUP_SYNC_ENABLED" "$USERSYNC_PROP" | ||
|
|
||
| log_ok "Successfully streamlined UserSync configuration properties." | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Phase 3: Streamline docker-compose.ranger.yml | ||
| # ------------------------------------------------------------------------------ | ||
| log_info "Reviewing permission parameters inside $COMPOSE_FILE..." | ||
|
|
||
| python3 -c " | ||
| import re | ||
|
|
||
| with open('$COMPOSE_FILE', 'r') as f: | ||
| yaml_content = f.read() | ||
|
|
||
| regex_pattern = r'(user:\s*root\s*\n\s*)?(command|entrypoint):\s*\n\s*-\s*(?:/bin/bash[\s\S]*?)?/home/ranger/scripts/ranger\.sh\"?' | ||
|
|
||
| clean_native_entrypoint = '''user: root | ||
| entrypoint: | ||
| - /bin/bash | ||
| - -c | ||
| - | | ||
| # Hand execution off directly to the native initialization runtime | ||
| chown -R ranger:ranger /opt/ranger/admin/ | ||
| su -s /bin/bash ranger -c \"/home/ranger/scripts/ranger.sh\"''' | ||
|
|
||
| yaml_content = re.sub(r'\s*extra_hosts:\s*\n\s*-\s*\"ccycloud.*?:127\.0\.0\.1\"', '', yaml_content) | ||
| updated_content, substitutions = re.subn(regex_pattern, clean_native_entrypoint, yaml_content) | ||
|
|
||
| if substitutions > 0: | ||
| with open('$COMPOSE_FILE', 'w') as f: | ||
| f.write(updated_content) | ||
| print('SUCCESS') | ||
| else: | ||
| print('NO_CHANGE') | ||
| " > /tmp/ranger_py_status.tmp | ||
|
|
||
| PY_STATUS=$(cat /tmp/ranger_py_status.tmp) | ||
| rm -f /tmp/ranger_py_status.tmp | ||
|
|
||
| if [ "$PY_STATUS" == "SUCCESS" ]; then | ||
| log_ok "Successfully synchronized Docker privilege blocks inside $COMPOSE_FILE." | ||
| else | ||
| log_warn "Docker Compose alignment skipped (already up to date)." | ||
| fi | ||
|
|
||
| # ------------------------------------------------------------------------------ | ||
| # Phase 4: Auto-Generate docker-compose.local-ldap.yml | ||
| # ------------------------------------------------------------------------------ | ||
| log_info "Generating infrastructure layer config inside $LDAP_COMPOSE_FILE..." | ||
|
|
||
| cat << EOF > "$LDAP_COMPOSE_FILE" | ||
| services: | ||
| local-ldap: | ||
| image: osixia/openldap:1.5.0 | ||
| container_name: ${LDAP_HOST} | ||
| hostname: ${LDAP_HOST}.rangernw | ||
| ports: | ||
| - "${LDAP_PORT}:389" | ||
| - "636:636" | ||
| environment: | ||
| - LDAP_ORGANISATION=RangerNW | ||
| - LDAP_DOMAIN=${LDAP_DOMAIN} | ||
| - LDAP_ADMIN_PASSWORD=${BIND_PASS} | ||
| - LDAP_TLS=false | ||
| networks: | ||
| - ranger | ||
|
|
||
| local-ldap-admin: | ||
| image: osixia/phpldapadmin:0.9.0 | ||
| container_name: ${LDAP_HOST}-admin | ||
| ports: | ||
| - "8080:80" | ||
| environment: | ||
| - PHPLDAPADMIN_HTTPS=false | ||
| - PHPLDAPADMIN_LDAP_HOSTS=${LDAP_HOST} | ||
| networks: | ||
| - ranger | ||
| depends_on: | ||
| - local-ldap | ||
|
|
||
| networks: | ||
| ranger: | ||
| name: rangernw | ||
| EOF | ||
|
|
||
| log_ok "Successfully auto-built $LDAP_COMPOSE_FILE with variables alignment." | ||
|
|
||
| echo | ||
| log_ok "All Ranger and OpenLDAP configurations are perfectly unified! 🎉" | ||
| log_warn "Run your 'down -v' and 'up -d' routine to compile everything into the cluster." | ||
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,18 @@ | ||
| # 1. Base Structural Container | ||
| dn: ou=People,dc=example,dc=com | ||
| objectClass: organizationalUnit | ||
| ou: People | ||
|
|
||
| # 2. User Entry | ||
| dn: cn=john,ou=People,dc=example,dc=com | ||
| cn: john | ||
| sn: doe | ||
| objectClass: inetOrgPerson | ||
| userPassword: password123 | ||
| uid: john | ||
|
|
||
| # 3. Group Entry | ||
| dn: cn=engineering,ou=People,dc=example,dc=com | ||
| cn: engineering | ||
| objectClass: groupOfNames | ||
| member: cn=john,ou=People,dc=example,dc=com |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add license header