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

Running go test for gopass modifies global config and also removes mounts #2725

Closed
AnomalRoil opened this issue Nov 25, 2023 · 3 comments · Fixed by #2727
Closed

Running go test for gopass modifies global config and also removes mounts #2725

AnomalRoil opened this issue Nov 25, 2023 · 3 comments · Fixed by #2727
Labels
bug Defects
Milestone

Comments

@AnomalRoil
Copy link
Member

Summary

If you have a mounted substore, e.g. "test":

gopass (/home/anomalroil/.local/share/gopass/stores/root)
└── test (/home/anomalroil/.local/share/gopass/stores/test)

and you run go test ./... somehow your config is changed and you'll loose your mount and will have to mount it again.

Steps To Reproduce

$ gopass init --store test
$ gopass mounts
$ git clone https://github.com/gopasspw/gopass && cd gopass
$ go test ./... -count=1
$ gopass mounts

Expected behavior

Running the tests should remain contained to some kind of /tmp files and not affect the global developer config for gopass.

Environment

  • OS: Ubuntu 22.04
  • OS version: 6.5.6-76060506-generic #202310061235~1697396945~22.04~9283e32 SMP PREEMPT_DYNAMIC Sun O x86_64 x86_64 x86_64 GNU/Linux
  • gopass Version: master tip
  • Installation method: from source
@dominikschulz dominikschulz added the bug Defects label Nov 25, 2023
@dominikschulz dominikschulz added this to the 1.15.11 milestone Nov 25, 2023
@dominikschulz
Copy link
Member

dominikschulz commented Nov 25, 2023

Running under strace shows that go test ./... writes to the global gopass config a few times ☹️

$ GOPASS_HOMEDIR=/tmp/gp1
$ strace -f -o /tmp/gopass.strace go test ./... -count=1
$ grep "/tmp/gp1/.config/gopass/config" /tmp/gopass.strace | grep O_WRONLY
256051 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>
256049 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>
256060 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>
256049 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>
256435 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>
256049 openat(AT_FDCWD, "/tmp/gp1/.config/gopass/config", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0600 <unfinished ...>

Now we need to figure out where this happens.

Edit: Actually this overwrites the entire config (O_CREATE and O_TRUNC).

@dominikschulz
Copy link
Member

The plot thickens:

$ grep "writing config to /tmp/gp1/.config/gopass/config" /tmp/gp.log 
2023/11/25 18:20:57.225061 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config: 
2023/11/25 18:20:57.226834 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config: 
2023/11/25 18:20:57.233848 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config: 
2023/11/25 18:20:57.234426 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config: 
2023/11/25 18:20:57.278175 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config: 
2023/11/25 18:20:57.307876 gitconfig/config.go:258	gitconfig.(*Config).flushRaw	writing config to /tmp/gp1/.config/gopass/config:

@dominikschulz
Copy link
Member

I think I got it (mostly). Not exactly sure what the root cause is, but the trigger might be related to some of your recent changes @AnomalRoil .

We should probably add ctx = config.NewNoWrites().WithConfig(ctx) to every (?) unit test.
Will work on a PR tomorrow.

dominikschulz added a commit to dominikschulz/gopass that referenced this issue Nov 25, 2023
Fixes gopasspw#2725

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
dominikschulz added a commit to dominikschulz/gopass that referenced this issue Nov 26, 2023
Fixes gopasspw#2725

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
dominikschulz added a commit to dominikschulz/gopass that referenced this issue Dec 1, 2023
Fixes gopasspw#2725

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
dominikschulz added a commit that referenced this issue Dec 1, 2023
* [bugfix] Fix writes to global config from tests

Fixes #2725

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

* Shorten readonly config creation.

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

* Address review comments

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>

---------

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Defects
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants