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

ApiKey action rules #2105

Closed
fpellet opened this issue Dec 12, 2024 · 4 comments
Closed

ApiKey action rules #2105

fpellet opened this issue Dec 12, 2024 · 4 comments

Comments

@fpellet
Copy link

fpellet commented Dec 12, 2024

Description

Allow to create a rule with an api ley

Steps to reproduce

Create a key:

{
  "description": "Admin key.",
  "actions": [
    "collections:*",
    "documents:*",
    "aliases:*",
    "synonyms:*",
    "overrides:*",
    "stopwords:*",
    "rules:*"
  ],
  "collections": [
    "*"
  ]
}

Expected Behavior

Can create rules

Actual Behavior

Unauthorized

Metadata

Typesense Version: 27.1

OS: Linux (docker)

@jasonbosco
Copy link
Member

Could you share a set of curl commands like this that replicates the issue with a minimal dataset?

@fpellet
Copy link
Author

fpellet commented Dec 15, 2024

Sure.

### Run Typesense via Docker ########################################
export TYPESENSE_API_KEY=xyz
    
mkdir "$(pwd)"/typesense-data

docker run -p 8108:8108 \
            -v"$(pwd)"/typesense-data:/data typesense/typesense:27.1 \
            --data-dir /data \
            --api-key=$TYPESENSE_API_KEY \
            --enable-cors

### Reproduction Steps ###############################################
export TYPESENSE_API_KEY=xyz
export HOST='http://localhost:8108'

curl "${HOST}/debug" \
       -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"

### create admin api key with all actions in documentation (+ rules to try)

curl "${HOST}/keys" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${ADMIN_API_KEY}" \
       -d '{"description":"Admin","actions":["collections:*","documents:*","aliases:*","synonyms:*","overrides:*","stopwords:*","rules:*"],"collections":["*"]}'

export ADMIN_API_KEY='new api key created'

curl "${HOST}/debug" \
       -H "X-TYPESENSE-API-KEY: ${ADMIN_API_KEY}"

curl "${HOST}/collections" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${ADMIN_API_KEY}" \
       -d '{
         "name": "companies",
         "fields": [
           {"name": "company_name", "type": "string" },
           {"name": "num_employees", "type": "int32" },
           {"name": "country", "type": "string", "facet": true }
         ],
         "default_sorting_field": "num_employees"
       }'

curl "${HOST}/collections" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${ADMIN_API_KEY}" \
       -d '{
         "name": "companies_stats",
         "fields": [
           {"name": "q", "type": "string" },
           {"name": "count", "type": "int32" }
         ],
         "default_sorting_field": "count"
       }'

curl "${HOST}/analytics/rules" \
       -X POST \
       -H "Content-Type: application/json" \
       -H "X-TYPESENSE-API-KEY: ${ADMIN_API_KEY}" \
       -d '{"name":"test","params":{"destination":{"collection":"collections_stats"},"limit":100,"source":{"collections":["companies"]}},"type":"popular_queries"}'

=> result: {"message": "Forbidden - a valid `x-typesense-api-key` header must be sent."}

Impossible to create rule without full authorization apikey

@jasonbosco
Copy link
Member

Instead of rules:*, could you try analytics/rules:* in the actions key when creating the API Key?

@fpellet
Copy link
Author

fpellet commented Dec 21, 2024

it's works. Thanks.
I saw that the documentation had been updated too.

@fpellet fpellet closed this as completed Dec 21, 2024
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

2 participants