Using the create an entity API but using an existing name
without providing an id
does not throw an error. Instead, it is updated.
Running the following script will easily reproduce this (jq
is used for nice output):
#!/bin/bash
vault_token='<insert_token>'
echo "Create an entity that is unique"
curl -s \
--header "X-Vault-Token: $vault_token" \
--request POST \
--data '{ "name": "some_name", "metadata": {"meta": "data"} }' \
http://127.0.0.1:8200/v1/identity/entity | jq
echo -e "Done\n"
echo "Read the created entity"
curl -s \
--header "X-Vault-Token: $vault_token" \
http://127.0.0.1:8200/v1/identity/entity/name/some_name | jq
echo -e "Done\n"
echo "Create an entity but using an existing name"
curl -s \
--header "X-Vault-Token: $vault_token" \
--request POST \
--data '{ "name": "some_name", "metadata": {"uh": "oh"} }' \
http://127.0.0.1:8200/v1/identity/entity | jq
echo -e "Done\n"
echo "Read the entity to check if it was updated"
curl -s \
--header "X-Vault-Token: $vault_token" \
http://127.0.0.1:8200/v1/identity/entity/name/some_name | jq
echo -e "Done\n"
echo "Cleanup"
curl \
--header "X-Vault-Token: $vault_token" \
--request DELETE \
http://127.0.0.1:8200/v1/identity/entity/name/some_name
echo "Done"
This script results in following output (data may vary):
Create an entity that is unique
{
"request_id": "77ec0f9a-5d43-adc4-32a3-35562742ff48",
"lease_id": "",
"renewable": false,
"lease_duration": 0,
"data": {
"aliases": null,
"id": "2cc21b11-bcf7-f5a2-89c5-a92358e7e313",
"name": "some_name"
},
"wrap_info": null,
"warnings": null,
"auth": null
}
Done
Read the created entity
{
"request_id": "4364fe86-d309-8aba-ef38-6b0ceed9df84",
"lease_id": "",
"renewable": false,
"lease_duration": 0,
"data": {
"aliases": [],
"creation_time": "2023-03-22T19:13:38.155405615Z",
"direct_group_ids": [],
"disabled": false,
"group_ids": [],
"id": "2cc21b11-bcf7-f5a2-89c5-a92358e7e313",
"inherited_group_ids": [],
"last_update_time": "2023-03-22T19:13:38.155405615Z",
"merged_entity_ids": null,
"metadata": {
"meta": "data"
},
"name": "some_name",
"namespace_id": "root",
"policies": []
},
"wrap_info": null,
"warnings": null,
"auth": null
}
Done
Create an entity but using an existing name
Done
Read the entity to check if it was updated
{
"request_id": "9d505bb4-88b4-52e1-9852-3ea43f869da6",
"lease_id": "",
"renewable": false,
"lease_duration": 0,
"data": {
"aliases": [],
"creation_time": "2023-03-22T19:13:38.155405615Z",
"direct_group_ids": [],
"disabled": false,
"group_ids": [],
"id": "2cc21b11-bcf7-f5a2-89c5-a92358e7e313",
"inherited_group_ids": [],
"last_update_time": "2023-03-22T19:13:38.219235824Z",
"merged_entity_ids": null,
"metadata": {
"uh": "oh"
},
"name": "some_name",
"namespace_id": "root",
"policies": []
},
"wrap_info": null,
"warnings": null,
"auth": null
}
Done
Cleanup
Done
Note how no content was returned in the update request and the metadata field was updated from {"meta": "data"}
to {"uh": "oh"}
.