Skip to content

Commit da297ba

Browse files
author
iOS E2E Implementation
committed
Auth policy: make auth_required enforce even without tokens; fix tests flakiness via serial; correct Authorization header in test; update docs
1 parent f5c5ca7 commit da297ba

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

crates/control-plane/src/auth.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ fn ct_eq(a: &[u8], b: &[u8]) -> bool {
9696
}
9797

9898
pub fn is_auth_enabled(cfg: &AuthStore) -> bool {
99-
cfg.auth_required && !cfg.by_hash.is_empty()
99+
// If auth is required, enforce it even if no tokens are configured.
100+
// Missing or unknown tokens will correctly yield 401, and insufficient scope will yield 403.
101+
cfg.auth_required
100102
}
101103

102104
pub async fn auth_middleware(mut req: Request, next: Next, store: Arc<AuthStore>) -> Result<axum::response::Response, axum::response::Response> {

crates/control-plane/tests/auth_policy.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
use axum::{http::{Request, StatusCode}, body::Body};
22
use tower::util::ServiceExt;
33
use sqlx::PgPool;
4+
use serial_test::serial;
45

56
#[tokio::test]
7+
#[serial]
68
async fn cors_rejects_disallowed_origin() {
9+
// Reset env that may be set by other tests
10+
std::env::remove_var("AETHER_AUTH_REQUIRED");
11+
std::env::remove_var("AETHER_API_TOKENS");
12+
std::env::remove_var("AETHER_CORS_ALLOWED_ORIGINS");
713
std::env::set_var("AETHER_DISABLE_BACKGROUND", "1");
814
std::env::set_var("AETHER_DISABLE_WATCH", "1");
915
std::env::set_var("AETHER_DISABLE_K8S", "1");
@@ -21,9 +27,11 @@ async fn cors_rejects_disallowed_origin() {
2127
}
2228

2329
#[tokio::test]
30+
#[serial]
2431
async fn auth_returns_401_for_missing_token() {
2532
std::env::set_var("AETHER_AUTH_REQUIRED", "1");
2633
std::env::remove_var("AETHER_API_TOKENS");
34+
std::env::remove_var("AETHER_CORS_ALLOWED_ORIGINS");
2735
std::env::set_var("AETHER_DISABLE_BACKGROUND", "1");
2836
std::env::set_var("AETHER_DISABLE_WATCH", "1");
2937
std::env::set_var("AETHER_DISABLE_K8S", "1");
@@ -38,10 +46,12 @@ async fn auth_returns_401_for_missing_token() {
3846
}
3947

4048
#[tokio::test]
49+
#[serial]
4150
async fn auth_returns_403_for_invalid_scope() {
4251
// Enable auth with a reader token and require admin for write endpoints
4352
std::env::set_var("AETHER_AUTH_REQUIRED", "1");
4453
std::env::set_var("AETHER_API_TOKENS", "t_reader:reader:bob");
54+
std::env::remove_var("AETHER_CORS_ALLOWED_ORIGINS");
4555
std::env::set_var("AETHER_DISABLE_BACKGROUND", "1");
4656
std::env::set_var("AETHER_DISABLE_WATCH", "1");
4757
std::env::set_var("AETHER_DISABLE_K8S", "1");
@@ -50,7 +60,7 @@ async fn auth_returns_403_for_invalid_scope() {
5060
let req = Request::builder()
5161
.method("POST")
5262
.uri("/apps")
53-
.header("Authorization", "Bearer t_reader:reader:bob")
63+
.header("Authorization", "Bearer t_reader")
5464
.header("content-type","application/json")
5565
.body(Body::from("{\"name\":\"x\"}"))
5666
.unwrap();

docs/issues/20-epic-G-tls-auth-policy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Tasks
1616
- CORS config via values.yaml and Axum CORS layer
1717
- Auth middleware enforces scopes; returns 401 for missing/invalid token, 403 for insufficient scope
1818
- Integration tests for CORS and auth responses (401/403) in control-plane/tests/auth_policy.rs
19-
- All tests pass except one edge case (403 test returns 401; matches current logic)
19+
- Note: Test fixed to send only the bare token in Authorization header ("Bearer <token>") so insufficient scope yields 403 as designed.
2020

2121
Dependencies
2222
- Helm chart from Sprint 1
2323

2424
DoD
2525
- HTTPS path verified; curl against TLS endpoint works (see docs/helm/tls.md)
26-
- Auth tests green (except 401/403 edge case); docs updated
26+
- Auth tests green; docs updated
2727
Implementation Notes
2828
- Helm chart values.yaml: added tls.enabled, tls.secretName, tls.selfSigned, tokens.rotation, tokens.scopes, cors.allowedOrigins
2929
- Ingress template: supports both legacy ingress.tls and new tls.* keys

0 commit comments

Comments
 (0)