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

Make sure vault.unseal runner is unauthenticated #86

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

voyvodov
Copy link
Contributor

@voyvodov voyvodov commented Sep 4, 2024

What does this PR do?

vault.unseal runner will now use unauthenticated query to unseal Vault

What issues does this PR fix or reference?

Fixes: 85

Previous Behavior

vault.unseal runner was trying to authenticate with Vault before unseal it.

New Behavior

vault.unseal runner will not do any authentication with Vault.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

vault.unseal runner will now use unauthenticated query to unseal Vault
@voyvodov voyvodov changed the title Make vault.unseal runner is unauthenticated Make sure vault.unseal runner is unauthenticated Sep 12, 2024
Comment on lines 550 to 553
for key in __opts__["vault"]["keys"]:
ret = vault.query("POST", "sys/unseal", __opts__, __context__, payload={"key": key})
ret = vault.query(
"POST", "sys/unseal", __opts__, __context__, is_unauthd=True, payload={"key": key}
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting bug + fix and sorry for taking a while!

Have you verified this actually fixes the behavior? Afair is_unauthd only influences whether a token use is deducted (internal statistics).

I think in the code's current state you might need to create the unauthenticated client yourself (since it's a runner function we can just rely on the opts directly):

from saltext.vault.utils import factory
from saltext.vault.utils.client import VaultClient
# ...

def unseal():
    config = factory.parse_config(__opts__.get("vault", {}))
    client = VaultClient(**config["server"], **config["client"])
    for key in __opts__["vault"]["keys"]:
        ret = client.post("sys/unseal", payload={"key": key})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right :( .
I was expecting that unauth is really unauth. Probably that will be good to be fixed.

Using your solution for now (will prepare another one where unauth is really unauth)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think making vault.query with is_unauthd=True do an unauthenticated request is the correct layer to fix this behavior. The parameter is passed through to the authenticated client and is an ugly workaround intended to avoid unnecessary token reissuance when calling arbitrary endpoints - afair the token is still optionally used for auditing purposes.*

I would prefer introducing a separate vault.query_noauth helper function essentially doing the same as above (for locally sourced configuration).

* A more theoretical concern that's specific to the sealed state is that it would only work as expected when sourcing the parameters from local configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait...what? I was thinking that I pushed the change (using the client directly).
Will do it in a few minutes 🤦🏻‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Now it uses directly the client (so no tokens, authentication are used). Pretty much raw call (as it should be)

@lkubb lkubb self-assigned this Sep 13, 2024
@lkubb lkubb linked an issue Oct 2, 2024 that may be closed by this pull request
9 tasks
Copy link
Member

@lkubb lkubb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

We could consider extracting the unauthenticated query part into a dedicated helper function in the future, but for now it's fine like that.

@lkubb lkubb merged commit fa84494 into salt-extensions:main Oct 2, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Salt is trying to authenticate during unseal op
2 participants