Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Security Context empty when using Python config #8416

Open
sabinevidal opened this issue Jul 2, 2024 · 0 comments
Open

Security Context empty when using Python config #8416

sabinevidal opened this issue Jul 2, 2024 · 0 comments

Comments

@sabinevidal
Copy link

sabinevidal commented Jul 2, 2024

Describe the bug
When using Cube Cloud, and sending additional information in the Cube Token via the API, the Security Context in driver_factory is empty. This was working in Javascript. We need to pass additional dynamic data in order to set up multitenancy and would prefer to use the Python implementation.
Edit: this does work in Dev Mode

To Reproduce

  1. Create an encoded JWT with the following in the payload, and set the secret to your configured CUBE_API_SECRET
{
  "iat": 1719909131,
  "user_id": 28
}
  1. Create the following Cube.py
from cube import config

@config('driver_factory')
def driver_factory(ctx: dict) -> None:
    try:
        print(ctx)
        user = default_userId
        warehouse = default_warehouse
        account = default_account
        database = default_database

        if not user or not warehouse:
            raise ValueError("Missing userId or warehouse in securityContext")

        return {
            'type': 'snowflake',
            'user': user,
            'private_key': private_key_content,
            'database': database,
            'warehouse': warehouse
        }
    except Exception as e:
        print(f"Error in driver_factory: {e}")
        return None
  1. Run a curl request with the created JWT and your REST API url.

Expected behavior
Printing ctx in the logs shows "securityContext":{"iat":1719909131,"user_id":28}

Results
From logs

{"message":"REST API Request","path":"/cubejs-api/v1/load?query={omitted}","method":"GET","status":200,"ip":"::ffff:1234567","time":"2024-07-02T11111Z","securityContext":{"iat":1719909131,"user_id":28},"requestId":"12345-span-1"}
{'requestId': 'scheduler-54321', 'dataSource': 'default', 'securityContext': {}, 'authInfo': None}

Version:
[e.g. 0.35.55]

Additional context
Possibly related to
#8133

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

1 participant