forked from EnterpriseDB/tpa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store the ansible-vault password in the system keyring by default
We used to write the vault password to vault/vault_pass.txt, and we'll continue to work with existing clusters where that is the case. For new clusters, we'll try to use the keyring module to store the password into any available system keyring (e.g., gnome-keyring). Use `tpaexec configure … --keyring-backend <name>` to select a backend, but the only available choices are "system" (the default) and "legacy" (which is to use vault/vault_pass.txt). vault/vault_pass.txt method stores credentials inside the cluster directory and therefore there is no chance of conflict when multiple clusters using the same name are provisioned on a single tpa host, it's a challenge though when using a shared service. The change introduces an additional configuration setting named `vault_name` for the config.yml to go with the `keyring_backend`. For new clusters configured using `tpaexec configure` command, `vault_name` will be set to a UUID to make sure the combination of `cluster_name` and `vault_name` gives us a unique combination when `system` (default) is used as the keyring_backend. `vault_name` can be set to any arbitrary value to make sure the combination of `cluster_name` and `vault_name` is unique. It does not have to comply with UUID format. Also update tpaexec-configure.md to document `keyring_backend` and `vault_name` settings. Adds `show-vault` command; it displays the vault password for both `legacy` and `system` backends. With contributions from Abhijit and Haroon. References: TPA-85
- Loading branch information
1 parent
b63e942
commit 4eff8cb
Showing
18 changed files
with
534 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,3 +232,5 @@ workflow/ | |
|
||
coverage-reports/ | ||
lib/tests/config/* | ||
requirements-dev.in | ||
requirements-dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../use-vault |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# © Copyright EnterpriseDB UK Limited 2015-2023 - All rights reserved. | ||
|
||
import sys | ||
from tpaexec.password import delete_password, exists | ||
|
||
|
||
def main( | ||
cluster_dir, keyring_backend="system", password_name="vault_pass" | ||
): | ||
""" | ||
delete vault password in chosen keyring backend | ||
exit code 0 if a password was deleted, otherwise exit code 2. | ||
""" | ||
if exists(cluster_dir, password_name, keyring_backend): | ||
delete_password(cluster_dir, password_name, keyring_backend) | ||
sys.exit(0) | ||
else: | ||
sys.exit(2) | ||
|
||
|
||
if __name__ == "__main__": | ||
from sys import argv | ||
|
||
main(*argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# © Copyright EnterpriseDB UK Limited 2015-2023 - All rights reserved. | ||
|
||
import sys | ||
from os import path | ||
from tpaexec.password import store_password, exists, generate_password | ||
|
||
|
||
def main( | ||
cluster_dir, keyring_backend=None, password_name="vault_pass", | ||
): | ||
""" | ||
generate and store vault password in chosen keyring backend | ||
exit code 0 if new password was generated else exit code 2 if password already existed. | ||
""" | ||
if not exists(path.basename(path.abspath(cluster_dir)), password_name, keyring_backend): | ||
store_password( | ||
cluster_dir, | ||
password_name, | ||
generate_password(), | ||
keyring_backend, | ||
) | ||
sys.exit(0) | ||
else: | ||
sys.exit(2) | ||
|
||
|
||
if __name__ == "__main__": | ||
from sys import argv | ||
|
||
main(*argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
# © Copyright EnterpriseDB UK Limited 2015-2023 - All rights reserved. | ||
from os import getenv, getcwd | ||
from os import path | ||
|
||
import yaml | ||
from tpaexec.password import show_password | ||
|
||
|
||
def main(): | ||
""" | ||
retrieve vault password from chosen keyring backend | ||
""" | ||
cluster_dir = getcwd() | ||
try: | ||
with open(path.join(cluster_dir, "config.yml")) as config_file: | ||
config = yaml.safe_load(config_file) | ||
keyring_backend = config.get( | ||
"keyring_backend", getenv("TPA_KEYRING_BACKEND", None) | ||
) | ||
password_name = config.get( | ||
"vault_name", "vault_pass") | ||
except IOError: | ||
print(f"could not load {path.join(cluster_dir, 'config.yml')}") | ||
raise | ||
|
||
show_password(cluster_dir, password_name, keyring_backend) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.