How share stream using rest api

Guys,
I need to share stream on graylog with multiple users. I want to use rest API for that.
The users already exist in my graylog, the problem is only associate the user with the stream.

Learning the API-Browser, I didn’t find how to work that

I followed the step:

  1. Create the permission for user
    API /users
    JSON
    '{"permissions": [ "streams:read:602ad48eec1ab24c865cd285"]}'

  2. share permission on entities
    API /authz/shares/entities/{entityGRN}
    entityGRN = grn::::stream:602afd2296ca933d41b20709
    JSON
    '{ "selected_grantee_capabilities": { "grn::::stream:602afd2296ca933d41b20709": view"}}'

after, when I check the API /authz/shares/user/{userId}, to see the entities permission. And nothing work. look

  "context": {
    "grantee_capabilities": {}
  }

But, when I try again the entities permission, I receive this message:

{
  "type": "ApiError",
  "message": "Write failed with error code 11000 and error message 'E11000 duplicate key error collection: graylog.grants index: grantee_1_capability_1_target_1 dup key: { grantee: \"grn::::stream:602afd2296ca933d41b20709\", capability: \"view\", target: \"grn::::stream:602afd2296ca933d41b20709\" }'"
}

The entities permission somehow work, but no show me.

I want only share stream with users using rest API.
Somebody can help-me?

tks

Your example is wrong, it can’t work because:

  1. Your first step is not necessary. Required step is to only assign permission to stream for user, your step two
  2. You use wrong parameter in step two. You use ID of stream and not ID user. Correct format for JSON:
    {"selected_grantee_capabilities":{"grn::::user:USER_ID":"view"}}
  • USER_ID should be ID of user, and not stream ID.

Complete example using curl:
curl 'http://172.28.128.15/api/authz/shares/entities/grn::::stream:STREAM_ID' -H 'Accept: application/json' -H 'Authorization: Basic BASE64' -H 'Content-Type: application/json' --data-raw '{"selected_grantee_capabilities":{"grn::::user:USER_ID":"view"}}'

  • Use your selected authentication for API: user name, password, token or session token.

If you want to share stream with multiple user you need to specify all users in API:
{"selected_grantee_capabilities":{"grn::::user:USER1_ID":"view","grn::::user:USER2_ID":"view"}}

2 Likes

If you want to only add new user, you can use API /api/authz/shares/entities/grn::::stream:STREAM_ID/prepare with request {} and use it to return already assigned permissions for other users. Then use it as input, concatenate with new NEW_USER_ID using jq:

curl -s 'http://172.28.128.15/api/authz/shares/entities/grn::::stream:STREAM_D/prepare' -H 'Accept: application/json' -H 'Authorization: Basic BASE64' -H 'Content-Type: application/json' --data-raw '{}' | jq --arg user_id NEW_USER_ID '{selected_grantee_capabilities}|. * {"selected_grantee_capabilities": {("grn::::user:" + $user_id): "view"}}'

Then you can use as input for previous api /api/authz/shares/entities/grn::::stream:STREAM_ID

\o/
Now it’s works. Thank you very much!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.