|
| 1 | += LMEval Authentication with OAuth-Protected KServe InferenceServices |
| 2 | +:sectnums: |
| 3 | +:icons: font |
| 4 | + |
| 5 | +== Overview |
| 6 | + |
| 7 | +This guide explains how to configure LMEvalJob Custom Resources to authenticate with OAuth-protected KServe InferenceServices using service account tokens. When KServe InferenceServices are protected by OAuth proxy (`security.opendatahub.io/enable-auth: "true"`), they require proper authentication and RBAC permissions. |
| 8 | + |
| 9 | +== Prerequisites |
| 10 | + |
| 11 | +* OpenShift/Kubernetes cluster with KServe installed |
| 12 | +* TrustyAI Operator installed and LMEvalJob CRD available |
| 13 | +* OAuth-protected InferenceService deployed |
| 14 | +* `kubectl` access with sufficient permissions to create RBAC resources |
| 15 | + |
| 16 | +== Authentication Architecture |
| 17 | + |
| 18 | +When an InferenceService has OAuth protection enabled, the authentication flow works as follows: |
| 19 | + |
| 20 | +1. **OAuth Proxy**: Protects the InferenceService endpoint |
| 21 | +2. **Service Account Token**: Used for programmatic API access |
| 22 | +3. **RBAC Permissions**: Required for the service account to access InferenceServices |
| 23 | +4. **Subject Access Review (SAR)**: OAuth proxy validates permissions before allowing access |
| 24 | + |
| 25 | +== Step-by-Step Setup |
| 26 | + |
| 27 | +=== Step 1: Create RBAC Permissions |
| 28 | + |
| 29 | +The service account used by the LMEvalJob needs permission to access InferenceServices in the namespace. |
| 30 | + |
| 31 | +==== Create the Role |
| 32 | + |
| 33 | +Create `role.yaml`: |
| 34 | + |
| 35 | +[source,yaml] |
| 36 | +---- |
| 37 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 38 | +kind: Role |
| 39 | +metadata: |
| 40 | + name: inferenceservice-reader |
| 41 | +rules: |
| 42 | +- apiGroups: ["serving.kserve.io"] |
| 43 | + resources: ["inferenceservices"] |
| 44 | + verbs: ["get", "list"] # <1> |
| 45 | +---- |
| 46 | +<1> `get` and `list` permissions are required for OAuth proxy validation |
| 47 | + |
| 48 | +Apply the Role: |
| 49 | + |
| 50 | +[source,bash] |
| 51 | +---- |
| 52 | +kubectl apply -f role.yaml -n $NAMESPACE |
| 53 | +---- |
| 54 | + |
| 55 | +==== Create the RoleBinding |
| 56 | + |
| 57 | +Create `rolebinding.yaml`: |
| 58 | + |
| 59 | +[source,yaml] |
| 60 | +---- |
| 61 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 62 | +kind: RoleBinding |
| 63 | +metadata: |
| 64 | + name: lmeval-inferenceservice-access |
| 65 | +subjects: |
| 66 | +- kind: ServiceAccount |
| 67 | + name: default # <1> |
| 68 | +roleRef: |
| 69 | + kind: Role |
| 70 | + name: inferenceservice-reader |
| 71 | + apiGroup: rbac.authorization.k8s.io |
| 72 | +---- |
| 73 | +<1> Using `default` service account; create a dedicated SA if needed |
| 74 | + |
| 75 | +Apply the RoleBinding: |
| 76 | + |
| 77 | +[source,bash] |
| 78 | +---- |
| 79 | +kubectl apply -f rolebinding.yaml -n $NAMESPACE |
| 80 | +---- |
| 81 | + |
| 82 | +=== Step 2: Create Service Account Token Secret |
| 83 | + |
| 84 | +Create a long-lived service account token for the LMEvalJob to use. |
| 85 | + |
| 86 | +Create `sa-token-secret.yaml`: |
| 87 | + |
| 88 | +[source,yaml] |
| 89 | +---- |
| 90 | +apiVersion: v1 |
| 91 | +kind: Secret |
| 92 | +metadata: |
| 93 | + name: lmeval-sa-token |
| 94 | + annotations: |
| 95 | + kubernetes.io/service-account.name: default # <1> |
| 96 | +type: kubernetes.io/service-account-token |
| 97 | +---- |
| 98 | +<1> Reference to the service account with RBAC permissions |
| 99 | + |
| 100 | +Apply the Secret: |
| 101 | + |
| 102 | +[source,bash] |
| 103 | +---- |
| 104 | +kubectl apply -f sa-token-secret.yaml -n $NAMESPACE |
| 105 | +---- |
| 106 | + |
| 107 | +=== Step 3: Verify RBAC Permissions |
| 108 | + |
| 109 | +Verify that the service account has the necessary permissions: |
| 110 | + |
| 111 | +[source,bash] |
| 112 | +---- |
| 113 | +kubectl auth can-i get inferenceservices.serving.kserve.io \ |
| 114 | + -n $NAMESPACE \ |
| 115 | + --as=system:serviceaccount:$NAMESPACE:default |
| 116 | +---- |
| 117 | + |
| 118 | +Expected output: `yes` |
| 119 | + |
| 120 | +=== Step 4: Configure LMEvalJob |
| 121 | + |
| 122 | +Create an LMEvalJob that uses the service account token for authentication. |
| 123 | + |
| 124 | +Create `lmeval-job.yaml`: |
| 125 | + |
| 126 | +[source,yaml] |
| 127 | +---- |
| 128 | +apiVersion: trustyai.opendatahub.io/v1alpha1 |
| 129 | +kind: LMEvalJob |
| 130 | +metadata: |
| 131 | + name: oauth-eval-job |
| 132 | +spec: |
| 133 | + model: local-completions # <1> |
| 134 | + taskList: |
| 135 | + taskNames: ["mmlu"] |
| 136 | + logSamples: true |
| 137 | + batchSize: "1" |
| 138 | + allowOnline: true |
| 139 | + allowCodeExecution: true |
| 140 | + modelArgs: # <2> |
| 141 | + - name: model |
| 142 | + value: granite |
| 143 | + - name: base_url |
| 144 | + value: $ROUTE/v1/completions # <3> |
| 145 | + - name: num_concurrent |
| 146 | + value: "1" |
| 147 | + - name: max_retries |
| 148 | + value: "3" |
| 149 | + - name: tokenized_requests |
| 150 | + value: "false" |
| 151 | + - name: tokenizer |
| 152 | + value: ibm-granite/granite-7b-instruct |
| 153 | + - name: verify_certificate |
| 154 | + value: "False" # <4> |
| 155 | + pod: |
| 156 | + container: |
| 157 | + env: |
| 158 | + - name: OPENAI_API_KEY # <5> |
| 159 | + valueFrom: |
| 160 | + secretKeyRef: |
| 161 | + name: lmeval-sa-token |
| 162 | + key: token |
| 163 | +---- |
| 164 | +<1> Use `local-completions` for OpenAI-compatible API endpoints |
| 165 | +<2> Model arguments configure the evaluation client |
| 166 | +<3> HTTPS endpoint of the OAuth-protected InferenceService |
| 167 | +<4> Disable SSL verification for self-signed certificates |
| 168 | +<5> Service account token injected as API key environment variable |
| 169 | + |
| 170 | +Apply the LMEvalJob: |
| 171 | + |
| 172 | +[source,bash] |
| 173 | +---- |
| 174 | +kubectl apply -f lmeval-job.yaml -n $NAMESPACE |
| 175 | +---- |
| 176 | + |
| 177 | +== Configuration Reference |
| 178 | + |
| 179 | +=== Required Model Arguments |
| 180 | + |
| 181 | +[cols="1,2,1"] |
| 182 | +|=== |
| 183 | +|Argument |Description |Example |
| 184 | + |
| 185 | +|`model` |
| 186 | +|Model name for the evaluation |
| 187 | +|`granite` |
| 188 | + |
| 189 | +|`base_url` |
| 190 | +|HTTPS URL of the OAuth-protected InferenceService |
| 191 | +|`$ROUTE/v1/completions` |
| 192 | + |
| 193 | +|`verify_certificate` |
| 194 | +|Set to `"False"` for self-signed certificates |
| 195 | +|`"False"` |
| 196 | + |
| 197 | +|`tokenizer` |
| 198 | +|Tokenizer compatible with the model |
| 199 | +|`ibm-granite/granite-7b-instruct` |
| 200 | +|=== |
| 201 | + |
| 202 | +=== OAuth Proxy Endpoints |
| 203 | + |
| 204 | +OAuth-protected InferenceServices typically expose: |
| 205 | + |
| 206 | +* **HTTPS Port**: `8443` (OAuth proxy) |
| 207 | +* **Health Check**: `/health` |
| 208 | +* **API Endpoint**: `/v1/completions` |
| 209 | +* **OAuth Callback**: `/oauth/callback` |
| 210 | + |
| 211 | +== Troubleshooting |
| 212 | + |
| 213 | +=== Common Issues |
| 214 | + |
| 215 | +[cols="1,2,2"] |
| 216 | +|=== |
| 217 | +|Problem |Causes |Solution |
| 218 | + |
| 219 | +|OAuth Redirect Loop + |
| 220 | +*(302 redirects to OAuth authorisation endpoint)* |
| 221 | +a|* Missing RBAC permissions |
| 222 | +* Invalid service account token |
| 223 | +* Incorrect OAuth proxy configuration |
| 224 | +a|* Verify RBAC permissions with `kubectl auth can-i` |
| 225 | +* Check service account token validity |
| 226 | +* Ensure OAuth proxy allows programmatic access |
| 227 | + |
| 228 | +|SSL Certificate Errors + |
| 229 | +*(SSL verification failures)* |
| 230 | +|SSL certificate validation issues |
| 231 | +a|* Set `verify_certificate: "False"` in model arguments |
| 232 | +* Use proper CA certificates if available |
| 233 | +* Verify the correct HTTPS endpoint |
| 234 | + |
| 235 | +|Connection Refused + |
| 236 | +*(Connection refused on port 8443)* |
| 237 | +a|* Incorrect service endpoint |
| 238 | +* OAuth proxy not running |
| 239 | +* Network policies blocking access |
| 240 | +a|* Verify InferenceService is running: `kubectl get inferenceservice` |
| 241 | +* Check service endpoints: `kubectl get svc` |
| 242 | +* Test connectivity from within cluster |
| 243 | +|=== |
| 244 | + |
| 245 | +=== Debugging Commands |
| 246 | + |
| 247 | +Check RBAC permissions: |
| 248 | +[source,bash] |
| 249 | +---- |
| 250 | +kubectl auth can-i get inferenceservices.serving.kserve.io \ |
| 251 | + -n $NAMESPACE \ |
| 252 | + --as=system:serviceaccount:$NAMESPACE:default |
| 253 | +---- |
| 254 | + |
| 255 | +Verify service account token: |
| 256 | +[source,bash] |
| 257 | +---- |
| 258 | +kubectl get secret lmeval-sa-token -n $NAMESPACE -o jsonpath='{.data.token}' | base64 -d |
| 259 | +---- |
| 260 | + |
| 261 | +Test OAuth proxy connectivity: |
| 262 | +[source,bash] |
| 263 | +---- |
| 264 | +kubectl run debug-pod --image=curlimages/curl:latest --rm -it --restart=Never -n $NAMESPACE -- \ |
| 265 | + sh -c "curl -k -I $ROUTE/health" |
| 266 | +---- |
| 267 | + |
| 268 | +Check LMEvalJob logs: |
| 269 | +[source,bash] |
| 270 | +---- |
| 271 | +kubectl logs -n $NAMESPACE -l job-name=oauth-eval-job |
| 272 | +---- |
| 273 | + |
| 274 | +This guide provides a complete setup for authenticating LMEvalJob with OAuth-protected KServe InferenceServices. |
0 commit comments