Skip to content

Commit 5926240

Browse files
committed
AAP-58797: Operator - Implement Chatbot authentication
Signed-off-by: romartin <[email protected]>
1 parent 35e8283 commit 5926240

File tree

10 files changed

+62
-1
lines changed

10 files changed

+62
-1
lines changed

molecule/default/tasks/1_1_create_instance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
definition: "{{ lookup('template', template_item) | from_yaml }}"
99
apply: true
1010
wait: yes
11-
wait_timeout: 900
11+
wait_timeout: 1200
1212
wait_condition:
1313
type: Running
1414
reason: Successful

roles/chatbot/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ _chatbot_mcp_lightspeed_image_version: "{{ lookup('env', 'DEFAULT_CHATBOT_MCP_LI
4242
chatbot_config_secret_name: ''
4343
# ========================================
4444

45+
# ----------------------------------------
46+
# Configuration for the Chatbot API Key
47+
# ----------------------------------------
48+
chatbot_api_key_secret_name: 'chatbot-api-key'
49+
# ========================================
4550

4651
# ----------------------------------------
4752
# Configuration for underlying service
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Set the composed Chatbot API Key Secret name.
3+
set_fact:
4+
_chatbot_api_key_secret_name: "{{ ansible_operator_meta.name }}-{{ chatbot_api_key_secret_name }}"
5+
6+
- name: Check for existing Chatbot API Key Secret
7+
set_fact:
8+
_chatbot_api_key_secret: "{{ query('kubernetes.core.k8s', kind='Secret', namespace=ansible_operator_meta.namespace, resource_name=_chatbot_api_key_secret_name) }}"
9+
10+
- name: Create Chatbot API Key Secret
11+
kubernetes.core.k8s:
12+
state: present
13+
definition: "{{ lookup('template', 'secrets/chatbot_api_key_secret.yaml.j2') }}"
14+
no_log: "{{ no_log }}"
15+
when:
16+
- _chatbot_api_key_secret | length == 0

roles/chatbot/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- name: Read AnsibleAIConnect's Chatbot secret
1515
ansible.builtin.include_tasks: read_chatbot_configuration_secret.yml
1616

17+
- name: Read AnsibleAIConnect's Chatbot API Key
18+
ansible.builtin.include_tasks: handle_chatbot_api_key_secret.yml
19+
1720
- name: Clean up old Chatbot PVC before upgrade
1821
ansible.builtin.include_tasks: upgrade_chatbot.yml
1922

roles/chatbot/tasks/remove_chatbot_api.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
namespace: '{{ ansible_operator_meta.namespace }}'
2424
wait: yes
2525

26+
- name: Remove Chatbot API Key Secret resource
27+
kubernetes.core.k8s:
28+
state: absent
29+
kind: Secret
30+
name: '{{ ansible_operator_meta.name }}-{{ chatbot_api_key_secret_name }}'
31+
namespace: '{{ ansible_operator_meta.namespace }}'
32+
wait: yes
33+
2634
- name: Remove Chatbot Service resources
2735
kubernetes.core.k8s:
2836
state: absent

roles/chatbot/templates/chatbot.configmap_lightspeed_stack_config.yaml.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ data:
3131
transcripts_enabled: false
3232
customization:
3333
system_prompt_path: /.llama/distributions/ansible-chatbot/system-prompts/default.txt
34+
authentication:
35+
module: "api-key-token"
36+
api_key_config:
37+
api_key: ${env.CHATBOT_API_KEY}
3438
{% if _aap_gateway_url is defined or _aap_controller_url is defined %}
3539
mcp_servers:
3640
{% if _aap_gateway_url is defined and _aap_controller_url is defined %}

roles/chatbot/templates/chatbot.deployment.yaml.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ spec:
106106
value: /.llama/data
107107
- name: EMBEDDING_MODEL
108108
value: ./embeddings_model
109+
- name: CHATBOT_API_KEY
110+
valueFrom:
111+
secretKeyRef:
112+
name: "{{ ansible_operator_meta.name }}-{{ chatbot_api_key_secret_name }}"
113+
key: api_key
109114
- name: PROVIDER_TOKEN
110115
value: {{ chatbot_token }}
111116
- name: PROVIDER_URL
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: '{{ ansible_operator_meta.name }}-{{ chatbot_api_key_secret_name }}'
6+
namespace: '{{ ansible_operator_meta.namespace }}'
7+
labels:
8+
{{ lookup("template", "../common/templates/labels/common.yaml.j2") | indent(width=4) | trim }}
9+
stringData:
10+
api_key: '{{ lookup('password', '/dev/null length=32 chars=ascii_letters,digits') }}'

roles/model/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ auth_config_secret_name: ''
4949
model_config_secret_name: ''
5050
# ========================================
5151

52+
# ----------------------------------------
53+
# Configuration for the Chatbot API Key
54+
# ----------------------------------------
55+
chatbot_api_key_secret_name: 'chatbot-api-key'
56+
# ========================================
5257

5358
# ----------------------------------------
5459
# Configuration for underlying service

roles/model/templates/model.deployment.yaml.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ spec:
204204
secretKeyRef:
205205
name: "{{ __model_pipeline_secret_name }}"
206206
key: config
207+
- name: CHATBOT_API_KEY
208+
valueFrom:
209+
secretKeyRef:
210+
name: "{{ ansible_operator_meta.name }}-{{ chatbot_api_key_secret_name }}"
211+
key: api_key
207212
{% if chatbot_config is defined %}
208213
- name: CHATBOT_DEFAULT_PROVIDER
209214
value: {{ chatbot_llm_provider_type }}

0 commit comments

Comments
 (0)