Skip to content

Commit

Permalink
chore(gpg_secretstore): add warning if running as root
Browse files Browse the repository at this point in the history
  • Loading branch information
transcaffeine committed Jan 2, 2024
1 parent fecbcc6 commit 2e5bc1d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions plugins/modules/gpg_secretstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
returned: failed or successful but with warnings
"""

import os
import hashlib
from pathlib import Path

Expand Down Expand Up @@ -351,12 +352,18 @@ def main():

errors = []
traceback = []
warnings = []

# Warn if running as root
if os.geteuid() == 0:
warnings.append("Running as root, ensure GPG keyring is present for root user")

error_map = check_secretstore_import_errors() | check_module_import_errors()
for lib, exception in error_map.items():
errors.append(missing_required_lib(lib))
traceback.append(exception)
if errors:
module.fail_json(errors=errors, traceback="\n".join(traceback))
module.fail_json(warning=',\n'.join(warnings), errors=errors, traceback="\n".join(traceback))

store = SecretStore(
password_store_path=module.params["password_store_path"],
Expand All @@ -382,7 +389,7 @@ def main():
result = dict(
changed=False,
message="",
warning="",
warning=warnings,
password_slug=module.params["password_slug"],
secret="",
ansible_facts={},
Expand Down Expand Up @@ -486,7 +493,7 @@ def main():
module.log(result["message"])

if result["warning"]:
module.warn(result["warning"])
module.warn(',\n'.join(result["warning"]))

result["diff"]["before"] = "\n".join(result["diff"]["before"]) + "\n"
result["diff"]["after"] = "\n".join(result["diff"]["after"]) + "\n"
Expand Down

0 comments on commit 2e5bc1d

Please sign in to comment.