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

Requests to vault via YARP reverse proxy #204

Open
grsw92 opened this issue Oct 2, 2024 · 0 comments
Open

Requests to vault via YARP reverse proxy #204

grsw92 opened this issue Oct 2, 2024 · 0 comments

Comments

@grsw92
Copy link

grsw92 commented Oct 2, 2024

Hi, I'm using vault client in a setup where my code fills up secrets in the vault which resides behind reverse proxy (YARP). In this setup I observed unexpected behavior when writing secrets under paths containing / . i.e. my/custom/path. In this scenario the secrets get incorrectly written into my%2fcustom%2fpath which I don't think is even a valid path (at least vault ui gets confused when you click on such item).

I did some investigation on my end and I was able to get into the root cause of it, which is a coefficient of two things:

  1. Vault C# Client encodes secret paths in the POST request URL (it's done here: https://github.com/hashicorp/vault-client-dotnet/blob/main/src/Vault/Client/ApiClient.cs#L372). This produces requests like this: /v1/2c78501d-73c5-4844-908e-408d3a6440c6/data/my%2fcustom%2fpath which does not seem to be an issue on its own because vault seems to handle requests like this correctly.
  2. YARP proxy has a known issue and does not properly recognize %2f and because of this it gets double encoded while rewriting request to the host (it's reported here: Double percent encoding of forward slashes (%2F) in paths dotnet/yarp#1419)

I'm aware it's not particularly issue with the vault client itself, but this might have some significant impact on the client library users since you don't always know what proxies exist in between the client and the vault server.

This leads me to the questions:

  1. Is this encoding on the client side required? I did some tests and it seems the vault handles not-encoded paths as well as encoded. i.e. both of these requests to vault work just fine:
/v1/2c78501d-73c5-4844-908e-408d3a6440c6/data/my%2fcustom%2fpath
/v1/2c78501d-73c5-4844-908e-408d3a6440c6/data/my/custom/path
  1. Do you think it would be worth to have it configurable for the client library user (whether encoding is enabled or not)?
  2. What would be your recommendation to get it working in my case? (just for the record, changing reverse proxy is not an option)

I developed a workaround of supplying custom HttpClientHandler into the VaultConfiguration which decodes the path in the URL before sending request, but I'm not sure how safe it is. Could you give me some advice on this as well?

Additional context

This is how it looks in the vault UI
image

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

No branches or pull requests

1 participant