Repository navigation
Commit e138559
fix(httpapi): refuse config-to-secret for values that embed a reference (#1782)
## Bug
`POST /api/v1/servers/{id}/config-to-secret` refuses to convert a value
that is already a reference, but the check is `strings.HasPrefix(value,
"${keyring:") || strings.HasPrefix(value, "${env:")`. Two kinds of
values get past it:
- a `${file:/path}` reference (the provider added in #1717);
- a composite value with an embedded reference, such as the documented
`"Authorization": "Bearer ${keyring:github-token}"`
(`docs/features/keyring-integration.md`).
For these values the handler stores the literal text in the keyring and
rewrites the field to `${keyring:<secret_name>}`. Secret expansion runs
once, so on the next connect the upstream gets the unresolved text, for
example `Bearer ${keyring:github-token}` or
`${file:/run/secrets/github-token}`, as its credential.
The API masks both values on the read path because `IsConfigReference`
only passes through an exact `${keyring:..}` or `${env:..}` value. The
UI therefore shows them as plain secrets and offers Convert-to-secret.
## Trigger
```json
"headers": {"Authorization": "Bearer ${keyring:github-token}"}
```
`POST /api/v1/servers/<name>/config-to-secret` with
`{"scope":"header","key":"Authorization","secret_name":"gh2"}` succeeds.
After that, the header sent upstream is the literal `Bearer
${keyring:github-token}`.
## Fix
Use `secret.IsSecretRef(value)`, which matches any `${type:name}`
reference anywhere in the value. The handler then returns the existing
400 "already a reference" error for these values.
## Test
Two cases added to `TestHandleConvertConfigToSecret_ValidationErrors`:
an env value `${file:/run/secrets/github-token}` and a header `Bearer
${keyring:github-token}`. Both must be rejected with 400 before the
resolver is called.
## Commands run
- `CGO_ENABLED=0 go test -count=1 ./internal/httpapi`: ok
- With `server.go` reverted, both new cases fail (`expected: 400,
actual: 500`). The handler gets past validation and reaches the
resolver, which the mock leaves nil.
- `go vet ./internal/httpapi`, `gofmt -l internal/httpapi/`: clean
---------
Co-authored-by: Algis Dumbris <a.dumbris@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 95837ad commit e138559
2 files changed
Lines changed: 42 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
412 | 412 | | |
413 | 413 | | |
414 | 414 | | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| |||
476 | 477 | | |
477 | 478 | | |
478 | 479 | | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
479 | 511 | | |
480 | 512 | | |
481 | 513 | | |
| |||
504 | 536 | | |
505 | 537 | | |
506 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
507 | 542 | | |
508 | 543 | | |
509 | 544 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3169 | 3169 | | |
3170 | 3170 | | |
3171 | 3171 | | |
3172 | | - | |
3173 | | - | |
| 3172 | + | |
| 3173 | + | |
3174 | 3174 | | |
3175 | 3175 | | |
3176 | 3176 | | |
| |||
0 commit comments