Skip to content

Commit 0e9230b

Browse files
Xynnn007cursoragent
andcommitted
kbs/admin: add insecure_header_jwk configuration
Add insecure_header_jwk to bearer_jwt to control whether header-embedded JWK keys must be endorsed via x5c before verifying admin JWT signatures. Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
1 parent 3102515 commit 0e9230b

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

kbs/docs/admin.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ This lets you keep identity issuance external while keeping KBS-side authorizati
7979
`[admin.authentication.bearer_jwt]` accepts:
8080

8181
- `identity_providers` (array): list of trusted identity providers
82-
- `insecure_public_key_from_uri` (optional bool, default `false`): allow fetching verification keys over plaintext `http://`
82+
- `insecure_public_key_from_uri` (optional bool, default `false`): allow fetching verification keys over plaintext `http://`. Applies to configured `public_key_uri` and `jwk_set_uri` values, and to any `jwks_uri` returned by OpenID discovery for remote `jwk_set_uri` entries
83+
- `insecure_header_jwk` (optional bool, default `false`): skip endorsement checks for JWT header-embedded JWK keys (signature is still verified, testing only)
8384

8485
Each `identity_providers` entry:
8586

kbs/docs/config.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ For `authorization_mode = "AuthenticatedAuthorization"`, configure:
276276
| Property | Type | Description | Required | Default |
277277
|----------|------|-------------|----------|---------|
278278
| `identity_providers` | Array | Trusted issuer entries for JWT verification | No | Empty |
279-
| `insecure_public_key_from_uri` | Boolean | Allow loading admin verification keys via plaintext `http://` | No | `false` |
279+
| `insecure_public_key_from_uri` | Boolean | Allow loading admin verification keys via plaintext `http://`. Applies to configured URIs and any `jwks_uri` returned by OpenID discovery for remote `jwk_set_uri` entries. | No | `false` |
280+
| `insecure_header_jwk` | Boolean | Skip endorsement checks for header-embedded JWK keys. Signature is still verified; use only in controlled test environments. | No | `false` |
280281

281282
Each `identity_providers` item:
282283

kbs/src/admin/authentication/bearer_jwt.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ pub struct BearerJwtConfig {
2121

2222
/// Allow loading admin verification keys over plaintext HTTP.
2323
///
24-
/// When false, any HTTP fetch for key material is rejected. Keep disabled by default and only
25-
/// enable in controlled environments.
24+
/// When false, any HTTP fetch for key material is rejected: configured `public_key_uri`
25+
/// and `jwk_set_uri` values, and any `jwks_uri` returned by OpenID discovery for remote
26+
/// `jwk_set_uri` entries. Keep disabled by default and only enable in controlled environments.
2627
pub insecure_public_key_from_uri: bool,
28+
29+
/// Whether to skip endorsement checks of header-embedded JWK keys.
30+
/// Signature is still verified.
31+
/// This should only be set to true for testing.
32+
///
33+
/// When false, header-embedded `jwk` keys must include an `x5c` certificate chain
34+
/// that can be validated against configured trusted certificates (if any).
35+
pub insecure_header_jwk: bool,
2736
}
2837

2938
/// Issuer config used to verify admin JWT tokens.
@@ -77,7 +86,7 @@ impl BearerJwtTokenVerifier {
7786
&trusted_jwk_set_uris,
7887
&[],
7988
&trusted_pem_public_key_uris,
80-
false,
89+
config.insecure_header_jwk,
8190
config.insecure_public_key_from_uri,
8291
)
8392
.await
@@ -181,3 +190,32 @@ fn claims_from_value(value: Value) -> Result<Claims> {
181190

182191
Ok(Claims { role })
183192
}
193+
194+
#[cfg(test)]
195+
mod tests {
196+
use super::BearerJwtConfig;
197+
198+
#[test]
199+
fn deserialize_insecure_header_jwk_true() {
200+
let config: BearerJwtConfig = toml::from_str(
201+
r#"
202+
insecure_public_key_from_uri = true
203+
insecure_header_jwk = true
204+
identity_providers = [
205+
{ issuer = "admin", public_key_uri = "/etc/kbs-admin.pub" },
206+
]
207+
"#,
208+
)
209+
.expect("valid bearer_jwt config");
210+
211+
assert!(config.insecure_header_jwk);
212+
assert!(config.insecure_public_key_from_uri);
213+
assert_eq!(config.identity_providers.len(), 1);
214+
}
215+
216+
#[test]
217+
fn default_insecure_header_jwk_false() {
218+
let config = BearerJwtConfig::default();
219+
assert!(!config.insecure_header_jwk);
220+
}
221+
}

0 commit comments

Comments
 (0)