diff --git a/group_vars/all/16_ai.yml b/group_vars/all/16_ai.yml index e650afa8d8..6391ff45fa 100644 --- a/group_vars/all/16_ai.yml +++ b/group_vars/all/16_ai.yml @@ -13,6 +13,15 @@ S1_BASE_LOCAL_URL: "http://{{ lookup('config','svc-ai-s1', 'services.s1.name') } LITELLM_OPENAI_BASE_LOCAL_URL: "{{ LITELLM_BASE_LOCAL_URL }}/v1" +LITELLM_LOOPBACK_HOSTS: + - "127.0.0.1" + - "::1" + - "localhost" + +LITELLM_BASE_LOOPBACK_URL: "http://{{ LITELLM_LOOPBACK_HOSTS | first }}:{{ lookup('config','svc-ai-litellm', 'services.litellm.ports.local.http') }}" + +LITELLM_OPENAI_BASE_LOOPBACK_URL: "{{ LITELLM_BASE_LOOPBACK_URL }}/v1" + LITELLM_BACKEND_ROLES: "{{ lookup('deployment').inventory }}" LITELLM_OLLAMA_BACKEND: >- diff --git a/roles/svc-ai-litellm/tasks/utils/consumer_contract.yml b/roles/svc-ai-litellm/tasks/utils/consumer_contract.yml index 16ebaad36f..0e163a9462 100644 --- a/roles/svc-ai-litellm/tasks/utils/consumer_contract.yml +++ b/roles/svc-ai-litellm/tasks/utils/consumer_contract.yml @@ -1,4 +1,8 @@ --- +- name: "🔧 Read how '{{ application_id }}' reaches the gateway" + ansible.builtin.set_fact: + _litellm_consumer_on_host: "{{ lookup('config', application_id, 'services.' ~ (application_id | get_entity_name) ~ '.modes.host.enabled', false) | bool }}" + - name: "✅ Assert '{{ application_id }}' carries a gateway virtual key" ansible.builtin.assert: that: @@ -23,3 +27,20 @@ ingress), a host that is not this role's own domain, and the gateway's internal port {{ lookup('config', 'svc-ai-litellm', 'services.litellm.ports.internal.http') }} rather than its published one. + when: not (_litellm_consumer_on_host | bool) + +- name: "✅ Assert the AI base URL of '{{ application_id }}' stays on this machine" + ansible.builtin.assert: + that: + - (LITELLM_BASE_LOOPBACK_URL | urlsplit('scheme')) == 'http' + - (LITELLM_BASE_LOOPBACK_URL | urlsplit('hostname')) in LITELLM_LOOPBACK_HOSTS + - (LITELLM_BASE_LOOPBACK_URL | urlsplit('port') | int) == (lookup('config', 'svc-ai-litellm', 'services.litellm.ports.local.http') | int) + fail_msg: >- + {{ application_id }} runs on the host rather than in the deployment's + container network, so it would send inference traffic to + '{{ LITELLM_BASE_LOOPBACK_URL }}'. A workstation reaches the gateway only + over the loopback address the engine publishes it on: plain http, one of + {{ LITELLM_LOOPBACK_HOSTS | join(', ') }}, and the published port + {{ lookup('config', 'svc-ai-litellm', 'services.litellm.ports.local.http') }}. + Anything routable would carry the workstation's key off this machine. + when: _litellm_consumer_on_host | bool