-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[BUG] sdb.get_or_set_hash does not work with Vault #60779
Comments
I assume it's because it's doing a Either way, the code should probably handle it. |
I think the issue is more likely to be on the Running these commands on the minion with Only # salt-call sdb.get 'sdb://myvault/salt/test1?password'
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[ERROR ] Error from vault: {"errors":[]}
local:
None
# salt-call sdb.get_or_set_hash 'sdb://myvault/salt/test1?password'
== Getting existing records
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[ERROR ] Error from vault: {"errors":[]}
Return value: None
ret is None, setting new value
New value: _7d_s#&-
uri: sdb://myvault/salt/test1?password, val: _7d_s#&-
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[WARNING ] /usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning,
[ERROR ] Unable to connect to vault server: {"errors":["permission denied"]}
[ERROR ] Failed to write secret! HTTPError: 403 Client Error: Forbidden for url: https://<VAULT_ADDR>:8200/v1/salt/test1
Error running 'sdb.get_or_set_hash': 403 Client Error: Forbidden for url: https://<VAULT_ADDR>:8200/v1/salt/test1 Here are the print commands I added, in case you wonder: def sdb_get_or_set_hash(
uri,
opts,
length=8,
chars="abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)",
utils=None,
):
# ...
print("== Getting existing records")
ret = sdb_get(uri, opts, utils=utils)
print(f"Return value: {ret}")
if ret is None:
print("ret is None, setting new value")
val = "".join([random.SystemRandom().choice(chars) for _ in range(length)])
print(f"New value: {val}")
print(f"uri: {uri}, val: {val}")
sdb_set(uri, val, opts, utils)
return ret or val |
Meanwhile, I had another finding. I tried to implement the "get, if empty result, then set" logic in the state file I am trying to write, in order to develop a workaround (since this issue blocks our development process). The By adding a state: tmp_create_secret_vault:
module.run:
- name: sdb.set
- uri: {{ 'sdb://myvault/salt/rabbitmq_team_passwords/' ~ cluster_name ~ '/' ~ team_username ~ '/password' }}
- value: {{ team_password }} From inside Jinja: {% set create_vault_secret_result = salt['sdb.set']('sdb://myvault/salt/rabbitmq_team_passwords/' ~ cluster_name ~ '/' ~ team_username ~ '/password', team_password) %} Both these methods fail with the following message:
Running the command from CLI still works: salt 'myminion' sdb.set 'sdb://myvault/salt/rabbitmq_team_passwords/<cluster_name>/<team_name>/password' '1234'
myminion:
True I think this might be related to the original issue, so I thought it would be worth to mention it. |
I think the issue is the same as #57561 The workaround to set
|
Even sdb.get does not work if the secret does not exist. In sdb/vault.py:92:
With the default of |
This commit represents a fundamental rewrite in how Salt interacts with Vault. The master should still be compatible with minions running the old code. There should be no breaking changes to public interfaces and the old configuration format should still apply. Core: - Issue AppRoles to minions - Manage entities with templatable metadata for minions - Use inbuilt Salt cache - Separate config cache from token cache - Cache: introduce connection-scope vs global scope Utility module: - Support being imported (__utils__ deprecation) - Raise exceptions on queries to simplify response handling - Add classes to wrap complexity, especially regarding KV v2 - Lay some groundwork for renewing tokens Execution module: - Add patch_secret - Add version support to delete_secret - Allow returning listed keys only in list_secret - Add policy_[fetch/write/delete] and policies_list - Add query for arbitrary API queries State module: - Make use of execution module - Change output format Docs: - Update for new configuration format - Correct examples - Add configuration examples - Add required policies Fixes: saltstack/salt#62552 saltstack/salt#59827 saltstack/salt#62380 saltstack/salt#58174 Probably fixes: saltstack/salt#60779 saltstack/salt#57561 Might fix: saltstack/salt#59846
Description
I tried using
sdb.get_or_set_hash
function with Vault as SDB backend. Whilesdb.get
andsdb.set
works flawlessly, I could not getsdb.get_or_set_hash
working, when creating a new secret.Here are the scenarios I tested:
salt 'myminion' sdb.set 'sdb://myvault/salt/test/password' 1234
salt 'myminion' sdb.get 'sdb://myvault/salt/test/password'
salt 'myminion' sdb.get_or_set_hash 'sdb://myvault/salt/test/password' 10
password
key was set intest
secret before. Returns the value forpassword
password
key was set intest
secret, and I am setting a new key namedpassword1
. Generates a new 10 digit string and replaces the{"password": 1234}
with{"password1": "some_random_string"}
test
secret was not created previously (under kv secret engine namedsalt
). Please note that the same thing (non-existing secret creation) works perfectly withsdb.set
, which this function calls internally.The error I see when using
sdb.get_or_set_hash
, creating a new secret is as follows:I added some print statements inside
sdb.py
andvault.py
to check if some argument is different between callingsdb.set
andsdb.get_or_set_hash
, and I could not see any difference.I tested with both v1 and v2 KV secrets. I also tried the old and new notation for separating the key ('?' vs '/').
Setup
Our set up is an on-prem VM infrastructure on VMware.
Steps to Reproduce the behavior
Expected behavior
sdb.get_or_set_hash
can create a secret assdb.set
does.Versions Report
(Master) salt --versions-report
(Minion) salt-minion --versions-report
The text was updated successfully, but these errors were encountered: