feat: require authentication and own uploads per Outpost (auth M0)
- auth is mandatory by default, including loopback and local proxies; startup refuses a hub with no credentials; TESSERA_LOCAL_DEVELOPMENT is explicit and loopback-only - legacy uploads are bound to an owning Outpost (PUT /api/v1/orbits/:id/outpost); unowned orbits and sessions fail closed - typed Principal and payload-free audit_events table - endpoint authorization contract with tests comparing it to the router - A00 compatibility spike (tests/auth-compat) and library research - archive the superseded A00-A25 plan Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1
tests/auth-compat/.gitignore
vendored
Normal file
1
tests/auth-compat/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target/
|
||||
3402
tests/auth-compat/Cargo.lock
generated
Normal file
3402
tests/auth-compat/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
27
tests/auth-compat/Cargo.toml
Normal file
27
tests/auth-compat/Cargo.toml
Normal file
@@ -0,0 +1,27 @@
|
||||
[package]
|
||||
name = "tessera-auth-compat"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.88"
|
||||
publish = false
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
# Isolated spike: no auth dependency enters the application until A00 passes.
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
|
||||
[dependencies]
|
||||
async-trait = "0.1"
|
||||
axum = "=0.7.9"
|
||||
tower = { version = "0.5", features = ["util"] }
|
||||
tokio = { version = "=1.40.0", features = ["full"] }
|
||||
rusqlite = { version = "=0.31.0", features = ["bundled"] }
|
||||
sha2 = "=0.10.8"
|
||||
serde_json = "1"
|
||||
time = "=0.3.47"
|
||||
tower-sessions = { version = "=0.15.0", default-features = false }
|
||||
openidconnect = { version = "=4.1.0", default-features = false, features = ["reqwest", "rustls-tls"] }
|
||||
governor = { version = "=0.10.4", default-features = false, features = ["std"] }
|
||||
async-compression = { version = "=0.4.36", default-features = false, features = ["tokio", "gzip"] }
|
||||
casbin = { version = "=2.10.1", default-features = false, features = ["runtime-tokio"] }
|
||||
rusqlite_migration = "=1.2.0"
|
||||
116
tests/auth-compat/README.md
Normal file
116
tests/auth-compat/README.md
Normal file
@@ -0,0 +1,116 @@
|
||||
# A00 compatibility spike
|
||||
|
||||
Evidence date: 11 November 2026. **Compatibility demonstrated; A00 acceptance
|
||||
still open. This crate is not runtime authentication and does not prove OIDC
|
||||
token validation, end-to-end revocation, or the self-service stories.**
|
||||
|
||||
Run from the repository root:
|
||||
|
||||
```sh
|
||||
rtk proxy env CARGO_TARGET_DIR=target/auth-compat cargo test --locked --manifest-path tests/auth-compat/Cargo.toml
|
||||
rtk cargo tree --manifest-path tests/auth-compat/Cargo.toml -i libsqlite3-sys
|
||||
rtk cargo audit --file tests/auth-compat/Cargo.lock
|
||||
```
|
||||
|
||||
The separate workspace/lockfile prevents experimental libraries entering the hub.
|
||||
Keep this executable evidence until production implementations replace its tests.
|
||||
No SQLx, second SQLite pool, external policy service, or workflow engine is used.
|
||||
|
||||
## Tested candidates
|
||||
|
||||
| Crate | Exact version | Features | Declared MSRV | License |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| openidconnect | 4.1.0 | reqwest,rustls-tls; defaults off | 1.88 | MIT |
|
||||
| reqwest | 0.12.28 (resolved) | OIDC feature closure | 1.64 | MIT OR Apache-2.0 |
|
||||
| tower-sessions | 0.15.0 | defaults off | unspecified | MIT |
|
||||
| governor | 0.10.4 | std; defaults off | unspecified | MIT |
|
||||
| async-compression | 0.4.36 | tokio,gzip; defaults off | unspecified | MIT OR Apache-2.0 |
|
||||
| casbin | 2.10.1 | runtime-tokio; defaults off | unspecified | Apache-2.0 |
|
||||
| rusqlite_migration | 1.2.0 | defaults only | 1.70 | Apache-2.0 |
|
||||
| time | 0.3.47 | defaults | 1.88 | MIT OR Apache-2.0 |
|
||||
| rustls | 0.23.46 (resolved) | reqwest feature closure | 1.71 | Apache-2.0 OR ISC OR MIT |
|
||||
|
||||
All six tests pass with local `rustc 1.88.0` on aarch64-apple-darwin, Axum 0.7.9,
|
||||
Tower 0.5.3, Tokio 1.40.0, rusqlite 0.31.0. No Linux image build was run.
|
||||
Unspecified MSRV is not assumed: the locked dependency graph was compiled.
|
||||
Declared licenses were inspected through `cargo info` and target-filtered
|
||||
`cargo metadata`; cargo-deny has **not** been run, so this is not license clearance.
|
||||
|
||||
Tower 0.5 works with current session middleware using Axum 0.7's
|
||||
`Extension<Session>`. Disable tower-sessions' Axum extractor feature. tower-cookies
|
||||
still brings axum-core 0.5.6 alongside Axum's 0.4.5, but the actual router/layer
|
||||
test passes: their extractor traits are not mixed. Do not upgrade Axum solely
|
||||
to obtain the session extractor. Only one libsqlite3-sys (0.28.0) resolves, including
|
||||
the migration helper. An Axum major upgrade and an ORM have not been justified.
|
||||
|
||||
## Checks and limits
|
||||
|
||||
- SQLite SessionStore: collision regeneration, digest-only key and data-only JSON
|
||||
(never serialize Record containing the bearer ID), rotation invalidates old ID,
|
||||
auth deadline survives rotation, idle/absolute expiry, stale save after delete
|
||||
cannot recreate a revoked row. UPDATE-only save is essential. This spike uses
|
||||
an in-memory SQLite connection, not durable hub sessions or a fake-clock suite.
|
||||
- Production A07 must additionally bind sessions to active users and an
|
||||
authoritative revocation generation/deadline: concurrent rotation/create can
|
||||
otherwise create a new record after a bulk revoke. The spike does not prove
|
||||
that stronger property. Do not copy it unchanged into runtime.
|
||||
- Same 14-row exact actor/resource/action matrix for Casbin and SQLite grants:
|
||||
no grant, reverse/unrelated relation, QA capture/download separation,
|
||||
developer scope, service, Outpost, admin, anonymous and unknown action. Both
|
||||
pass; removal denies on the next evaluation. Expiry/group/user-active/domain
|
||||
safety guards still belong in A11 tests.
|
||||
- Prefer typed permission + direct SQL grants for the fixed permission set.
|
||||
Casbin still requires SQL persistence, reload/invalidation, list filtering and
|
||||
domain guards, while the exact-scope query already implements this evaluator.
|
||||
The prototype does not justify a new policy source/cache. Casbin is rejected
|
||||
for runtime; this old comparison candidate also resolves unmaintained
|
||||
smartstring. It is not a recommendation to ship casbin 2.10.1.
|
||||
- governor keyed quota rejects source A's second request without consuming B's
|
||||
quota. Semaphore admission and trusted-source extraction are A08 work.
|
||||
- gzip magic, decompression and exact synthetic SQL bytes pass. Not an export
|
||||
quota, memory, disconnect or disk-full benchmark (A21).
|
||||
- OIDC HTTP client builds with redirects disabled and S256 PKCE. Discovery,
|
||||
claims, signed fixtures, JWKS rotation/outage, nonce/state replay and IdP
|
||||
browser verification remain A09/A25 work, not covered by this smoke test.
|
||||
- rusqlite_migration can use the same Connection and advance user_version.
|
||||
Production already has idempotent migrations; retain those until a numbered
|
||||
baseline migration is designed in A24. No helper enters runtime yet.
|
||||
|
||||
## Audit evidence and release blockers
|
||||
|
||||
`cargo-audit 0.21.2` could not parse current RustSec CVSS 4 records. A temporary
|
||||
0.22.0 installation (MSRV 1.85) under `/tmp/tessera-auth-tools` successfully
|
||||
audited both lockfiles. No advisory ignore or weakened validation was added.
|
||||
|
||||
Initial baseline audit: **10 vulnerabilities**, plus two unmaintained warnings
|
||||
and two Tokio unsound warnings. Initial spike: **12 vulnerabilities**. Updating
|
||||
only the spike's resolved rustls/webpki to 0.23.46/0.103.16 and pinning time 0.3.47
|
||||
removed its TLS/time findings; six tests still pass. Final spike still reports:
|
||||
|
||||
- [RUSTSEC-2026-0459](https://rustsec.org/advisories/RUSTSEC-2026-0459.html):
|
||||
bundled SQLite via libsqlite3-sys 0.28.0; patched binding >=0.39.0.
|
||||
- [RUSTSEC-2023-0071](https://rustsec.org/advisories/RUSTSEC-2023-0071.html):
|
||||
RSA 0.9.10, patched >=0.10.0. openidconnect 4.1.0 still depends on 0.9.
|
||||
Tessera's intended RP uses public-key verification, not RSA private-key
|
||||
decryption/signing; document reachability before any narrowly scoped exception.
|
||||
Do not silently suppress it or write a replacement verifier.
|
||||
- Tokio 1.40.0 unsound warnings: RUSTSEC-2025-0023 and RUSTSEC-2026-0386;
|
||||
a common patched branch is 1.51.6 (MSRV 1.71).
|
||||
|
||||
Workspace runtime TLS is **still** rustls 0.23.23/webpki 0.102.8 with its baseline
|
||||
findings: RUSTSEC-2026-0346, -0285, -0348, -0349; webpki -0104, -0098, -0099,
|
||||
-0049, -0382. The runtime manifest/lockfile was deliberately not changed by this
|
||||
isolated experiment. Existing unmaintained warnings concern proc-macro-error and
|
||||
rustls-pemfile. Release approval requires triage/remediation, not merely compilation.
|
||||
|
||||
Further A00 work: prove a patched SQLite baseline, test required upgrades across
|
||||
workspace and old DBs, resolve/triage RSA and Tokio, run cargo-deny, and re-audit.
|
||||
rusqlite 0.41.1 declares Rust 1.89, while libsqlite3-sys 0.39.0 declares 1.88;
|
||||
do not assume the current compiler or migration helper supports the upgrade.
|
||||
Record a separate compiler/binding migration slice if needed. No runtime auth
|
||||
library has been selected as release-ready until these checks pass.
|
||||
|
||||
Primary API references were fetched through Context7:
|
||||
`/ramosbugs/openidconnect-rs`, `/maxcountryman/tower-sessions`, `/apache/casbin-rs`.
|
||||
Published package manifests/metadata and RustSec were checked directly; versions
|
||||
were not selected solely from a `latest` documentation URL.
|
||||
363
tests/auth-compat/src/lib.rs
Normal file
363
tests/auth-compat/src/lib.rs
Normal file
@@ -0,0 +1,363 @@
|
||||
//! Executable A00 experiments, not production authentication.
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use async_trait::async_trait;
|
||||
use rusqlite::{params, Connection, OptionalExtension};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use time::{Duration, OffsetDateTime};
|
||||
use tower_sessions::{
|
||||
session::{Id, Record},
|
||||
session_store, Session, SessionStore,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct Store(Arc<Mutex<Connection>>);
|
||||
|
||||
fn digest(id: &Id) -> Vec<u8> {
|
||||
Sha256::digest(id.to_string().as_bytes()).to_vec()
|
||||
}
|
||||
|
||||
impl Store {
|
||||
fn new() -> Self {
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE sessions (
|
||||
digest BLOB PRIMARY KEY, data TEXT NOT NULL,
|
||||
idle INTEGER NOT NULL, absolute INTEGER NOT NULL
|
||||
)",
|
||||
)
|
||||
.unwrap();
|
||||
Self(Arc::new(Mutex::new(conn)))
|
||||
}
|
||||
}
|
||||
|
||||
fn backend(e: rusqlite::Error) -> session_store::Error {
|
||||
session_store::Error::Backend(e.to_string())
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SessionStore for Store {
|
||||
async fn create(&self, record: &mut Record) -> session_store::Result<()> {
|
||||
let conn = self.0.lock().unwrap();
|
||||
let absolute = record
|
||||
.data
|
||||
.entry("auth_deadline".into())
|
||||
.or_insert_with(|| {
|
||||
serde_json::json!(
|
||||
(OffsetDateTime::now_utc() + Duration::hours(8)).unix_timestamp()
|
||||
)
|
||||
})
|
||||
.as_i64()
|
||||
.expect("server-owned auth deadline");
|
||||
loop {
|
||||
// Serialize only data: Record contains the raw bearer ID.
|
||||
let inserted = conn.execute(
|
||||
"INSERT INTO sessions VALUES (?1, ?2, ?3, ?4) ON CONFLICT(digest) DO NOTHING",
|
||||
params![digest(&record.id), serde_json::to_string(&record.data).unwrap(),
|
||||
record.expiry_date.unix_timestamp(),
|
||||
absolute],
|
||||
).map_err(backend)?;
|
||||
if inserted == 1 {
|
||||
return Ok(());
|
||||
}
|
||||
record.id = Id::default();
|
||||
}
|
||||
}
|
||||
|
||||
async fn save(&self, record: &Record) -> session_store::Result<()> {
|
||||
// UPDATE only: a stale in-flight request must never resurrect a revoked row.
|
||||
let changed = self
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.execute(
|
||||
"UPDATE sessions SET data = ?2, idle = MIN(?3, absolute)
|
||||
WHERE digest = ?1 AND idle > ?4 AND absolute > ?4",
|
||||
params![
|
||||
digest(&record.id),
|
||||
serde_json::to_string(&record.data).unwrap(),
|
||||
record.expiry_date.unix_timestamp(),
|
||||
OffsetDateTime::now_utc().unix_timestamp()
|
||||
],
|
||||
)
|
||||
.map_err(backend)?;
|
||||
if changed == 0 {
|
||||
return Err(session_store::Error::Backend("revoked or expired".into()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load(&self, id: &Id) -> session_store::Result<Option<Record>> {
|
||||
let row: Option<(String, i64)> = self
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.query_row(
|
||||
"SELECT data, MIN(idle, absolute) FROM sessions
|
||||
WHERE digest = ?1 AND idle > ?2 AND absolute > ?2",
|
||||
params![digest(id), OffsetDateTime::now_utc().unix_timestamp()],
|
||||
|r| Ok((r.get(0)?, r.get(1)?)),
|
||||
)
|
||||
.optional()
|
||||
.map_err(backend)?;
|
||||
Ok(row.map(|(data, expiry)| Record {
|
||||
id: *id,
|
||||
data: serde_json::from_str(&data).unwrap(),
|
||||
expiry_date: OffsetDateTime::from_unix_timestamp(expiry).unwrap(),
|
||||
}))
|
||||
}
|
||||
|
||||
async fn delete(&self, id: &Id) -> session_store::Result<()> {
|
||||
self.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.execute("DELETE FROM sessions WHERE digest = ?1", [digest(id)])
|
||||
.map_err(backend)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn record() -> Record {
|
||||
Record {
|
||||
id: Id::default(),
|
||||
data: Default::default(),
|
||||
expiry_date: OffsetDateTime::now_utc() + Duration::minutes(30),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn session_collision_digest_rotation_expiry_and_revoke() {
|
||||
let store = Store::new();
|
||||
let mut first = record();
|
||||
let deadline = (OffsetDateTime::now_utc() + Duration::minutes(5)).unix_timestamp();
|
||||
first
|
||||
.data
|
||||
.insert("auth_deadline".into(), serde_json::json!(deadline));
|
||||
store.create(&mut first).await.unwrap();
|
||||
let mut collision = first.clone();
|
||||
store.create(&mut collision).await.unwrap();
|
||||
assert_ne!(first.id, collision.id);
|
||||
let raw: String = store
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.query_row(
|
||||
"SELECT group_concat(hex(digest) || data) FROM sessions",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(!raw.contains(&first.id.to_string()));
|
||||
|
||||
let session = Session::new(Some(first.id), Arc::new(store.clone()), None);
|
||||
session.insert("actor", "qa").await.unwrap();
|
||||
session.cycle_id().await.unwrap();
|
||||
session.save().await.unwrap();
|
||||
assert_ne!(session.id().unwrap(), first.id);
|
||||
assert!(store.load(&first.id).await.unwrap().is_none());
|
||||
assert_eq!(session.get::<String>("actor").await.unwrap().unwrap(), "qa");
|
||||
let rotated_deadline: i64 = store
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.query_row(
|
||||
"SELECT absolute FROM sessions WHERE digest=?1",
|
||||
[digest(&session.id().unwrap())],
|
||||
|r| r.get(0),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
rotated_deadline, deadline,
|
||||
"rotation must not extend absolute auth lifetime"
|
||||
);
|
||||
|
||||
let stale = store.load(&session.id().unwrap()).await.unwrap().unwrap();
|
||||
store.delete(&stale.id).await.unwrap();
|
||||
assert!(store.save(&stale).await.is_err());
|
||||
assert!(store.load(&stale.id).await.unwrap().is_none());
|
||||
for column in ["idle", "absolute"] {
|
||||
let mut r = record();
|
||||
store.create(&mut r).await.unwrap();
|
||||
store
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.execute(
|
||||
&format!("UPDATE sessions SET {column} = 0 WHERE digest = ?1"),
|
||||
[digest(&r.id)],
|
||||
)
|
||||
.unwrap();
|
||||
assert!(store.load(&r.id).await.unwrap().is_none());
|
||||
assert!(store.save(&r).await.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn axum_07_accepts_current_session_layer_without_axum_extractor_feature() {
|
||||
use axum::{
|
||||
body::{to_bytes, Body},
|
||||
http::Request,
|
||||
routing::get,
|
||||
Extension, Router,
|
||||
};
|
||||
use tower::ServiceExt;
|
||||
use tower_sessions::SessionManagerLayer;
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/",
|
||||
get(|Extension(session): Extension<Session>| async move {
|
||||
session.insert("actor", "qa").await.unwrap();
|
||||
"ok"
|
||||
}),
|
||||
)
|
||||
.layer(SessionManagerLayer::new(Store::new()));
|
||||
let response = app
|
||||
.oneshot(Request::builder().uri("/").body(Body::empty()).unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(response.status(), 200);
|
||||
assert!(response.headers().contains_key("set-cookie"));
|
||||
assert_eq!(
|
||||
to_bytes(response.into_body(), 32).await.unwrap().as_ref(),
|
||||
b"ok"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gzip_content_and_keyed_limiter() {
|
||||
use async_compression::tokio::bufread::{GzipDecoder, GzipEncoder};
|
||||
use tokio::io::{AsyncReadExt, BufReader};
|
||||
let original = b"CREATE TABLE synthetic (id INTEGER);\n";
|
||||
let mut gzip = Vec::new();
|
||||
GzipEncoder::new(&original[..])
|
||||
.read_to_end(&mut gzip)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(&gzip[..2], &[0x1f, 0x8b]);
|
||||
let mut decoded = Vec::new();
|
||||
GzipDecoder::new(BufReader::new(&gzip[..]))
|
||||
.read_to_end(&mut decoded)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(decoded, original);
|
||||
let limiter = governor::RateLimiter::keyed(governor::Quota::per_minute(
|
||||
std::num::NonZeroU32::new(1).unwrap(),
|
||||
));
|
||||
assert!(limiter.check_key(&"source-a").is_ok());
|
||||
assert!(limiter.check_key(&"source-a").is_err());
|
||||
assert!(limiter.check_key(&"source-b").is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oidc_client_disables_redirects_and_uses_s256() {
|
||||
use openidconnect::{reqwest, PkceCodeChallenge};
|
||||
let _client = reqwest::Client::builder()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.build()
|
||||
.unwrap();
|
||||
let (challenge, verifier) = PkceCodeChallenge::new_random_sha256();
|
||||
assert_eq!(challenge.method().as_str(), "S256");
|
||||
assert!(verifier.secret().len() >= 43);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn migration_shares_sqlite_binding() {
|
||||
use rusqlite_migration::{Migrations, M};
|
||||
let mut conn = Connection::open_in_memory().unwrap();
|
||||
Migrations::new(vec![M::up("CREATE TABLE fixture (id INTEGER PRIMARY KEY)")])
|
||||
.to_latest(&mut conn)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
conn.query_row("PRAGMA user_version", [], |r| r.get::<_, i64>(0))
|
||||
.unwrap(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn casbin_and_sql_grants_have_the_same_deny_and_revoke_matrix() {
|
||||
use casbin::prelude::*;
|
||||
let model = DefaultModel::from_str(
|
||||
"[request_definition]\nr = sub, obj, act\n[policy_definition]\np = sub, obj, act\n\
|
||||
[policy_effect]\ne = some(where (p.eft == allow))\n\
|
||||
[matchers]\nm = r.sub == p.sub && r.obj == p.obj && r.act == p.act",
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let mut enforcer = Enforcer::new(model, MemoryAdapter::default())
|
||||
.await
|
||||
.unwrap();
|
||||
let conn = Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(
|
||||
"CREATE TABLE grants (actor TEXT, resource TEXT, action TEXT,
|
||||
PRIMARY KEY(actor, resource, action))",
|
||||
)
|
||||
.unwrap();
|
||||
let grants = [
|
||||
("qa", "prod->stage", "refresh.run"),
|
||||
("developer", "prod", "snapshot.download"),
|
||||
("service", "stage", "capture.run"),
|
||||
("admin", "prod", "orbit.manage"),
|
||||
];
|
||||
for (actor, resource, action) in grants {
|
||||
enforcer
|
||||
.add_policy(vec![actor.into(), resource.into(), action.into()])
|
||||
.await
|
||||
.unwrap();
|
||||
conn.execute(
|
||||
"INSERT INTO grants VALUES (?1, ?2, ?3)",
|
||||
params![actor, resource, action],
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let matrix = [
|
||||
("qa", "prod->stage", "refresh.run", true),
|
||||
("qa", "stage->prod", "refresh.run", false),
|
||||
("qa", "prod->dev", "refresh.run", false),
|
||||
("qa", "prod", "capture.run", false),
|
||||
("qa", "prod", "snapshot.download", false),
|
||||
("developer", "prod", "snapshot.download", true),
|
||||
("developer", "stage", "snapshot.download", false),
|
||||
("developer", "prod", "capture.run", false),
|
||||
("service", "stage", "capture.run", true),
|
||||
("service", "prod", "capture.run", false),
|
||||
("outpost", "prod", "orbit.manage", false),
|
||||
("admin", "prod", "orbit.manage", true),
|
||||
("anonymous", "prod", "orbit.manage", false),
|
||||
("admin", "prod", "unknown", false),
|
||||
];
|
||||
for (actor, resource, action, expected) in matrix {
|
||||
let sql: bool = conn.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM grants WHERE actor=?1 AND resource=?2 AND action=?3)",
|
||||
params![actor, resource, action], |r| r.get(0)).unwrap();
|
||||
assert_eq!(sql, expected, "SQL {actor}/{resource}/{action}");
|
||||
assert_eq!(
|
||||
enforcer.enforce((actor, resource, action)).unwrap(),
|
||||
expected,
|
||||
"Casbin {actor}/{resource}/{action}"
|
||||
);
|
||||
}
|
||||
enforcer
|
||||
.remove_policy(vec![
|
||||
"qa".into(),
|
||||
"prod->stage".into(),
|
||||
"refresh.run".into(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
conn.execute("DELETE FROM grants WHERE actor='qa'", [])
|
||||
.unwrap();
|
||||
assert!(!enforcer
|
||||
.enforce(("qa", "prod->stage", "refresh.run"))
|
||||
.unwrap());
|
||||
assert!(!conn
|
||||
.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM grants WHERE actor='qa')",
|
||||
[],
|
||||
|r| r.get::<_, bool>(0)
|
||||
)
|
||||
.unwrap());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user