Commit 5286e34
authored
feat(security, authc): implement optional "minimal" authentication mode (elastic#251119)
## Summary
This PR introduces a **"minimal" authentication mode** for Kibana HTTP
routes and updates the authentication provider interfaces to pass full
session objects instead of raw provider state.
### Minimal authentication mode
Adds a new `'minimal'` option for `security.authc.enabled` on route
definitions. When a route opts into minimal authentication, Kibana
**skips the Elasticsearch `_authenticate` API call** and instead returns
a lightweight user proxy constructed from session data already stored in
the Kibana session document.
This is useful for high-frequency or performance-sensitive endpoints
where:
- The session has already been fully authenticated on login
- Credential validation will happen naturally when the request reaches
Elasticsearch
- The overhead of an extra `_authenticate` round-trip is unnecessary
The minimal user proxy provides `username`, `authentication_provider`,
`profile_uid`, and `enabled`, but deliberately **throws** if code tries
to access properties that require a real ES authenticate call
(`authentication_realm`, `lookup_realm`, `authentication_type`,
`elastic_cloud_user`).
### Route type system changes
The `RouteAuthc` type is expanded from `AuthcEnabled | AuthcDisabled` to
`AuthcEnabled | AuthcMinimal | AuthcOptional | AuthcDisabled`:
- **`AuthcEnabled`** (`enabled: true`) - full authentication (default,
unchanged)
- **`AuthcMinimal`** (`enabled: 'minimal'`) - new, session-only
authentication, no ES call, requires `reason`
- **`AuthcOptional`** (`enabled: 'optional'`) - existing behavior, now
requires an explicit `reason`
- **`AuthcDisabled`** (`enabled: false`) - no authentication (unchanged)
Both `'minimal'` and `'optional'` now require a `reason` string
explaining why the route deviates from the default. Existing
`'optional'` routes are migrated to the new shape with explicit reasons.
### Provider interface refactoring
All authentication provider methods (`login`, `authenticate`, `logout`)
now receive the full `SessionValue<TState>` object instead of raw
`state`:
- `BaseAuthenticationProvider` becomes generic:
`BaseAuthenticationProvider<TState>`
- `logout(request, state?)` → `logout(request, session?)`
- Providers extract `state` from `session?.state` internally when needed
- The `Authenticator` passes `sessionValue` (not `sessionValue.state`)
to providers
- This gives providers access to session metadata (`username`,
`provider`, `userProfileId`) needed for minimal auth
### Route migrations
Existing routes using `options.authRequired: 'optional'` are migrated to
the new `security.authc` config:
- `GET /api/status` - status endpoint (k8s probes)
- `GET /api/banners/info` - banner info on login page
- `GET /api/custom_branding/info` - custom branding on login page
- `GET /bootstrap-anonymous.js` - anonymous bootstrap script
- `POST /internal/security/analytics/_record_violations` - CSP violation
reports
- `POST /login` - login page view route (reason added)
- Mock IDP plugin routes (testing)
### Integration tests
Every authentication provider (anonymous, basic/token, SAML, OIDC, PKI,
Kerberos) gets a `'should support minimal authentication'` integration
test that:
1. Authenticates and obtains a session cookie via the provider's normal
flow
2. Hits **both** `/authentication/fast/me` (minimal) and
`/internal/security/me` (default)
3. Asserts that `username` and `authentication_provider` match between
both responses
4. Asserts the key behavioral difference: minimal mode does **not**
return `authentication_realm` (since ES `_authenticate` is skipped),
while default mode does
__Assisted by:__ Claude Opus 4.6 (via OpenCode and GitHub Copilot).
Closes elastic#2449281 parent 5fbc247 commit 5286e34
48 files changed
Lines changed: 1651 additions & 640 deletions
File tree
- packages/kbn-mock-idp-plugin/server
- src
- core/packages
- capabilities/server-internal/src
- routes
- http
- router-server-internal/src
- versioned_router
- server-internal/src
- server
- src/router
- rendering/server-internal/src/bootstrap
- status/server-internal/src/routes
- x-pack/platform
- plugins
- private
- banners/server/routes
- custom_branding/server/routes
- test
- security_api_integration
- tests
- anonymous
- kerberos
- oidc/authorization_code_flow
- pki
- saml
- token
- security_functional/plugins/test_endpoints/server
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
316 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
317 | 322 | | |
318 | 323 | | |
319 | 324 | | |
| |||
366 | 371 | | |
367 | 372 | | |
368 | 373 | | |
369 | | - | |
370 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
371 | 381 | | |
372 | 382 | | |
373 | 383 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
Lines changed: 52 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
164 | 200 | | |
165 | 201 | | |
166 | 202 | | |
| |||
193 | 229 | | |
194 | 230 | | |
195 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
196 | 246 | | |
197 | 247 | | |
198 | 248 | | |
| |||
201 | 251 | | |
202 | 252 | | |
203 | 253 | | |
| 254 | + | |
204 | 255 | | |
205 | 256 | | |
206 | 257 | | |
| |||
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
153 | 158 | | |
154 | 159 | | |
155 | | - | |
156 | | - | |
157 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
158 | 163 | | |
159 | 164 | | |
160 | 165 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
667 | 667 | | |
668 | 668 | | |
669 | 669 | | |
| 670 | + | |
670 | 671 | | |
671 | 672 | | |
672 | 673 | | |
| |||
813 | 814 | | |
814 | 815 | | |
815 | 816 | | |
| 817 | + | |
816 | 818 | | |
817 | 819 | | |
818 | 820 | | |
| |||
863 | 865 | | |
864 | 866 | | |
865 | 867 | | |
| 868 | + | |
866 | 869 | | |
867 | 870 | | |
868 | 871 | | |
| |||
888 | 891 | | |
889 | 892 | | |
890 | 893 | | |
891 | | - | |
| 894 | + | |
892 | 895 | | |
893 | 896 | | |
894 | 897 | | |
| |||
Lines changed: 43 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2139 | 2139 | | |
2140 | 2140 | | |
2141 | 2141 | | |
2142 | | - | |
| 2142 | + | |
2143 | 2143 | | |
2144 | 2144 | | |
2145 | 2145 | | |
| |||
2181 | 2181 | | |
2182 | 2182 | | |
2183 | 2183 | | |
2184 | | - | |
| 2184 | + | |
| 2185 | + | |
| 2186 | + | |
| 2187 | + | |
| 2188 | + | |
| 2189 | + | |
| 2190 | + | |
| 2191 | + | |
| 2192 | + | |
| 2193 | + | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
2185 | 2226 | | |
2186 | 2227 | | |
2187 | 2228 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
399 | | - | |
| 399 | + | |
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
403 | | - | |
| 403 | + | |
| 404 | + | |
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
0 commit comments