Commit bf18263
Add currentRole to Health Summary Report at /health (#3158)
## Why make this change?
Adds `currentRole` to the `/health` endpoint response to surface the
effective role of the requesting user, enabling easier authentication
testing without needing external tooling to inspect request headers.
## What is this change?
- **`ComprehensiveHealthCheckReport`**: New `currentRole` string
property (JSON: `"currentRole"`) inserted after `timestamp` in the
report header.
- **`HealthCheckHelper.ReadRoleHeaders(HttpContext)`**: Replaces the
former `StoreIncomingRoleHeader` method. Instead of writing to mutable
instance fields on the singleton, it returns a `(roleHeader, roleToken)`
tuple that the caller holds as request-local values, eliminating a race
condition under concurrent requests.
- **`HealthCheckHelper.GetCurrentRole(roleHeader, roleToken)`**:
Determines the effective role using a three-way fallback: explicit
`X-MS-API-ROLE` header → `"authenticated"` (if a bearer token is present
via `X-MS-CLIENT-PRINCIPAL`) → `"anonymous"`. This correctly handles
authenticated users who provide a bearer token without an explicit role
header.
- **`HealthCheckHelper.IsUserAllowedToAccessHealthCheck` /
`GetHealthCheckResponseAsync`**: Updated to accept
`roleHeader`/`roleToken` as explicit parameters; the values flow down
the entire private call chain (`UpdateHealthCheckDetailsAsync` →
`UpdateEntityHealthCheckResultsAsync` → `PopulateEntityHealthAsync` →
`ExecuteRestEntityQueryAsync` / `ExecuteGraphQlEntityQueryAsync`) so no
per-request state is stored on the singleton.
- **`ComprehensiveHealthReportResponseWriter`**: Reads role headers once
per request into locals, passes them through all downstream calls, and
stamps `currentRole` per-request **after** cache retrieval (using a
non-destructive `with` expression) so cached responses never leak one
caller's role to another request. The cache now stores the
`ComprehensiveHealthCheckReport` object (without `currentRole`) rather
than a serialized string.
> **Access control note**: `IsUserAllowedToAccessHealthCheck` checks
`allowedRoles` against the explicit `X-MS-API-ROLE` header value only —
matching DAB's existing authorization policy where clients must
explicitly claim a role via the header.
Example response shape:
```json
{
"status": "Healthy",
"version": "1.x.x",
"app-name": "dab_oss_1.x.x",
"timestamp": "2026-02-24T22:28:30Z",
"currentRole": "authenticated",
"configuration": { ... },
"checks": [ ... ]
}
```
## How was this tested?
- [ ] Integration Tests
- [x] Unit Tests
Unit tests added to `HealthCheckUtilitiesUnitTests.cs` covering all key
scenarios:
- `GetCurrentRole_NoHeaders_ReturnsAnonymous` — no auth headers →
`anonymous`
- `GetCurrentRole_BearerTokenOnly_ReturnsAuthenticated` — bearer token,
no role header → `authenticated`
- `GetCurrentRole_ExplicitRoleHeader_ReturnsHeaderValue` — explicit
`X-MS-API-ROLE` → exact header value
- `GetCurrentRole_BothHeaderAndToken_RoleHeaderWins` — role header takes
priority over bearer token
-
`GetCurrentRole_CacheDoesNotLeakRole_DifferentCallersGetDifferentRoles`
— sequential calls with different inputs each return the correct role,
confirming no cross-request state
- `GetCurrentRole_ParallelRequests_NoRoleBleed` — 50 concurrent tasks
each with a unique role return exactly their own role with no bleed
- `ReadRoleHeaders_WithRoleHeader_ReturnsRoleHeader` /
`ReadRoleHeaders_NoHeaders_ReturnsEmpty` — validates header extraction
## Sample Request(s)
```http
GET /health
X-MS-API-ROLE: myrole
```
Response includes `"currentRole": "myrole"`.
```http
GET /health
X-MS-CLIENT-PRINCIPAL: <base64-token>
```
Response includes `"currentRole": "authenticated"` (bearer token
present, no explicit role header).
```http
GET /health
```
Response includes `"currentRole": "anonymous"` (no role header, no
bearer token).
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>[Enh]: Add to Health Summary</issue_title>
> <issue_description>## What?
>
> 1. Add to the header part of the Health Summary Report returned at
/health a scalar property "currentRole" which returns the current role
"anonymous", "authenticated", etc.
>
> ## Why?
>
> To help with authentication testing.</issue_description>
>
> <agent_instructions>with as little new code as
possible</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #3157
<!-- START COPILOT CODING AGENT TIPS -->
---
🔒 GitHub Advanced Security automatically protects Copilot coding agent
pull requests. You can protect all pull requests by enabling Advanced
Security for your repositories. [Learn more about Advanced
Security.](https://gh.io/cca-advanced-security)
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: JerryNixon <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Aniruddh Munde <[email protected]>1 parent a7c1be3 commit bf18263
4 files changed
Lines changed: 206 additions & 50 deletions
File tree
- src
- Service.Tests/UnitTests
- Service/HealthCheck
- Model
Lines changed: 151 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
| |||
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 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 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
153 | 304 | | |
154 | 305 | | |
Lines changed: 15 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
79 | | - | |
80 | | - | |
| 78 | + | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
85 | 84 | | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
89 | 87 | | |
90 | 88 | | |
91 | 89 | | |
| 90 | + | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
| 93 | + | |
95 | 94 | | |
96 | | - | |
| 95 | + | |
97 | 96 | | |
98 | | - | |
| 97 | + | |
99 | 98 | | |
100 | | - | |
| 99 | + | |
101 | 100 | | |
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
107 | | - | |
108 | 106 | | |
109 | 107 | | |
110 | 108 | | |
111 | 109 | | |
112 | | - | |
| 110 | + | |
113 | 111 | | |
114 | | - | |
115 | | - | |
| 112 | + | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
| |||
124 | 122 | | |
125 | 123 | | |
126 | 124 | | |
127 | | - | |
| 125 | + | |
128 | 126 | | |
129 | | - | |
| 127 | + | |
130 | 128 | | |
131 | 129 | | |
132 | 130 | | |
| |||
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | | - | |
| 140 | + | |
143 | 141 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 142 | + | |
| 143 | + | |
149 | 144 | | |
150 | 145 | | |
151 | 146 | | |
0 commit comments