From 176f6a62ae44f07ebdf5cbec6daa7276eb459697 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 08:06:57 +0200 Subject: [PATCH] [PR #8689/8989b6c4 backport][stable-9] Namespace the passwordstore lockfile (#8746) Namespace the passwordstore lockfile (#8689) * Namespace the lockfile When passwordstore needs to grab a lock, it creates a statically file (within /tmp, typically). This is unfortunate, when there might be more than one user using the passwordstore functionality on that machine. Prepend the user to the filename, to bypass further issues. * Update plugins/lookup/passwordstore.py specifically reference the argument number in the format string. Co-authored-by: Felix Fontein * Add changelog fragment for PR#8689 * Update 8689-passwordstore-lock-naming.yml I was sure that was a copy/paste. * Update changelogs/fragments/8689-passwordstore-lock-naming.yml specify the type of plugin Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 8989b6c4d4b7588c7f0c97185fb18bb9bf9d08c2) Co-authored-by: Adam Tygart --- changelogs/fragments/8689-passwordstore-lock-naming.yml | 2 ++ plugins/lookup/passwordstore.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/8689-passwordstore-lock-naming.yml diff --git a/changelogs/fragments/8689-passwordstore-lock-naming.yml b/changelogs/fragments/8689-passwordstore-lock-naming.yml new file mode 100644 index 0000000000..c5c9a82d78 --- /dev/null +++ b/changelogs/fragments/8689-passwordstore-lock-naming.yml @@ -0,0 +1,2 @@ +minor_changes: + - passwordstore lookup plugin - add the current user to the lockfile file name to address issues on multi-user systems (https://github.com/ansible-collections/community.general/pull/8689). diff --git a/plugins/lookup/passwordstore.py b/plugins/lookup/passwordstore.py index a1b0842a7b..510bdbec3d 100644 --- a/plugins/lookup/passwordstore.py +++ b/plugins/lookup/passwordstore.py @@ -469,7 +469,8 @@ class LookupModule(LookupBase): def opt_lock(self, type): if self.get_option('lock') == type: tmpdir = os.environ.get('TMPDIR', '/tmp') - lockfile = os.path.join(tmpdir, '.passwordstore.lock') + user = os.environ.get('USER') + lockfile = os.path.join(tmpdir, '.{0}.passwordstore.lock'.format(user)) with FileLock().lock_file(lockfile, tmpdir, self.lock_timeout): self.locked = type yield