dify icon indicating copy to clipboard operation
dify copied to clipboard

raise private key not found when set llm key

Open cjdxhjj opened this issue 9 months ago • 4 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.7

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

when i set the llm secret it report an error

✔️ Expected Behavior

No response

❌ Actual Behavior

the docker report error image image image self host image

cjdxhjj avatar May 10 '24 08:05 cjdxhjj

the dify 0.6.6 also report that error

cjdxhjj avatar May 10 '24 08:05 cjdxhjj

Hey @cjdxhjj, great to see you back! 🙌 I'm diving into the details of your issue and will get back to you shortly with some insights.

dosubot[bot] avatar May 10 '24 08:05 dosubot[bot]

我有同样的问题 我发现在设置API Key后就会一直有这个问题 image

2024-05-11 07:07:16.629 INFO [Thread-169 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [11/May/2024 07:07:16] "OPTIONS /console/api/workspaces/current/model-providers HTTP/1.1" 200 -
2024-05-11 07:07:16.772 ERROR [Thread-171 (process_request_thread)] [app.py:838] - Exception on /console/api/workspaces/current/model-providers [GET]
Traceback (most recent call last):
  File "/home/anhao/project/dify/api/libs/rsa.py", line 55, in get_decrypt_decoding
    private_key = storage.load(filepath)
  File "/home/anhao/project/dify/api/extensions/ext_storage.py", line 45, in load
    return self.load_once(filename)
  File "/home/anhao/project/dify/api/extensions/ext_storage.py", line 48, in load_once
    return self.storage_runner.load_once(filename)
  File "/home/anhao/project/dify/api/extensions/storage/local_storage.py", line 40, in load_once
    raise FileNotFoundError("File not found")
FileNotFoundError: File not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/setup.py", line 86, in decorated
    return view(*args, **kwargs)
  File "/home/anhao/project/dify/api/libs/login.py", line 91, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/wraps.py", line 21, in decorated
    return view(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/workspace/model_providers.py", line 33, in get
    provider_list = model_provider_service.get_provider_list(
  File "/home/anhao/project/dify/api/services/model_provider_service.py", line 46, in get_provider_list
    provider_configurations = self.provider_manager.get_configurations(tenant_id)
  File "/home/anhao/project/dify/api/core/provider_manager.py", line 118, in get_configurations
    custom_configuration = self._to_custom_configuration(
  File "/home/anhao/project/dify/api/core/provider_manager.py", line 509, in _to_custom_configuration
    self.decoding_rsa_key, self.decoding_cipher_rsa = encrypter.get_decrypt_decoding(tenant_id)
  File "/home/anhao/project/dify/api/core/helper/encrypter.py", line 29, in get_decrypt_decoding
    return rsa.get_decrypt_decoding(tenant_id)
  File "/home/anhao/project/dify/api/libs/rsa.py", line 57, in get_decrypt_decoding
    raise PrivkeyNotFoundError("Private key not found, tenant_id: {tenant_id}".format(tenant_id=tenant_id))
libs.rsa.PrivkeyNotFoundError: Private key not found, tenant_id: ea69b0eb-d3a8-421e-85c2-4310c3ee5c63
2024-05-11 07:07:16.804 INFO [Thread-171 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [11/May/2024 07:07:16] "GET /console/api/workspaces/current/model-providers HTTP/1.1" 500 -
2024-05-11 07:07:16.936 INFO [Thread-172 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [11/May/2024 07:07:16] "OPTIONS /console/api/workspaces/current/models/model-types/llm HTTP/1.1" 200 -
2024-05-11 07:07:17.002 ERROR [Thread-173 (process_request_thread)] [app.py:838] - Exception on /console/api/workspaces/current/models/model-types/llm [GET]
Traceback (most recent call last):
  File "/home/anhao/project/dify/api/libs/rsa.py", line 55, in get_decrypt_decoding
    private_key = storage.load(filepath)
  File "/home/anhao/project/dify/api/extensions/ext_storage.py", line 45, in load
    return self.load_once(filename)
  File "/home/anhao/project/dify/api/extensions/ext_storage.py", line 48, in load_once
    return self.storage_runner.load_once(filename)
  File "/home/anhao/project/dify/api/extensions/storage/local_storage.py", line 40, in load_once
    raise FileNotFoundError("File not found")
FileNotFoundError: File not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper
    resp = resource(*args, **kwargs)
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask/views.py", line 110, in view
    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]
  File "/home/anhao/app/anaconda3/envs/dify/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/setup.py", line 86, in decorated
    return view(*args, **kwargs)
  File "/home/anhao/project/dify/api/libs/login.py", line 91, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/wraps.py", line 21, in decorated
    return view(*args, **kwargs)
  File "/home/anhao/project/dify/api/controllers/console/workspace/models.py", line 251, in get
    models = model_provider_service.get_models_by_model_type(
  File "/home/anhao/project/dify/api/services/model_provider_service.py", line 290, in get_models_by_model_type
    provider_configurations = self.provider_manager.get_configurations(tenant_id)
  File "/home/anhao/project/dify/api/core/provider_manager.py", line 118, in get_configurations
    custom_configuration = self._to_custom_configuration(
  File "/home/anhao/project/dify/api/core/provider_manager.py", line 509, in _to_custom_configuration
    self.decoding_rsa_key, self.decoding_cipher_rsa = encrypter.get_decrypt_decoding(tenant_id)
  File "/home/anhao/project/dify/api/core/helper/encrypter.py", line 29, in get_decrypt_decoding
    return rsa.get_decrypt_decoding(tenant_id)
  File "/home/anhao/project/dify/api/libs/rsa.py", line 57, in get_decrypt_decoding
    raise PrivkeyNotFoundError("Private key not found, tenant_id: {tenant_id}".format(tenant_id=tenant_id))
libs.rsa.PrivkeyNotFoundError: Private key not found, tenant_id: ea69b0eb-d3a8-421e-85c2-4310c3ee5c63
2024-05-11 07:07:17.008 INFO [Thread-173 (process_request_thread)] [_internal.py:97] - 127.0.0.1 - - [11/May/2024 07:07:17] "GET /console/api/workspaces/current/models/model-types/llm HTTP/1.1" 500 -

在开发环境中存在这个问题,启动生产环境的时候不会有这个问题 我在生产环境中,把api key删掉,再启动调试环境,这个问题也会消失,但是再设置api key还是会复现 有没有可能跟key过期了有关系??

btnkr avatar May 11 '24 07:05 btnkr

The error indicating "Private key not found" suggests an issue with locating the private key for the specified tenant ID. This problem often arises from the encryption keys not being properly set up or accessible in your environment. To address this, you should reset the encryption keys. Here's how you can do it for both Docker and source code setups:

  • For Docker compose deployment, execute the following command:
    docker exec -it docker-api-1 flask reset-encrypt-key-pair
    
  • For source code startup, navigate to the API directory and run:
    flask reset-encrypt-key-pair
    

This process is detailed in the Dify documentation's FAQ section, which provides guidance on handling encryption key-related issues.

Additionally, ensure that your Redis cache is functioning correctly, as Dify uses Redis to cache private keys for efficiency. Issues with Redis, such as connectivity problems or incorrect cache eviction policies, could lead to the application being unable to retrieve the private key from the cache, thus attempting to load it from storage and resulting in the error you're experiencing.

If resetting the encryption keys does not resolve the issue, it may be necessary to review the application's configuration regarding key storage and retrieval, as well as ensuring that the Redis cache is properly configured and accessible.

Details

Sources


About Dosu This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

dosubot[bot] avatar May 11 '24 07:05 dosubot[bot]

the dify 0.6.14 also report that error

steven-yan avatar Aug 05 '24 12:08 steven-yan