Skip to content
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

fix: Use host environment for git to get root path #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zaporozhets
Copy link

Hi All,

A few years ago, Git introduced a safe directory policy that prevents Git commands from running, particularly in CI environments. This behavior breaks the get_root_path functionality because the command:

git rev-parse --show-toplevel --show-superproject-working-tree

returns the following error:

fatal: detected dubious ownership in repository at '/builds/taras.zaporozhets/yoyo'
To add an exception for this directory, call:
	git config --global --add safe.directory /builds/taras.zaporozhets/yoyo

This MR updates get_root_path to allow Git to use the host gitconfig, including the defined exception directory.

Best,
Taras

@jan-kiszka
Copy link
Collaborator

Thanks for your bug report. Could you please describe in more details how to reproduce it?

Regarding patch contributions, please have a look at https://github.com/siemens/kas/blob/master/CONTRIBUTING.md. What is specifically missing formally is a commit message (merge request threads can get lost, the git history stays) and the signed-off.

Regarding how to address the issue: kas is intentionally not simply passing everything through from the host environment to ensure reproducibility in different setups. Once the issue can be reproduced, we will have to discuss how to address it best without violating that rule. BTW, reproduction will also allow writing a test case for this.

@zaporozhets
Copy link
Author

Hi Jan,

Thank you for your quick response and for sharing the contribution checklist.

I created a demo project to illustrate this issue:
https://gitlab.com/zaporozhets/kas-demo

The project contains a main configuration YAML file (machine/product/demo-board.yml), which includes a secondary configuration (machine/common/debug.yml). The secondary file is referenced relative to the Git repository path, which is determined by the get_root_path function. However, this function fails in GitLab CI due to different repository ownership, causing KAS to be unable to locate the secondary configuration file. Please find logs and link to CI below

$ kas -l debug checkout machine/product/demo-board.yml
2025-02-13 08:26:14 - INFO     - kas 4.7 started
2025-02-13 08:26:14 - DEBUG    - Using selector: EpollSelector
2025-02-13 08:26:14 - DEBUG    - /builds/zaporozhets/kas-demo/machine/product$ git rev-parse --show-toplevel --show-superproject-working-tree
2025-02-13 08:26:14 - DEBUG    - /builds/zaporozhets/kas-demo/machine/product$ hg root
2025-02-13 08:26:14 - DEBUG    - /builds/zaporozhets/kas-demo/machine/product$ git rev-parse --show-toplevel --show-superproject-working-tree
2025-02-13 08:26:14 - DEBUG    - /builds/zaporozhets/kas-demo/machine/product$ hg root
2025-02-13 08:26:14 - DEBUG    - execute setup_dir
2025-02-13 08:26:14 - DEBUG    - execute setup_home
2025-02-13 08:26:14 - INFO     - Running on GitLab CI
2025-02-13 08:26:14 - DEBUG    - execute init_setup_repos
2025-02-13 08:26:14 - ERROR    - Configuration file not found: /builds/zaporozhets/kas-demo/machine/product/machine/common/debug.yml


https://gitlab.com/zaporozhets/kas-demo/-/jobs/9126156151

Best,
Taras.

@fmoessbauer
Copy link
Member

Thanks for the example. I already suspected that this happens in a GitLab CI environment. In the kas docker container we have a workaround for that in the entrypoint. The root cause is the same for your container and the kas container: Switching the user.

Would it be possible for you to just apply the same workaround to your container entrypoint?
Another strategy (also for kas) would be to conditionally apply this workaround if a GitLab CI environment is detected (we already have special handling for well-known CI envs in place).

@zaporozhets
Copy link
Author

Hi Felix,

I appreciate you pointing me to the workaround. I added it to the Dockerfile instead of the entry point:

# Work around gitlab-runner not aligning checked out repo ownership
# with our builder user
RUN git config --system safe.directory "*"

It works(https://gitlab.com/zaporozhets/kas-demo/-/jobs/9127280910), so I'll stick with it for now.

Wishing you a great day!

Best,
Taras

fmoessbauer added a commit to fmoessbauer/kas that referenced this pull request Feb 13, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: siemens#141
Signed-off-by: Felix Moessbauer <[email protected]>
fmoessbauer added a commit to fmoessbauer/kas that referenced this pull request Feb 13, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: siemens#141
Signed-off-by: Felix Moessbauer <[email protected]>
fmoessbauer added a commit to fmoessbauer/kas that referenced this pull request Feb 13, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: siemens#141
Signed-off-by: Felix Moessbauer <[email protected]>
@fmoessbauer
Copy link
Member

@zaporozhets : I just sent a patch series to the kas ML that fixes the safe-dir handling also for non kas-container users. It would be great if you could have a look and check if patches 1 and 2 solve your issue as well. With that, you should not need to set any git safe dirs manually. https://groups.google.com/g/kas-devel/c/xPPsXQ--xs4

The patches are also available under https://github.com/fmoessbauer/kas/tree/fm/git-safe-dir-v1

@zaporozhets
Copy link
Author

@fmoessbauer, thanks. I'll try them today/tomorrow and let you know.

fmoessbauer added a commit to fmoessbauer/kas that referenced this pull request Feb 28, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: siemens#141
Signed-off-by: Felix Moessbauer <[email protected]>
fmoessbauer added a commit to fmoessbauer/kas that referenced this pull request Feb 28, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: siemens#141
Signed-off-by: Felix Moessbauer <[email protected]>
jan-kiszka pushed a commit that referenced this pull request Mar 3, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: #141
Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
jan-kiszka pushed a commit that referenced this pull request Mar 4, 2025
The GitLab CI runner mounts the $CI_PROJECT_DIR git project root from
the outside but does not align the ownership of that directory with the
user of the docker container. By that, git does not allow to perform any
operation on that repository.

As this is a well-known case, we mark that directory as a safe dir if
running in GitLab CI.

Xref: #141
Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants