microsoft / jupyter-Kqlmagic

Extension (Magic) to Jupyter notebook and Jupyter lab, that enable notebook experience working with Kusto, ApplicationInsights, and LogAnalytics data.
Other
85 stars 31 forks source link

Cannot login with personal account (non school or work account) #96

Closed sqlworldwide closed 5 months ago

sqlworldwide commented 1 year ago

Code Sample, a copy-pastable example if possible

# Initialize workspace ID to connect to, to analyze Azure SQL log data
workspaceID = 'f0d9184f-c15a-4511-a634-3b58927bda47'

if (workspaceID == ''):
    workspaceID = input("Enter Log Analytics Workspace ID (guid)")
    #print(workspaceID)
    print("workspaceID is set") 

%kql loganalytics://code;workspace=workspaceID;alias="sqlpassws" -try-azcli-login-by-profile

Problem description

Once I execute the above code, I get a code "FXNLBDXSU Copy code to clipboard and authenticate". I cannot authenticate using my portal account (which is not a school or work account). I get an error:

ZUQCwTz0

Output of pip freeze and %kql --bugreport

[bugreport must be executed immediatly after bug noticed]

adal==1.2.7 applicationinsights==0.11.10 argcomplete==1.12.3 argon2-cffi==20.1.0 async-generator==1.10 attrs==21.2.0 azure-cli-core==2.26.0 azure-cli-telemetry==1.0.6 azure-common==1.1.27 azure-core==1.16.0 azure-identity==1.6.1 azure-mgmt-core==1.2.2 backcall==0.2.0 bcrypt==3.2.0 beautifulsoup4==4.9.3 bleach==3.3.0 certifi==2021.5.30 cffi==1.14.6 chardet==4.0.0 click==8.0.1 colorama==0.4.4 cryptography==3.3.2 cycler==0.10.0 debugpy==1.3.0 decorator==5.0.9 defusedxml==0.7.1 entrypoints==0.3 Flask==2.0.1 humanfriendly==9.2 idna==2.10 ipykernel==6.0.1 ipython==7.25.0 ipython-genutils==0.2.0 ipywidgets==7.6.3 isodate==0.6.0 itsdangerous==2.0.1 jedi==0.18.0 Jinja2==3.0.1 jmespath==0.10.0 jsonschema==3.2.0 jupyter==1.0.0 jupyter-client==6.1.12 jupyter-console==6.4.0 jupyter-core==4.7.1 jupyterlab-pygments==0.1.2 jupyterlab-widgets==1.0.0 kiwisolver==1.3.1 knack==0.8.2 Kqlmagic==0.1.114.post22 lxml==4.6.3 Markdown==3.3.4 MarkupSafe==2.0.1 matplotlib==3.4.2 matplotlib-inline==0.1.2 mistune==0.8.4 msal==1.12.0 msal-extensions==0.3.0 msrest==0.6.21 msrestazure==0.6.4 nbclient==0.5.3 nbconvert==6.1.0 nbformat==5.1.3 nest-asyncio==1.5.1 notebook==6.4.0 numpy==1.21.0 Note: you may need to restart the kernel to use updated packages.oauthlib==3.1.1 packaging==21.0 pandas==1.3.0 pandocfilters==1.4.3 paramiko==2.7.2 parso==0.8.2 password-strength==0.0.3.post2 pickleshare==0.7.5 Pillow==8.3.1 pkginfo==1.7.1 plotly==5.1.0 portalocker==1.7.1 powershell-kernel==0.1.4 prettytable==2.1.0 prometheus-client==0.11.0 prompt-toolkit==3.0.19 psutil==5.8.0 pycparser==2.20 Pygments==2.9.0 PyJWT==2.1.0 PyNaCl==1.4.0 pyOpenSSL==20.0.1 pyparsing==2.4.7 pyperclip==1.8.2 pyreadline==2.1 pyrsistent==0.18.0 python-dateutil==2.8.1 pytz==2021.1 pywin32==301 pywinpty==1.1.3 PyYAML==5.4.1 pyzmq==22.1.0 qtconsole==5.1.1 QtPy==1.9.0 requests==2.25.1 requests-oauthlib==1.3.0 scipy==1.7.0 seaborn==0.11.1 Send2Trash==1.7.1 six==1.16.0 soupsieve==2.2.1 tabulate==0.8.9 tenacity==8.0.1 terminado==0.10.1 testpath==0.5.0 tornado==6.1 traitlets==5.0.5 urllib3==1.26.6 wcwidth==0.2.5 webencodings==0.5.1 Werkzeug==2.0.1 widgetsnbextension==3.5.1 { "Kqlmagic_last_execution": { "args": { "cell": null, "line": "loganalytics://code;workspace=workspaceID;alias=\"sqlpassws\" -try-azcli-login-by-profile", "override_connection": null, "override_options": null, "override_query_properties": null, "override_result_set": null, "override_vars": null }, "connection": "sqlpassws@loganalytics", "log": [ "Kqlmagic_core::execute - input: \n\rline: loganalytics://code;workspace=workspaceID;alias=\"sqlpassws\" -try-azcli-login-by-profile\n\rcell:\n\rNone", "Kqlmagic_core::execute - parsed_queries: [{'connection_string': 'loganalytics://code;workspace=workspaceID;alias=\"sqlpassws\"', 'query': '', 'options': {'auto_dataframe': False, 'short_errors': True, 'feedback': True, 'show_conn_info': 'current', 'columns_to_local_vars': False, 'show_query_time': True, 'show_query': False, 'show_query_link': False, 'query_link_destination': 'Kusto.WebExplorer', 'enable_suppress_result': True, 'plotly_fs_includejs': False, 'popup_window': False, 'auto_limit': 0, 'display_limit': None, 'timeout': None, 'prettytable_style': 'DEFAULT', 'last_raw_result_var': '_kql_raw_result_', 'table_package': 'prettytable', 'plot_package': 'plotly', 'dsn_filename': 'odbc.ini', 'validate_connection_string': True, 'auto_popup_schema': True, 'json_display': 'formatted', 'schema_json_display': 'auto', 'palette_desaturation': 1.0, 'params_dict': None, 'palette_name': 'tab10', 'cache': None, 'use_cache': None, 'temp_folder_name': 'temp_files', 'cache_folder_name': 'cache_files', 'export_folder_name': 'exported_files', 'add_kql_ref_to_help': True, 'add_schema_to_help': True, 'enable_add_items_to_help': True, 'notebook_app': 'visualstudiocode', 'debug': False, 'check_magic_version': True, 'show_what_new': True, 'show_init_banner': True, 'is_kernel_intializtion': False, 'warn_missing_dependencies': True, 'warn_missing_env_variables': True, 'allow_single_line_cell': True, 'allow_py_comments_before_cell': True, 'kqlmagic_kernel': False, 'extras_require': 'default', 'test_notebook_app': 'none', 'cloud': 'public', 'enable_sso': False, 'sso_db_gc_interval': 168, 'auth_use_http_client': False, 'try_azcli_login': False, 'try_azcli_login_by_profile': True, 'try_vscode_login': False, 'try_azcli_login_subscription': None, 'try_token': None, 'try_msi': None, 'request_id_tag': None, 'request_app_tag': None, 'request_user_tag': None, 'request_user_agent_tag': None, 'request_cache_max_age': 0, 'device_code_login_notification': 'auto', 'device_code_notification_email': '', 'save_as': None, 'save_to': None, 'query_properties': {}, 'palette_colors': 10, 'palette_reverse': False, 'popup_schema': False, 'display_id': False, 'display_handlers': {'acquire_token': None}, 'popup_interaction': 'auto', 'temp_files_server': 'auto', 'temp_files_server_address': 'http://127.0.0.1:61125', 'kernel_location': 'local', 'kernel_id': '5d2484ae-db67-4efe-8902-782c318930e2', 'notebook_service_address': None, 'dynamic_to_dataframe': 'object', 'temp_folder_location': 'user_dir', 'plotly_layout': None, 'auth_token_warnings': False, 'enable_curly_brackets_params': False, 'nop': False, 'assign_var': None, 'cursor_var': None, 'is_magic': True, 'code_auth_interactive_mode': 'device_code'}, 'command': {}, 'last_query': True}]", "kql_engine.py -_parse_common_connection_str - params: conn_str: loganalytics://code;workspace=workspaceID;alias=\"sqlpassws\"; current: , uri_schema_name: loganalytics;mandatory_key: workspace, valid_keys_combinations: [['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'clientid', 'clientsecret'], ['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'clientid', 'code'], ['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'code'], ['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'clientid', 'username', 'password'], ['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'username', 'password'], ['workspace', 'alias', 'datasourceurl', 'anonymous'], ['workspace', 'alias', 'datasourceurl', 'appkey']]", "kql_engine.py - _parse_connection_str - params: conn_str: loganalytics://code;workspace=workspaceID;alias=\"sqlpassws\"", "kql_engine.py - _parse_connection_str - parsed_conn_kv: {'code': '', 'workspace': 'f0d9184f-c15a-4511-a634-3b58927bda47', 'alias': 'sqlpassws'} (return of Parser.parse_and_get_kv_string)", "kql_engine.py -_parse_common_connection_str - matched_keys_set: {'alias', 'workspace', 'code'}", "kql_engine.py - _find_combination - found these valid_combinations: [['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'clientid', 'code'], ['workspace', 'alias', 'datasourceurl', 'tenant', 'aadurl', 'code']]", "kql_engine.py - _find_combination - chose current combination_keys_list is: {'alias', 'workspace', 'aadurl', 'datasourceurl', 'tenant', 'code'}", "kql_engine.py - _inherit_keys - add inherited to combination_keys_set and now inherit_keys_set: {'aadurl', 'datasourceurl', 'tenant'}", "kql_engine.py - _check_for_restricted_values - make sure that all required keys are with proper value: {'alias', 'workspace', 'code'}", "kql_engine.py -_set_and_check_for_cluster_name - setting attributes - cluster_name: loganalytics", "kql_engine.py -_set_and_check_for_cluster_name - setting attributes - cluster_friendly_name: loganalytics", "kql_engine.py - _set_and_check_for_database_name - setting attributes - database_name: f0d9184f-c15a-4511-a634-3b58927bda47", "kql_engine.py - _set_and_check_for_database_name - setting attributes - database_friendly_name: f0d9184f-c15a-4511-a634-3b58927bda47", "kql_engine.py - _set_and_check_for_alias - setting attributes - alias: sqlpassws", "kql_engine.py - _create_and_set_bind_url - setting attributes - bind_url:loganalytics://workspace('f0d9184f-c15a-4511-a634-3b58927bda47').aadurl('None').datasourceurl('None').tenant('None').code('')", "draft_client.py :: __init__ : conn_kv[\"datasourceurl\"]: None", "draft_client.py :: __init__ : self._appkey: None", "draft_client.py :: __init__ : self._aad_helper: ;", "_MyAadHelper::_get_azcli_token_by_profile failed to get token - subscription: 'None', tenant: 'common'", "No suitable token exists in cache. Let's get a new one from AAD." ] }, "kqlmagic": { "version": "0.1.114.post22" }, "kqlmagic_connections:": { "sqlpassws@loganalytics": { "auth": { "aad_login_url": "https://login.microsoftonline.com", "authentication_method": "aad_code_login", "authority_uri": "https://login.microsoftonline.com/common", "client_app_type": "public", "client_id": "db662dc1-0cfe-4e1c-a843-19a68e65be58", "scopes": [ "https://api.loganalytics.io/.default" ], "username": null }, "cluster_name": "loganalytics", "database_name": "f0d9184f-c15a-4511-a634-3b58927bda47", "parsed_conn": { "alias": "sqlpassws", "code": "", "workspace": "f0d9184f-c15a-4511-a634-3b58927bda47" } } }, "kqlmagic_default_env": {}, "kqlmagic_default_options": { "add_kql_ref_to_help": true, "add_schema_to_help": true, "allow_py_comments_before_cell": true, "allow_single_line_cell": true, "assign_var": null, "auth_token_warnings": false, "auth_use_http_client": false, "auto_dataframe": false, "auto_limit": 0, "auto_popup_schema": true, "cache": null, "cache_folder_name": "cache_files", "check_magic_version": true, "cloud": "public", "code_auth_interactive_mode": "device_code", "columns_to_local_vars": false, "cursor_var": null, "debug": false, "device_code_login_notification": "auto", "device_code_notification_email": "", "display_limit": null, "dsn_filename": "odbc.ini", "dynamic_to_dataframe": "object", "enable_add_items_to_help": true, "enable_curly_brackets_params": false, "enable_sso": false, "enable_suppress_result": true, "export_folder_name": "exported_files", "extras_require": "default", "feedback": true, "is_kernel_intializtion": false, "is_magic": true, "json_display": "formatted", "kernel_id": "5d2484ae-db67-4efe-8902-782c318930e2", "kernel_location": "local", "kqlmagic_kernel": false, "last_raw_result_var": "_kql_raw_result_", "notebook_app": "visualstudiocode", "notebook_service_address": null, "palette_colors": 10, "palette_desaturation": 1.0, "palette_name": "tab10", "plot_package": "plotly", "plotly_config": null, "plotly_fs_includejs": false, "plotly_layout": null, "popup_interaction": "auto", "prettytable_style": "DEFAULT", "query_link_destination": "Kusto.WebExplorer", "request_app_tag": null, "request_cache_max_age": 0, "request_id_tag": null, "request_user_agent_tag": null, "request_user_tag": null, "schema_json_display": "auto", "short_errors": true, "show_conn_info": "current", "show_init_banner": true, "show_query": false, "show_query_link": false, "show_query_time": true, "show_what_new": true, "sso_db_gc_interval": 168, "table_package": "prettytable", "temp_files_server": "auto", "temp_files_server_address": "http://127.0.0.1:61125", "temp_folder_location": "user_dir", "temp_folder_name": "temp_files", "test_notebook_app": "none", "timeout": null, "try_azcli_login": false, "try_azcli_login_by_profile": false, "try_azcli_login_subscription": null, "try_kqlmaic_sso": false, "try_msi": null, "try_token": null, "try_vscode_login": false, "use_cache": null, "validate_connection_string": true, "warn_missing_dependencies": true, "warn_missing_env_variables": true }, "packages": { "azure-common": "1.1.27", "azure-identity": "1.6.1", "beautifulsoup4": "4.9.3", "cryptography": "3.3.2", "flask": "2.0.1", "ipykernel": "6.0.1", "ipython": "7.25.0", "ipywidgets": "7.6.3", "isodate": "0.6.0", "lxml": "4.6.3", "markdown": "3.3.4", "matplotlib": "3.4.2", "msal": "1.12.0", "msal_extensions": "0.3.0", "msrestazure": "0.6.4", "pandas": "1.3.0", "password_strength": "0.0.3.post2", "plotly": "5.1.0", "prettytable": "2.1.0", "psutil": "5.8.0", "pygments": "2.9.0", "pyperclip": "1.8.2", "python-dateutil": "2.8.1", "requests": "2.25.1", "setuptools": "56.0.0", "traitlets": "5.0.5" }, "platform": { "release": "10", "system": "Windows" }, "python": { "branch": "tags/v3.8.10", "name": "CPython", "version": "3.8.10" } } OSError: [Errno 22] Invalid argument: 'C:\\Users\\taiob\\.kqlmagic\\temp_files\\5d2484ae-db67-4efe-8902-782c318930e2\\popup_newtitleKqlmagic20bug20report20236c50a122-6abd-44ae-b5e9-6734b5c1f84dbodyPlease20copy20the20bug20report20from20the20notebook20and20paste20it20to20the20template20below200A0ABEFORE20YOU20SUBMIT20IT2C20MAKE20SURE20
sqlworldwide commented 1 year ago

Is there an update on this issue? Error message changed. Now I see this why trying to run the same command.

KqlError: {"error":{"message":"The provided authentication is not valid for this resource","code":"InvalidTokenError","correlationId":"5bfd7f47-56a0-408e-9559-b4493f87323e","innererror":{"code":"InvalidAuthenticationTokenTenant","message":"The access token is from the wrong issuer 'https://sts.windows.net/dfb41db2-24dd-436a-acd1-0b12ee3de452/'. It must match the tenant 'https://sts.windows.net/d5b50601-6698-4f8f-beb6-1799fee4dc80/' associated with this subscription. Please use the authority (URL) 'https://login.windows.net/d5b50601-6698-4f8f-beb6-1799fee4dc80' to get the token. Note, if the subscription is transferred to another tenant there is no impact to the services, but information about new tenant could take time to propagate (up to an hour). If you just transferred your subscription and see this error message, please try back later."}}}

mbnshtck commented 5 months ago

should work

sqlworldwide commented 5 months ago

Thank you, will test.

sqlworldwide commented 4 months ago

It still only works if it is a work or school account and not a personal account. You can check the backend.

%kql loganalytics://workspace='d42a9746-53c0-42f7-b3c4-db3dd8966d3d';alias="kustodemows" -try-azcli-login-by-profile