git: detected dubious ownership in Azure Blob Storage mapped on a Azure VM

560 Views Asked by At

When I run git status, git branch --track, git fetch --all, git pull --all inside a git repository stored inside an Azure Blob Storage mapped to an Azure virtual machine with Windows 11 and Git for Windows version 2.37.3, I get the following error:

fatal: detected dubious ownership in repository at '<path>'
'<path>' is owned by:
'S-1-5-18'
but the current user is:
'S-1-5-21-1990399924-2863569968-2306271318-500'
To add an exception for this directory, call:

        git config --global --add safe.directory '%(prefix)///<path>'

I have tested:

git config --global --add safe.directory '%(prefix)///<path>'

and

git config --global --add safe.directory '*'

and change directories and files permissions:

TAKEOWN /F * /R

But when I do all this in a local folder of the virtual machine everything works perfectly.

2

There are 2 best solutions below

0
Imran On

I tried to reproduce same in my environment I got the error like below.

![enter image description here](https://i.imgur.com/AqUPS02.png)

This error usually occurs When git will determine whether the current user is the owner of the git repository folder. if not, it will display the error like below because if the folder is not owned by the currently logged-in user, harmful files may be added there by other users.

To resolve the issue:

You can make use of this command.

git config --global --add safe.directory <path>

As you tested above command already, try the below workaround:

Select the folder of the git warehouse. If this folder is full of git warehouses, you can select the entire folder or select your file -> properties -> security -> advanced like below:

enter image description here

If the owner is not same as current windows login account, click to change.

enter image description here

enter image description here

Click Find Now and search your current account name and click okay.

enter image description here

enter image description here

Refer this SO thread by halt9k to disable inheritance.

When I tried to use git status or git log now error doesn't occur like below:

enter image description here

0
VonC On

Git 2.44 (Q1 2024) will be more helpful with this error message.

In addition to (rather cryptic) Security Identifiers, it will now show username and domain in the error message when it barfs on a mismatch between the Git directory and the current user on Windows.

See commit f755e09 (08 Jan 2024) by Sören Krecker (soerenkrecker-baader).
(Merged by Junio C Hamano -- gitster -- in commit b5fb623, 19 Jan 2024)

mingw: give more details about unsafe directory's ownership

Signed-off-by: Sören Krecker
Acked-by: Johannes Sixt

Add domain/username in error message, if owner sid of repository and user sid are not equal on windows systems.

Old error message:

fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by:
    'S-1-5-21-571067702-4104414259-3379520149-500'
but the current user is:
    'S-1-5-21-571067702-4104414259-3379520149-1001'
To add an exception for this directory, call:  

    git config --global --add safe.directory C:/Users/test/source/repos/git

New error message:

fatal: detected dubious ownership in repository at 'C:/Users/test/source/repos/git' 'C:/Users/test/source/repos/git' is owned by:
    DESKTOP-L78JVA6/Administrator (S-1-5-21-571067702-4104414259-3379520149-500)
but the current user is:
    DESKTOP-L78JVA6/test (S-1-5-21-571067702-4104414259-3379520149-1001)
To add an exception for this directory, call:  

    git config --global --add safe.directory C:/Users/test/source/repos/git