Skip to content

Commit 0a3c3a0

Browse files
authored
Merge pull request #2 from thepetk/feature/add_byo_server_token_auth_support
Feature/add byo server token auth support
2 parents ba48a4e + fdea136 commit 0a3c3a0

20 files changed

+210
-17
lines changed

skeleton/gitops-template/components/http/base/deployment.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ spec:
3232
- configMapRef:
3333
name: ${{ values.name }}-database-config
3434
{%- endif %}
35+
{%- if values.includeModelEndpointSecret %}
36+
env:
37+
- name: MODEL_ENDPOINT_BEARER
38+
valueFrom:
39+
secretKeyRef:
40+
name: ${{ values.modelEndpointSecretName }}
41+
key: ${{ values.modelEndpointSecretKey }}
42+
{%- endif %}
3543
ports:
3644
- containerPort: ${{ values.appPort }}
3745
securityContext:

skeleton/gitops-template/components/http/base/rhoai/initialize-dsp.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ spec:
9090
successThreshold: 1
9191
timeoutSeconds: 1
9292
env:
93+
{%- if values.includeModelEndpointSecret %}
94+
- name: MODEL_ENDPOINT_BEARER
95+
valueFrom:
96+
secretKeyRef:
97+
name: $${{ values.modelEndpointSecretName }}
98+
key: $${{ values.modelEndpointSecretKey }}
99+
{%- endif %}
93100
- name: NOTEBOOK_ARGS
94101
value: |-
95102
--ServerApp.port=8888

skeleton/template.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,36 @@ spec:
8080
title: Model Server Endpoint
8181
type: string
8282
description: "The endpoint for an existing model server."
83+
includeModelEndpointSecret:
84+
title: Bearer Authentication Required?
85+
type: boolean
86+
default: false
8387
# SED_LLM_SERVER_START
8488
modelName:
8589
title: Model Name
8690
type: string
8791
ui:help: "The name of the model deployed on the model server you would like to use."
8892
# SED_LLM_SERVER_END
93+
dependencies:
94+
includeModelEndpointSecret:
95+
allOf:
96+
- if:
97+
properties:
98+
includeModelEndpointSecret:
99+
const: true
100+
then:
101+
properties:
102+
modelEndpointSecretName:
103+
title: Model Endpoint Secret Name
104+
ui:help: Provide the name of the Secret containing your bearer token.
105+
type: string
106+
modelEndpointSecretKey:
107+
title: Model Endpoint Secret Key
108+
ui:help: Provide the Secret's key containing the token value.
109+
type: string
110+
required:
111+
- modelEndpointSecretName
112+
- modelEndpointSecretKey
89113
# SED_LLM_SERVER_START
90114
- properties:
91115
modelServer:
@@ -340,6 +364,9 @@ spec:
340364
# SED_LLM_SERVER_END
341365
existingModelServer: ${{ parameters.modelServer === 'Existing model server' }}
342366
modelEndpoint: ${{ parameters.modelEndpoint }}
367+
modelEndpointSecretName: ${{ parameters.modelEndpointSecretName }}
368+
modelEndpointSecretKey: ${{ parameters.modelEndpointSecretKey }}
369+
includeModelEndpointSecret: ${{ parameters.includeModelEndpointSecret }}
343370
# for RHOAI
344371
rhoaiSelected: ${{ parameters.rhoaiSelected }}
345372
# SED_DB_START

templates/audio-to-text/content/Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/python-311:1-72.1722518949
1+
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
22
WORKDIR /locallm
33
COPY requirements.txt /locallm/requirements.txt
44
RUN pip install --upgrade pip && \

templates/audio-to-text/content/whisper_client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
st.markdown("Upload an audio file you wish to have translated")
99
endpoint = os.getenv("MODEL_ENDPOINT", default="http://0.0.0.0:8001")
1010
endpoint = f"{endpoint}/inference"
11+
endpoint_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
12+
request_kwargs = {}
13+
if endpoint_bearer is not None:
14+
request_kwargs["headers"] = {"Authorization": f"Bearer {endpoint_bearer}"}
1115
audio = st.file_uploader("", type=["wav","mp3","mp4","flac"], accept_multiple_files=False)
1216
# read audio file
1317
if audio:
1418
audio_bytes = audio.read()
1519
st.audio(audio_bytes, format='audio/wav', start_time=0)
16-
files = {'file': audio_bytes}
17-
response = requests.post(endpoint, files=files)
20+
request_kwargs["files"] = {'file': audio_bytes}
21+
response = requests.post(endpoint, **request_kwargs)
1822
response_json = response.json()
1923
st.subheader(f"Translated Text")
2024
st.text_area(label="", value=response_json['text'], height=300)

templates/audio-to-text/template.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ spec:
5757
title: Model Server Endpoint
5858
type: string
5959
description: "The endpoint for an existing model server."
60+
includeModelEndpointSecret:
61+
title: Bearer Authentication Required?
62+
type: boolean
63+
default: false
64+
dependencies:
65+
includeModelEndpointSecret:
66+
allOf:
67+
- if:
68+
properties:
69+
includeModelEndpointSecret:
70+
const: true
71+
then:
72+
properties:
73+
modelEndpointSecretName:
74+
title: Model Endpoint Secret Name
75+
ui:help: Provide the name of the Secret containing your bearer token.
76+
type: string
77+
modelEndpointSecretKey:
78+
title: Model Endpoint Secret Key
79+
ui:help: Provide the Secret's key containing the token value.
80+
type: string
81+
required:
82+
- modelEndpointSecretName
83+
- modelEndpointSecretKey
6084
# SED_ASR_MODEL_SERVER_START
6185
- properties:
6286
modelServer:
@@ -270,6 +294,9 @@ spec:
270294
modelServicePort: 8001
271295
existingModelServer: ${{ parameters.modelServer === 'Existing model server' }}
272296
modelEndpoint: ${{ parameters.modelEndpoint }}
297+
modelEndpointSecretName: ${{ parameters.modelEndpointSecretName }}
298+
modelEndpointSecretKey: ${{ parameters.modelEndpointSecretKey }}
299+
includeModelEndpointSecret: ${{ parameters.includeModelEndpointSecret }}
273300
# for RHOAI
274301
rhoaiSelected: ${{ parameters.rhoaiSelected }}
275302
- action: fs:rename

templates/chatbot/content/Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/python-311:1-72.1722518949
1+
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
22
WORKDIR /chat
33
COPY requirements.txt .
44
RUN pip install --upgrade pip

templates/chatbot/content/chatbot_ui.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
model_service = os.getenv("MODEL_ENDPOINT",
1313
"http://localhost:8001")
1414
model_service = f"{model_service}/v1"
15+
model_service_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
16+
request_kwargs = {}
17+
if model_service_bearer is not None:
18+
request_kwargs = {"headers": {"Authorization": f"Bearer {model_service_bearer}"}}
1519

1620
@st.cache_resource(show_spinner=False)
1721
def checking_model_service():
@@ -20,8 +24,8 @@ def checking_model_service():
2024
ready = False
2125
while not ready:
2226
try:
23-
request_cpp = requests.get(f'{model_service}/models')
24-
request_ollama = requests.get(f'{model_service[:-2]}api/tags')
27+
request_cpp = requests.get(f'{model_service}/models', **request_kwargs)
28+
request_ollama = requests.get(f'{model_service[:-2]}api/tags', **request_kwargs)
2529
if request_cpp.status_code == 200:
2630
server = "Llamacpp_Python"
2731
ready = True
@@ -37,7 +41,7 @@ def checking_model_service():
3741

3842
def get_models():
3943
try:
40-
response = requests.get(f"{model_service[:-2]}api/tags")
44+
response = requests.get(f"{model_service[:-2]}api/tags", **request_kwargs)
4145
return [i["name"].split(":")[0] for i in
4246
json.loads(response.content)["models"]]
4347
except:
@@ -76,7 +80,7 @@ def memory():
7680
options=models)
7781

7882
llm = ChatOpenAI(base_url=model_service,
79-
api_key="sk-no-key-required",
83+
api_key="sk-no-key-required" if model_service_bearer is None else model_service_bearer,
8084
model=model_name,
8185
streaming=True,
8286
callbacks=[StreamlitCallbackHandler(st.empty(),

templates/chatbot/template.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,36 @@ spec:
6464
title: Model Server Endpoint
6565
type: string
6666
description: "The endpoint for an existing model server."
67+
includeModelEndpointSecret:
68+
title: Bearer Authentication Required?
69+
type: boolean
70+
default: false
6771
# SED_LLM_SERVER_START
6872
modelName:
6973
title: Model Name
7074
type: string
7175
ui:help: "The name of the model deployed on the model server you would like to use."
7276
# SED_LLM_SERVER_END
77+
dependencies:
78+
includeModelEndpointSecret:
79+
allOf:
80+
- if:
81+
properties:
82+
includeModelEndpointSecret:
83+
const: true
84+
then:
85+
properties:
86+
modelEndpointSecretName:
87+
title: Model Endpoint Secret Name
88+
ui:help: Provide the name of the Secret containing your bearer token.
89+
type: string
90+
modelEndpointSecretKey:
91+
title: Model Endpoint Secret Key
92+
ui:help: Provide the Secret's key containing the token value.
93+
type: string
94+
required:
95+
- modelEndpointSecretName
96+
- modelEndpointSecretKey
7397
# SED_LLM_SERVER_START
7498
- properties:
7599
modelServer:
@@ -300,6 +324,9 @@ spec:
300324
# SED_LLM_SERVER_END
301325
existingModelServer: ${{ parameters.modelServer === 'Existing model server' }}
302326
modelEndpoint: ${{ parameters.modelEndpoint }}
327+
modelEndpointSecretName: ${{ parameters.modelEndpointSecretName }}
328+
modelEndpointSecretKey: ${{ parameters.modelEndpointSecretKey }}
329+
includeModelEndpointSecret: ${{ parameters.includeModelEndpointSecret }}
303330
# for RHOAI
304331
rhoaiSelected: ${{ parameters.rhoaiSelected }}
305332
- action: fs:rename

templates/codegen/content/Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/python-311:1-72.1722518949
1+
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
22
WORKDIR /codegen
33
COPY requirements.txt .
44
RUN pip install --upgrade pip

templates/codegen/content/codegen-app.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
model_service = os.getenv("MODEL_ENDPOINT", "http://localhost:8001")
1212
model_service = f"{model_service}/v1"
13+
model_service_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
14+
request_kwargs = {}
15+
if model_service_bearer is not None:
16+
request_kwargs = {"headers": {"Authorization": f"Bearer {model_service_bearer}"}}
1317

1418
@st.cache_resource(show_spinner=False)
1519
def checking_model_service():
@@ -18,7 +22,7 @@ def checking_model_service():
1822
ready = False
1923
while not ready:
2024
try:
21-
request = requests.get(f'{model_service}/models')
25+
request = requests.get(f'{model_service}/models', **request_kwargs)
2226
if request.status_code == 200:
2327
ready = True
2428
except:
@@ -43,7 +47,7 @@ def checking_model_service():
4347

4448
llm = ChatOpenAI(base_url=model_service,
4549
model=model_name,
46-
api_key="EMPTY",
50+
api_key="EMPTY" if model_service_bearer is None else model_service_bearer,
4751
streaming=True)
4852

4953
# Define the Langchain chain

templates/codegen/template.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,36 @@ spec:
6464
title: Model Server Endpoint
6565
type: string
6666
description: "The endpoint for an existing model server."
67+
includeModelEndpointSecret:
68+
title: Bearer Authentication Required?
69+
type: boolean
70+
default: false
6771
# SED_LLM_SERVER_START
6872
modelName:
6973
title: Model Name
7074
type: string
7175
ui:help: "The name of the model deployed on the model server you would like to use."
7276
# SED_LLM_SERVER_END
77+
dependencies:
78+
includeModelEndpointSecret:
79+
allOf:
80+
- if:
81+
properties:
82+
includeModelEndpointSecret:
83+
const: true
84+
then:
85+
properties:
86+
modelEndpointSecretName:
87+
title: Model Endpoint Secret Name
88+
ui:help: Provide the name of the Secret containing your bearer token.
89+
type: string
90+
modelEndpointSecretKey:
91+
title: Model Endpoint Secret Key
92+
ui:help: Provide the Secret's key containing the token value.
93+
type: string
94+
required:
95+
- modelEndpointSecretName
96+
- modelEndpointSecretKey
7397
# SED_LLM_SERVER_START
7498
- properties:
7599
modelServer:
@@ -300,6 +324,9 @@ spec:
300324
# SED_LLM_SERVER_END
301325
existingModelServer: ${{ parameters.modelServer === 'Existing model server' }}
302326
modelEndpoint: ${{ parameters.modelEndpoint }}
327+
modelEndpointSecretName: ${{ parameters.modelEndpointSecretName }}
328+
modelEndpointSecretKey: ${{ parameters.modelEndpointSecretKey }}
329+
includeModelEndpointSecret: ${{ parameters.includeModelEndpointSecret }}
303330
# for RHOAI
304331
rhoaiSelected: ${{ parameters.rhoaiSelected }}
305332
- action: fs:rename

templates/object-detection/content/Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/python-311:1-72.1722518949
1+
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
22
WORKDIR /locallm
33
COPY requirements.txt /locallm/requirements.txt
44
RUN pip install --upgrade pip && \

templates/object-detection/content/object_detection_client.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77

88
st.title("🕵️‍♀️ Object Detection")
99
endpoint =os.getenv("MODEL_ENDPOINT", default = "http://0.0.0.0:8000")
10+
endpoint_bearer = os.getenv("MODEL_ENDPOINT_BEARER")
1011
headers = {"accept": "application/json",
1112
"Content-Type": "application/json"}
13+
if endpoint_bearer:
14+
headers["Authorization"] = f"Bearer {endpoint_bearer}"
1215
image = st.file_uploader("Upload Image")
1316
window = st.empty()
1417

templates/object-detection/content/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ MarkupSafe==2.1.5
1616
mdurl==0.1.2
1717
numpy==1.26.4
1818
packaging==24.0
19-
pandas==2.2.2
19+
pandas==2.2.3
2020
pillow==10.3.0
2121
protobuf==4.25.3
2222
pyarrow==15.0.2
@@ -37,4 +37,4 @@ toolz==0.12.1
3737
tornado==6.4.1
3838
typing_extensions==4.11.0
3939
tzdata==2024.1
40-
urllib3==2.2.2
40+
urllib3==2.2.3

templates/object-detection/template.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ spec:
5757
title: Model Server Endpoint
5858
type: string
5959
description: "The endpoint for an existing model server."
60+
includeModelEndpointSecret:
61+
title: Bearer Authentication Required?
62+
type: boolean
63+
default: false
64+
dependencies:
65+
includeModelEndpointSecret:
66+
allOf:
67+
- if:
68+
properties:
69+
includeModelEndpointSecret:
70+
const: true
71+
then:
72+
properties:
73+
modelEndpointSecretName:
74+
title: Model Endpoint Secret Name
75+
ui:help: Provide the name of the Secret containing your bearer token.
76+
type: string
77+
modelEndpointSecretKey:
78+
title: Model Endpoint Secret Key
79+
ui:help: Provide the Secret's key containing the token value.
80+
type: string
81+
required:
82+
- modelEndpointSecretName
83+
- modelEndpointSecretKey
6084
# SED_DETR_MODEL_SERVER_START
6185
- properties:
6286
modelServer:
@@ -270,6 +294,9 @@ spec:
270294
modelServicePort: 8000
271295
existingModelServer: ${{ parameters.modelServer === 'Existing model server' }}
272296
modelEndpoint: ${{ parameters.modelEndpoint }}
297+
modelEndpointSecretName: ${{ parameters.modelEndpointSecretName }}
298+
modelEndpointSecretKey: ${{ parameters.modelEndpointSecretKey }}
299+
includeModelEndpointSecret: ${{ parameters.includeModelEndpointSecret }}
273300
# for RHOAI
274301
rhoaiSelected: ${{ parameters.rhoaiSelected }}
275302
- action: fs:rename

templates/rag/content/Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi9/python-311:1-72.1722518949
1+
FROM registry.access.redhat.com/ubi9/python-311:1-77.1726664316
22
### Update sqlite for chroma
33
USER root
44
RUN dnf remove sqlite3 -y

0 commit comments

Comments
 (0)