Fix Git safe.directory errors across all roles (Git 2.35+)#323
Draft
Fix Git safe.directory errors across all roles (Git 2.35+)#323
Conversation
Copilot
AI
changed the title
[WIP] Fix dubious ownership and safe.directory errors
Fix Git safe.directory errors across all roles (Git 2.35+)
Feb 18, 2026
5eb4b72 to
b1fe707
Compare
b1fe707 to
846c02b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Git 2.35+ enforces
safe.directoryprotections, causingfatal: detected dubious ownershiperrors during deployments when git operations run under users that don't match directory ownership.Changes
Added two tasks before git operations in affected roles:
1. Ownership enforcement
2. Idempotent safe.directory configuration
Roles Updated
tasks/deploy.yml) - edx-platform checkoutstasks/deploy.yml) - cs_comments_service checkoutstasks/main.yml) - tableau repo checkoutstasks/main.yml) - shared git handler; also fixed existing safe.directory task to run asrepo_ownerinstead of rootThe git_clone changes fix 20+ services indirectly: analytics_api, blockstore, credentials, discovery, ecommerce, insights, registrar, mfe, and all other services using
edx_service/edx_django_service.Notes
{{ edxapp_user }},{{ forum_code_dir }})Original prompt
We are seeing Git "dubious ownership" /
safe.directoryerrors across many applications managed by theedx/configurationrepository, not justedxapp.Example error (from edxapp, but similar patterns are appearing elsewhere):
The underlying cause is consistent: newer Git versions (2.35+) enforce
safe.directoryprotections and refuse to operate in repositories where the effective user runninggitdoes not match expected ownership or where the directory hierarchy appears unsafe. Our Ansible roles inedx/configurationperform GitHub checkouts for multiple apps (edxapp, and others) and then rungitoperations (e.g.,git clean,git pull, etc.), which are now failing under these protections.We already have a targeted PR in-flight for edxapp, but we now want a more global, systematic fix that applies to all apps defined in
edx/configurationthat check out code from GitHub and run git commands.Goals for this PR:
Implement a global pattern in
edx/configurationfor safely handling Git checkouts for all app roles that pull code from GitHub and then rungitcommands.Target branch:
master.The solution should be:
{{ app_user }},{{ app_code_dir }}, or the role-specific equivalents like{{ edxapp_user }},{{ edxapp_code_dir }}) instead of hard-coded usernames or paths.Implementation strategy (to be reflected in code changes):
For each applicable role / play that manages a Git checkout for an app (including but not limited to edxapp), do the following before any
gitoperations (checkout, pull, clean, etc.):a. Ensure correct ownership of the code directory
Add an Ansible
filetask to enforce appropriate ownership on the app's code directory. For example, in pseudo-code:This should be placed before any
gittasks (e.g.,git clean,git pull, or customcommand/shelltasks invoking git) that operate on the app's code directory.b. Mark the directory as safe for Git for the app user
For environments where Git may still consider the repo "dubious" due to higher-level directory ownership or other security heuristics, explicitly configure
safe.directoryfor the app's code directory, executed as the app user:This ensures Git can operate on that repository for the app user without triggering
rc: 128errors due tosafe.directorychecks.Scope of changes:
Identify all roles and tasks in
edx/configurationthat:git,command,shell, or specific Ansible git modules).For each such app/role, add tasks implementing (4a) and (4b) using the role's existing variables for user and code directory.
If there is a shared or common pattern (for example, a base role or helper tasks included by multiple app roles for Git checkouts), prefer implementing the logic in that shared place to avoid duplication; otherwise, implement per-role.
Documentation and comments:
safe.directory/ "dubious ownership" protections introduced in newer Git versions.Testing / validation expectations:
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.