Hi,
I’m trying to use the embedded browser CLI to write to a KV v2 engine and I’m not sure if I’m doing it right, but it is not working. I simple started a dev server (version 1.6.3), logged in with root token and did the steps below:
1st attempt:
$ write secret/test foo=bar
Error writing to: secret/test.
URL: /v1/secret/test
Code: 404
Ok, KV v2 API states clearly that the URL to create secrets must contain “data” after the name of the secret engine.
2nd attempt:
$ write secret/data/test foo=bar
Error writing to: secret/data/test.
URL: /v1/secret/data/test
Code: 400
Errors:
no data provided
Now it’s odd. I have provided “foo=bar” as data.
3rd attempt
$ write secret/data/test data='{"foo":"bar"}'
Error writing to: secret/data/test.
URL: /v1/secret/data/test
Code: 400
Errors:
error converting input {"foo":"bar"} for field "data": '' expected a map, got 'string'
Hmm, so when I declare explicitly the field “data”, it recognizes it, but complains it’s not a map.
I tried a lot of different formats for the field “data” without success.
$ write secret/data/test data=foo:bar
$ write secret/data/test data=foo=bar
$ write secret/data/test data.foo=bar
$ write secret/data/test data[foo]=bar
$ write secret/data/test data["foo"]=bar
4th attempt (“hacking” into this thing)
So I decided open the hood and see how the UI was making the API requests, and eventually stumbled on this function:
write: function(e, t, n) {
return this.ajax("write", r(e), {
data: t,
wrapTTL: n
})
}
Debugging I could see that:
e = "secret/data/test", t = {foo: "bar"}, n = undefined
And as this variable “t” is being passed directly to ajax lib, without being enclosed in a object with “data” attribute, I decided to help with a little “hack”:
$ write secret/data/test foo=bar
Breakpoint at function above and run at developer tools’ console:
t = { data: t }
Key Value
created_time 2021-02-26T18:43:44.445292403Z
deletion_time
destroyed false
version 1
And it worked!
The questions
- Am I using it wrong or is it a bug?
- Where are the docs on those commands?
- Are they using the same syntax as CLI, but with fewer options?
Bonus
I thought that maybe this command is not prepared to work with KV v2 and decided to try it with KV v1. Created a secret engine KV v1 called “kv1” and it works perfectly. Maybe it was not evolved to work with KV v2 yet?
$ write kv1/test foo=bar
Success! Data written to: kv1/test
Thanks,