snowflakedb / snowflake-sqlalchemy

Snowflake SQLAlchemy
https://pypi.python.org/pypi/snowflake-sqlalchemy/
Apache License 2.0
234 stars 152 forks source link

SNOW-1478600: MFA Authenticator Parameter Not Caching Token #504

Closed jordantshaw closed 5 months ago

jordantshaw commented 5 months ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of Python are you using?

    Python 3.11.7 (main, Feb 1 2024, 14:44:16) [Clang 15.0.0 (clang-1500.1.0.2.5)]

  2. What operating system and processor architecture are you using?

    macOS-14.5-arm64-arm-64bit

  3. What are the component versions in the environment (pip freeze)?

    
    annotated-types==0.7.0
    anyio==4.4.0
    asn1crypto==1.5.1
    Babel==2.15.0
    build==1.0.3
    certifi==2024.6.2
    cffi==1.16.0
    cfgv==3.4.0
    charset-normalizer==3.3.2
    click==8.1.7
    colorama==0.4.6
    cryptography==42.0.8
    distlib==0.3.8
    dnspython==2.6.1
    ecdsa==0.19.0
    email_validator==2.1.1
    fastapi==0.111.0
    fastapi-cli==0.0.4
    filelock==3.14.0
    ghp-import==2.1.0
    h11==0.14.0
    httpcore==1.0.5
    httptools==0.6.1
    httpx==0.27.0
    identify==2.5.36
    idna==3.7
    iniconfig==2.0.0
    Jinja2==3.1.4
    Markdown==3.6
    markdown-it-py==3.0.0
    MarkupSafe==2.1.5
    mdurl==0.1.2
    mergedeep==1.3.4
    mkdocs==1.5.3
    mkdocs-material==9.5.13
    mkdocs-material-extensions==1.3.1
    nodeenv==1.9.1
    orjson==3.10.4
    packaging==24.1
    paginate==0.5.6
    pathspec==0.12.1
    pip-tools==7.4.1
    platformdirs==4.2.2
    pluggy==1.5.0
    pre-commit==3.7.1
    pyasn1==0.6.0
    pycparser==2.22
    pydantic==2.7.3
    pydantic-config==0.3.0
    pydantic-settings==2.3.2
    pydantic_core==2.18.4
    Pygments==2.18.0
    PyJWT==2.8.0
    pymdown-extensions==10.8.1
    pyodbc==5.1.0
    pyOpenSSL==24.1.0
    pyproject_hooks==1.0.0
    pytest==8.0.2
    python-dateutil==2.9.0.post0
    python-dotenv==1.0.1
    python-jose==3.3.0
    python-json-logger==2.0.7
    python-multipart==0.0.9
    pytz==2024.1
    PyYAML==6.0.1
    pyyaml_env_tag==0.1
    regex==2024.5.15
    requests==2.32.3
    rich==13.7.1
    rsa==4.9
    ruff==0.2.2
    shellingham==1.5.4
    six==1.16.0
    sniffio==1.3.1
    snowflake-connector-python==3.10.1
    snowflake-sqlalchemy==1.5.3
    sortedcontainers==2.4.0
    SQLAlchemy==1.4.52
    starlette==0.37.2
    tomli==2.0.1
    tomlkit==0.12.5
    typer==0.12.3
    typing_extensions==4.12.2
    ujson==5.10.0
    urllib3==2.2.1
    uvicorn==0.27.1
    uvloop==0.19.0
    virtualenv==20.26.2
    watchdog==4.0.1
    watchfiles==0.22.0
    websockets==12.0

4. What did you do?

from sqlalchemy import create_engine from snowflake.sqlalchemy import URL

from app import settings

url = URL( account='abc123', user='testuser1', password='0123456', database='testdb', schema='public', warehouse='testwh', role='myrole', authenticator='username_password_mfa' )

engine = create_engine( url=url, future=True, echo=True, )



5. What did you expect to see?

When using the `username_password_mfa` option the client should be caching the mfa token and should only need to re-authenticate every 4 hours. Currently, anytime I restart my sqlalchmey app, I am recieving a duo push notification to re-authenticate.  If I check in my keychain access there are no keys being stored.

I have enabled the [ALLOW_CLIENT_MFA_CACHING](https://docs.snowflake.com/en/sql-reference/parameters.html#label-allow-client-mfa-caching) option in snowflake. I have also succesfully been able to use MFA caching using the standard snowflake-connector-python.
jordantshaw commented 5 months ago

I realized the reason this was not caching properly was because you need to explicitly install the snowflake-connector-python with the secure-local-storage alongside the snowflake-sqlalchemy library.