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

Key names cannot include // or start with / and this is not documented #3476

Closed
tjim opened this issue Sep 18, 2017 · 6 comments
Closed

Key names cannot include // or start with / and this is not documented #3476

tjim opened this issue Sep 18, 2017 · 6 comments
Labels
theme/api Relating to the HTTP API interface
Milestone

Comments

@tjim
Copy link

tjim commented Sep 18, 2017

consul version for both Client and Server

Client: Consul v0.9.2
Server: Consul v0.9.2

Description of the Issue (and unexpected/desired result)

I wanted to use a key name that is a base64 encoded value. These can start with slash (/) and can contain double slash (//).

Turns out this fails. I don't see any discussion of the accepted syntax of key names in the documentation. Moreover the error message is cryptic.

I understand looking through other issues that this may be related to use of net/http.

Can this at least be documented?

Reproduction steps

$ consul kv put foo//bar bar
Error! Failed writing data: Unexpected response code: 404 ()
@tjim
Copy link
Author

tjim commented Sep 20, 2017

So for anyone with the same problem, I have a workaround: use the golang library function net/url.PathEscape(s) to translate your key name s to a key name that will work with consul.

You will also need to use net/url.PathUnescape(k) to convert a key name from consul into your own key name space.

This is not a good situation. It's hard to document the current syntax of key names in consul. A technical detail of consul's implementation is bleeding through here. Namely, consul uses key names in URL paths, and moreover uses golang net/http to process these. The net/http library appears to put more restrictions on URL paths than does RFC 3986.

So I guess that the documentation is that you can use any string s such that s == url.PathEscape(s) ??

@simar7
Copy link

simar7 commented Dec 6, 2017

I was able to reproduce this as well. Here's a simple test case:

root@ubuntu:/home/ubuntu# consul kv put service/name/test//foo/baz bar
Error! Failed writing data: Unexpected response code: 404 ()
root@ubuntu:/home/ubuntu# consul kv put service/name/test/foo/baz bar
Success! Data written to: service/name/test/foo/baz

In addition to this I noticed that the GET method returns the same value, double '/' or not.

root@ubuntu:/home/ubuntu# consul kv get service/name/test//foo/baz
bar
root@ubuntu:/home/ubuntu# consul kv get service/name/test/foo/baz
bar

Is this expected behavior? Seems like it might be better if it was at least consistent across various methods.

@slackpad
Copy link
Contributor

slackpad commented Jan 4, 2018

Part of this is Go's behavior as seen in hashicorp/nomad#3620, but we need to make the key format clear. Also, the https://www.consul.io/api/txn.html API takes key names outside of URLs so might make keys that can't be accessed by the URL-based API.

@slackpad slackpad added the theme/api Relating to the HTTP API interface label Jan 4, 2018
@slackpad slackpad added this to the Unplanned milestone Jan 4, 2018
@stale
Copy link

stale bot commented Oct 21, 2019

Hey there,
We wanted to check in on this request since it has been inactive for at least 60 days.
If you think this is still an important issue in the latest version of Consul
or its documentation please reply with a comment here which will cause it to stay open for investigation.
If there is still no activity on this issue for 30 more days, we will go ahead and close it.

Feel free to check out the community forum as well!
Thank you!

@stale stale bot added the waiting-reply Waiting on response from Original Poster or another individual in the thread label Oct 21, 2019
@stale
Copy link

stale bot commented Nov 20, 2019

Hey there, This issue has been automatically closed because there hasn't been any activity for at least 90 days. If you are still experiencing problems, or still have questions, feel free to open a new one 👍

@stale stale bot closed this as completed Nov 20, 2019
@ghost
Copy link

ghost commented Jan 25, 2020

Hey there,

This issue has been automatically locked because it is closed and there hasn't been any activity for at least 30 days.

If you are still experiencing problems, or still have questions, feel free to open a new one 👍.

@ghost ghost locked and limited conversation to collaborators Jan 25, 2020
@ghost ghost removed the waiting-reply Waiting on response from Original Poster or another individual in the thread label Jan 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
theme/api Relating to the HTTP API interface
Projects
None yet
Development

No branches or pull requests

3 participants