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

No way to check if a secret path exists #381

Closed
grantdlr opened this issue Jan 17, 2019 · 8 comments
Closed

No way to check if a secret path exists #381

grantdlr opened this issue Jan 17, 2019 · 8 comments
Labels
kv Key/Value (KV) secrets engine

Comments

@grantdlr
Copy link

I need to programatically verify if a path exists before writing a secret to it. a simple read to check the path throws and exception "path doesn't exist"

@viralpoetry
Copy link
Contributor

@grantdlr what exactly are you trying to achieve? "Paths" does not exist in vault until you write something there, they are only defined with the ACLs / policies.
You can only check if some mount point is available, or what rights you have with token on some path (issue #335)

@jeffwecan
Copy link
Member

I'm with @viralpoetry on this issue. That said, would having an optional parameter (or something similar) on the implicated methods that would toggle returning None instead of raising an exception help solve your concern @grantdlr?

@jeffwecan jeffwecan added this to Needs triage in Bug / Feature Request Triage via automation Jan 18, 2019
@jeffwecan jeffwecan added waiting-reply waiting for more information (probably for a while) kv Key/Value (KV) secrets engine labels Jan 18, 2019
@grantdlr
Copy link
Author

@jeffwecan that would absolutely solve my concern. I've been able to get around this using a try catch block. was just looking for a nicer way to ensure that I'm not overwriting existing secrets.

@jeffwecan
Copy link
Member

I've had the same concern from time to time! I'll queue this issue up for the next release and see if we can get something sorted...

@jeffwecan
Copy link
Member

Oh and to be clear, is your particular use case tied to KV v1, v2, or just a general secrets engines concern?

@jeffwecan jeffwecan added this to the 0.7.3 milestone Jan 18, 2019
@grantdlr
Copy link
Author

its the same for KV1 and KV2 but currently using KV2

@jeffwecan jeffwecan removed the waiting-reply waiting for more information (probably for a while) label Jan 18, 2019
@jeffwecan jeffwecan moved this from Needs triage to Medium Priority in Bug / Feature Request Triage Jan 18, 2019
@jeffwecan jeffwecan modified the milestones: 0.8.0, 0.8.1 Mar 29, 2019
@jeffwecan jeffwecan modified the milestones: 0.9.0, 0.9.1, 0.9.2 May 23, 2019
@jeffwecan jeffwecan removed this from the 0.9.2 milestone Jun 8, 2019
@netson
Copy link

netson commented Aug 13, 2019

I'm with @viralpoetry on this issue. That said, would having an optional parameter (or something similar) on the implicated methods that would toggle returning None instead of raising an exception help solve your concern @grantdlr?

Wouldn't it be better to use a construct such as below instead? After this, you can either use patch() or create_or_update_secret() to update the secret. Creating the path is obviously not required and depends on your use case, but returning None instead of an exception may create confusion as to whether the value is None, or the value doesn't exist.

# see if the path exists
try:
    data = client.secrets.kv.v2.read_secret_version(
        path='your/path/here',
    )

# if not, it will throw an exception
except hvac.exceptions.InvalidPath:
    client.secrets.kv.v2.create_or_update_secret(
        path='your/path/here',
        secret=dict(pssst=None),
    )
    pass

@briantist
Copy link
Contributor

I have to agree that this is a bit outside the library's control. Vault returns a 404, and so that is the exception we raise. We recently made a change to optionally not raise an exception for a specific type of 404 (see also: #955) but that is a different case since that 404 returns useful data with it.

404 is an appropriate response for a path that doesn't exist. I recommend using the try/catch method above.

@briantist briantist closed this as not planned Won't fix, can't repro, duplicate, stale Sep 17, 2023
Bug / Feature Request Triage automation moved this from Medium Priority to Closed Sep 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kv Key/Value (KV) secrets engine
Projects
Development

No branches or pull requests

5 participants