n4ze3m / page-assist

Use your locally running AI models to assist you in your web browsing
https://chromewebstore.google.com/detail/page-assist-a-web-ui-for/jfgfiigpkhlkbnfnbobbkinehhfdhndo
MIT License
864 stars 99 forks source link

[FEATURE SUGGESTION] Add a Basic or Bearer 'Authorization' header to Ollama API requests #106

Open lambirou opened 1 month ago

lambirou commented 1 month ago

Currently, requests to the Ollama API do not include an 'Authorization' header. To strengthen the security of API calls, it is necessary to add an 'Authorization' header with Basic or Bearer authentication.

Tasks to complete:

n4ze3m commented 1 month ago

Hey, thanks for this great idea! Is there an API key on Ollama?

aiseei commented 1 month ago

@n4ze3m no ollama doesnt not have any auth built it. the expectation is that it sits within a local host env behind a proxy server and app/backend and that auth is managed there. Trying to add auth header in this extension will not make the setup any more secure.

n4ze3m commented 1 month ago

I will add an option in the advanced URL configuration for the headers :)

lambirou commented 3 weeks ago

Here is my nginx configuration to add an Authorization Basic header in the request to the Ollama API. I use Apache's htpasswd to manage HTTP users.


server {
  ...

  location @reverse_proxy {
    ...
    proxy_set_header  Authorization $http_authorization;
    proxy_pass_header Authorization;
    proxy_pass_request_headers on;
    ...
  }

  ...

  auth_basic           "Administrator’s Area";
  auth_basic_user_file /etc/apache2/.htpasswd;

  ...
}

The HTTP header:

Content-Type: application/json
Accept: application/json
Authorization: Basic cmVkaTpxSlczbk01cFlaNzM=

The hash is the concatenation of user:password hashed in base64.

lambirou commented 3 weeks ago

@n4ze3m No Ollama does not integrate API key management but using Authorization headers in reverse proxy can be an interesting alternative.

yusiwen commented 1 week ago

Any update? Need this feature badly...

n4ze3m commented 1 week ago

I will add an option to pass custom headers in the next version (v1.1.14), which will be released on Monday or Tuesday.

n4ze3m commented 6 days ago

Hello, everyone! v1.1.14 has been released, which includes the option to configure custom headers for Ollama. Please let me know if you encounter any issues using this feature. Thanks!

image

lambirou commented 3 days ago

A huge thank you for the efforts you put into this project. But in my tests the headers I provided are not added to the request to the API.

n4ze3m commented 2 days ago

Hey, sorry about that. Which header key was used? I will try to fix it in the next release.