esp-idf/docs/en
Frantisek Hrbata 99f9dd4c07 feat(docker): allow to add paths into git's safe.directory
With 8959555cee7e[1] ("setup_git_directory(): add an owner check for the top..")
git added an ownership check of the git directory and refuses to
run any git commands, even parsing the config file, if the git directory
is not owned by the current user. The "fatal: detected dubious ownership in repository"
is reported.

This fixes CVE-2022-24765[2], which allows to compromise user account. On a
multi-user system or e.g. on a shared file system, one user may create a "rogue"
git repository with e.g. core.fsmonitor set to an arbitrary command. Other user
may unwillingly execute this command by running e.g. git-diff or
git-status within the "rogue" git repository, which may be in one of the parent
directories. If e.g. PS1 is set to display information about a git
repository in CWD, as suggested in Git in Bash[3], the user do not need to run
any git command to trigger this, just entering some subdirectory under
this "rogue" git repository is enough, because the git command will be
started transparently through the script used in PS1. The core.fsmonitor
can be set to arbitrary command. It's purpose is to help git to identify changed files
and speed up the scanning for changed files.

rogue
├── .git     # owned by user1
└── dir1     # owned by user2
    ├── dir2 # owned by user2
    └── .git # owned by user2

user1 sets core.fsmonitor for git repository in rogue directory
$ git config --add core.fsmonitor "bash -c 'rm -rf \$HOME'"

user2 enters dir1 and runs e.g. git diff and triggers the core.fsmonitor command.

The ownership check may cause problems when running git commands in
ESP-IDF Docker container. For example user may run the container as
root, but the mounted project may be owned by a particular user.

In this case git will refuse to execute any git command within the
"/project" directory, because it's not owned by root. To overcome this,
git allows to set safe.directories, for which the ownership check is
skipped. The security check may be completely disabled by setting
safe.directories to "*". This solution was proposed in PR 12636[4], but
it would allow make it possible to exploit this vulnerability again.

This fix allows user to specify git's safe.directory in IDF_GIT_SAFE_DIR
environmental variable, which may be set during container startup.

The IDF_GIT_SAFE_DIR has same format as PATH and multiple directories can be
specified by using a ":" separator. To entirely disable this git security check
within the container, user may set IDF_GIT_SAFE_DIR='*'. This might be
heplfull in CI.

Closes https://github.com/espressif/esp-idf/pull/12636

[1] - 8959555cee
[2] - https://nvd.nist.gov/vuln/detail/cve-2022-24765
[3] - https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Bash
[4] - https://github.com/espressif/esp-idf/pull/12636

Signed-off-by: Frantisek Hrbata <frantisek.hrbata@espressif.com>
2023-12-01 08:23:16 +01:00
..
_templates doc: Add exact git version & target SoC to feedback form parameters 2020-03-27 11:29:59 +11:00
api-guides feat(docker): allow to add paths into git's safe.directory 2023-12-01 08:23:16 +01:00
api-reference Merge branch 'backport/add_ot_radio_stats_enable_config_5_1' into 'release/v5.1' 2023-11-22 12:23:53 +08:00
contribute docs: Provide CN translation for contribute/index.rst 2023-08-23 15:48:42 +08:00
get-started docs: Update CN translation for get-started/index.rst 2023-08-23 11:19:43 +02:00
hw-reference docs: updated misc docs with H2 specific information. 2023-07-11 07:05:53 +00:00
libraries-and-frameworks docs: migrated documentetation from github.io to docs.espressif.com 2023-04-20 13:38:16 +04:00
migration-guides change(wifi): Add supplicant's public API header files to doc 2023-09-25 10:54:52 +05:30
security Merge branch 'bugfix/esp32h2_ecdsa_hardware_k_v5.1' into 'release/v5.1' 2023-11-21 13:57:38 +08:00
third-party-tools docs: fix link_roles not linking correctly for certain files 2020-06-22 20:42:59 +08:00
404.rst docs: update 404.rst 2022-07-04 14:44:29 +08:00
about.rst docs: updated misc docs with H2 specific information. 2023-07-11 07:05:53 +00:00
conf.py docs: update copyright date for docs automatically 2022-01-10 15:05:33 +08:00
COPYRIGHT.rst esp_rom: convert USB related headers to SPDX, update COPYRIGHTS.rst 2023-11-21 17:33:30 +01:00
index.rst docs: add H2 to list of supported series to front page doc 2023-07-28 14:02:16 +08:00
languages.rst doc:updated cn translation for language.rst and version.rst to provide new layout for version/target select 2021-03-12 16:15:56 +08:00
resources.rst docs: update redirected links 2022-05-07 13:09:41 +08:00
versions.rst docs: add commands to updating esp-idf versions in windows system 2022-10-19 15:18:01 +08:00