Skip to content

Breaking change in how OPENAI_API_KEY is injected into workload after PR #304 #310

@mirco-bozzolini

Description

@mirco-bozzolini

Hello everyone,

I think that the pull request #304 introduces a breaking change on how the env var OPENAI_API_KEY is added to the workload.

In the default values there's a safe example on how to inject that variable through secrets:

# -- Env vars added to the Open WebUI deployment. Most up-to-date environment variables can be found here: https://docs.openwebui.com/getting-started/env-configuration. Variables can be defined as list or map style.
extraEnvVars: []
  # - name: OPENAI_API_KEY
  #   valueFrom:
  #     secretKeyRef:
  #       name: pipelines-api-key
  #       key: api-key
  # - name: OPENAI_API_KEY
  #   valueFrom:
  #     secretKeyRef:
  #       name: openai-api-key
  #       key: api-key

With tools like External Secret Operator you can safely add that env var to the container without hardcoding it within values.

Also THIS IS the best practice in production environments.

I also aknowledge that if you just want to try-out the service a simple attribute in the values is easier to use.

The problem I have is that with these lines of code in the template workload-manager.yaml OPENAI_API_KEY gets written always in the env field:

        {{- if and .Values.enableOpenaiApi .Values.openaiBaseApiUrl (not .Values.openaiBaseApiUrls) (not .Values.pipelines.enabled) }}
        # If only an OpenAI API value is set, set it to OPENAI_API_BASE_URL
        - name: "OPENAI_API_BASE_URL"
          value: {{ .Values.openaiBaseApiUrl | quote }}
        - name: "OPENAI_API_KEY"
          value: {{ .Values.openaiApiKey | quote }}

This produce the following result if you had previously followed the best practices:

 # If only an OpenAI API value is set, set it to OPENAI_API_BASE_URL
        - name: "OPENAI_API_BASE_URL"
          value: <REDACTED>
        - name: "OPENAI_API_KEY" <--- IT GETS WRITTEN HERE
          value: "0p3n-w3bu!"
          ....
        - name: OPENAI_API_KEY   <--- BUT ALSO HERE
          valueFrom:
            secretKeyRef:
              key: openai_api_key
              name: open-webui-managed-secret

That result in an error since there could not be duplicated env vars.

I tried on using the extraEnvFrom like so:

  extraEnvFrom: 
    # - configMapRef:
    #     name: my-config
    - secretRef:
        name: extra-env-from-secret

But still the OPENAI_API_KEY written by the template in the env field takes precedence.

I think this is the wrong approach.

My proposed solution is to check whether the value of openaiApiKey is empty and set it in the templates only if it not, so this change is not breaking if someone wants to follow security best practices or not.

If you give me a go for this solution I can make the change myself in no time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions