feat: refresh console for QA and refresh-only access (auth M6d)
- web: Refresh console (relation cards, overwrite confirmation, progress, cancel, distinct failure messages), rail item, and a single-screen view for people who may only refresh - hub: refresh-only users are authorized; /me exposes refresh_relations - docs and auth plan record the real rehearsal (Postgres, agent, Keycloak, browser) and what was not verified Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -673,3 +673,22 @@ async fn a_target_that_is_the_source_or_a_production_database_is_refused_when_th
|
||||
assert_eq!(lab.run(&run).blocked_reason.as_deref(), Some("target_matches_a_production_source"));
|
||||
assert_eq!(lab.restore_jobs(), 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn someone_who_may_only_refresh_gets_into_the_app_but_sees_nothing_else() {
|
||||
let lab = fresh().await;
|
||||
let nobody = lab.person("nobody");
|
||||
let status = lab.send(&nobody, "GET", "/api/v1/operator/session", None).await.1;
|
||||
assert_eq!((status["authorized"].clone(), status["admin"].clone()), (json!(false), json!(false)), "no grant at all: closed");
|
||||
let (qa, _) = lab.refresher("qa");
|
||||
let status = lab.send(&qa, "GET", "/api/v1/operator/session", None).await.1;
|
||||
assert_eq!((status["authorized"].clone(), status["admin"].clone()), (json!(true), json!(false)), "a relation grant opens the app");
|
||||
let me = lab.send(&qa, "GET", "/api/v1/me", None).await.1;
|
||||
assert_eq!(me["refresh_relations"], json!([lab.relation.clone()]));
|
||||
assert_eq!(me["grants"].as_array().unwrap().len(), 0, "and carries no orbit permission");
|
||||
// nothing about orbits, snapshots or restores is visible to them
|
||||
for path in ["/api/v1/orbits", "/api/v1/snapshots", "/api/v1/capture-jobs", "/api/v1/restore-jobs", "/api/v1/relations"] {
|
||||
assert_eq!(lab.send(&qa, "GET", path, None).await.0, StatusCode::FORBIDDEN, "{path}");
|
||||
}
|
||||
assert_eq!(lab.send(&qa, "GET", "/api/v1/refresh-relations", None).await.0, StatusCode::OK);
|
||||
}
|
||||
|
||||
@@ -43,11 +43,14 @@ async fn status(
|
||||
let browser = state.sessions.active(&headers);
|
||||
// The app opens for an administrator or for anyone holding a live grant that lets them read an orbit.
|
||||
let reads_something = browser.as_ref().is_some_and(|session| {
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
!session.admin
|
||||
&& state
|
||||
&& (state
|
||||
.db
|
||||
.permitted_orbits(Some(&session.user_id), &session.groups, "orbit.read", chrono::Utc::now().timestamp())
|
||||
.permitted_orbits(Some(&session.user_id), &session.groups, "orbit.read", now)
|
||||
.is_ok_and(|p| p.everywhere || !p.orbits.is_empty())
|
||||
// someone who may only refresh a staging database still gets in, to that one screen
|
||||
|| state.db.granted_relations(Some(&session.user_id), &session.groups, now).is_ok_and(|r| !r.is_empty()))
|
||||
});
|
||||
let authorized = browser.as_ref().is_some_and(|session| session.admin) || reads_something
|
||||
|| (browser.is_none() && !state.sessions.enabled() && state.admin.token.is_none()
|
||||
@@ -82,6 +85,8 @@ struct Me {
|
||||
admin: bool,
|
||||
capabilities: Vec<String>,
|
||||
grants: Vec<MyGrant>,
|
||||
/// Ids of the relations this person may refresh through (everything, for an administrator).
|
||||
refresh_relations: Vec<String>,
|
||||
}
|
||||
|
||||
/// The caller's own identity. Every authenticated principal is an administrator
|
||||
@@ -113,9 +118,17 @@ async fn me(
|
||||
names
|
||||
};
|
||||
capabilities.sort();
|
||||
let refresh_relations = if actor.subject.admin {
|
||||
vec![]
|
||||
} else {
|
||||
state
|
||||
.db
|
||||
.granted_relations(actor.subject.user_id.as_deref(), &actor.subject.groups, chrono::Utc::now().timestamp())
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
};
|
||||
Ok((
|
||||
no_store(),
|
||||
Json(Me { id, kind, auth_method, display_name: actor.name.clone(), admin: actor.subject.admin, capabilities, grants }),
|
||||
Json(Me { id, kind, auth_method, display_name: actor.name.clone(), admin: actor.subject.admin, capabilities, grants, refresh_relations }),
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user