[GH-ISSUE #6592] Model whitelisting for generate endpoint #4150

Open
opened 2026-04-12 15:03:47 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @JTHesse on GitHub (Sep 2, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6592

I would like to support the ability to whitelist models that are usable with the generate endpoint.

The model list should be provided via an env variable and be checked against before running the generate function.

With this feature, the admins will gain more control over the models that can used by auto coding, f.e.: continue or other services. High frequent request from those applications will lead to huge delays, if the wrong model is selected.

Originally created by @JTHesse on GitHub (Sep 2, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6592 I would like to support the ability to whitelist models that are usable with the generate endpoint. The model list should be provided via an env variable and be checked against before running the generate function. With this feature, the admins will gain more control over the models that can used by auto coding, f.e.: [continue ](https://www.continue.dev/) or other services. High frequent request from those applications will lead to huge delays, if the wrong model is selected.
GiteaMirror added the feature request label 2026-04-12 15:03:47 -05:00
Author
Owner

@adamoutler commented on GitHub (Mar 25, 2025):

Looking at this code https://github.com/ollama/ollama/blob/main/cmd/cmd.go#L775

I think it could have an environmental variable added

...
    environment:
      OLLAMA_ALLOWED_MODEL_PREFIX: gemma,granite
...

By implementing like this

package main

import (
    "net/http"
    "os"
    "strings"
)

// PullHandler handles requests to pull models
func PullHandler(w http.ResponseWriter, r *http.Request) {
    // Retrieve the allowed model prefixes from the environment variable
    allowedPrefixes := strings.Split(os.Getenv("OLLAMA_ALLOWED_MODEL_PREFIX"), ",")

    // Extract the model name from the request parameters
    modelName := r.URL.Query().Get("model")
    if modelName == "" {
        http.Error(w, "Model name is required", http.StatusBadRequest)
        return
    }

    // Check if the model name starts with any of the allowed prefixes
    isAllowed := false
    for _, prefix := range allowedPrefixes {
        if strings.HasPrefix(modelName, prefix) {
            isAllowed = true
            break
        }
    }

    if !isAllowed {
        http.Error(w, "Model not allowed", http.StatusForbidden)
        return
    }

    // Proceed with the existing pull logic for allowed models
    // ...
}
<!-- gh-comment-id:2750943355 --> @adamoutler commented on GitHub (Mar 25, 2025): Looking at this code https://github.com/ollama/ollama/blob/main/cmd/cmd.go#L775 I think it could have an environmental variable added ``` docker-compose ... environment: OLLAMA_ALLOWED_MODEL_PREFIX: gemma,granite ... ``` By implementing like this ``` go package main import ( "net/http" "os" "strings" ) // PullHandler handles requests to pull models func PullHandler(w http.ResponseWriter, r *http.Request) { // Retrieve the allowed model prefixes from the environment variable allowedPrefixes := strings.Split(os.Getenv("OLLAMA_ALLOWED_MODEL_PREFIX"), ",") // Extract the model name from the request parameters modelName := r.URL.Query().Get("model") if modelName == "" { http.Error(w, "Model name is required", http.StatusBadRequest) return } // Check if the model name starts with any of the allowed prefixes isAllowed := false for _, prefix := range allowedPrefixes { if strings.HasPrefix(modelName, prefix) { isAllowed = true break } } if !isAllowed { http.Error(w, "Model not allowed", http.StatusForbidden) return } // Proceed with the existing pull logic for allowed models // ... } ```
Author
Owner

@adamoutler commented on GitHub (Mar 25, 2025):

I think this is an important feature for government/enterprise

<!-- gh-comment-id:2750946803 --> @adamoutler commented on GitHub (Mar 25, 2025): I think this is an important feature for government/enterprise
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#4150