Skip to content

Commit 0272aa6

Browse files
committed
kbs/admin: add insecure_header_jwk configuration
Usually the admin token carried by the client will have a JWK header in the token. If this is the case, `insecure_header_jwk` will control whether the endorsement of the key will be checked. Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
1 parent 1c37635 commit 0272aa6

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

kbs/docs/admin.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ This lets you keep identity issuance external while keeping KBS-side authorizati
8080

8181
- `identity_providers` (array): list of trusted identity providers
8282
- `insecure_public_key_from_uri` (optional bool, default `false`): allow fetching`public_key_uri` and `jwk_set_uri` over `http://`
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ For `authorization_mode = "AuthenticatedAuthorization"`, configure:
199199
|----------|------|-------------|----------|---------|
200200
| `identity_providers` | Array | Trusted issuer entries for JWT verification | No | Empty |
201201
| `insecure_public_key_from_uri` | Boolean | Allow loading `public_key_uri` and `jwk_set_uri` via plaintext `http://` | No | `false` |
202+
| `insecure_header_jwk` | Boolean | Skip endorsement checks for header-embedded JWK keys. Signature is still verified; use only in controlled test environments. | No | `false` |
202203

203204
Each `identity_providers` item:
204205

kbs/src/admin/authentication/bearer_jwt.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@ use crate::crypto::jwt::JwtVerifier;
1818
#[serde(default, deny_unknown_fields)]
1919
pub struct BearerJwtConfig {
2020
pub identity_providers: Vec<IssuerConfig>,
21+
2122
/// Allow loading admin PEM keys/keysets from insecure HTTP sources.
2223
/// Keep disabled by default and only enable in controlled environments.
2324
pub insecure_public_key_from_uri: bool,
25+
26+
/// Whether to skip endorsement checks of header-embedded JWK keys.
27+
/// Signature is still verified.
28+
/// This should only be set to true for testing.
29+
///
30+
/// When false, the key must be endorsed by one of the the
31+
/// `public_key_uri` or `jwk_set_uri` specified in the `identity_providers` field.
32+
pub insecure_header_jwk: bool,
2433
}
2534

2635
/// Issuer config used to verify admin JWT tokens.
2736
///
2837
/// - `public_key_uri`: a PEM file source (`https://`, `file://`, local path,
2938
/// or `http://` when `insecure_public_key_from_uri=true`)
30-
/// - `jwk_set_uri`: a JWKS source (https://, file:// or local path)
39+
/// - `jwk_set_uri`: a JWKS source (`https://`, `file://`, local path,
40+
/// or `http://` when `insecure_public_key_from_uri=true`)
3141
/// - `issuer`: the issuer of the JWT token. If given, This field will be checked when a token is verified successfully
3242
/// with given public key or JWKS. If the token's issuer is matched, the token will be verified successfully.
3343
/// - `audience`: the audience of the JWT token. If given, This field will be checked when a token is verified successfully
@@ -72,7 +82,7 @@ impl BearerJwtTokenVerifier {
7282
&trusted_jwk_set_uris,
7383
&[],
7484
&trusted_pem_public_key_uris,
75-
false,
85+
config.insecure_header_jwk,
7686
config.insecure_public_key_from_uri,
7787
)
7888
.await
@@ -176,3 +186,32 @@ fn claims_from_value(value: Value) -> Result<Claims> {
176186

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

0 commit comments

Comments
 (0)