fix(pentest): delete test users only in the target's identity provider (#999) (#1002)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m9s
CI / Deploy MCP (push) Successful in 3m49s
CI / Deploy Dashboard (push) Successful in 4m55s
CI / Deploy Agent (push) Successful in 6m4s
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Docs (push) Successful in 1m9s
CI / Deploy MCP (push) Successful in 3m49s
CI / Deploy Dashboard (push) Successful in 4m55s
CI / Deploy Agent (push) Successful in 6m4s
This commit was merged in pull request #1002.
This commit is contained in:
1 parent
396cb3cd39
commit
fad023e734
12 files changed
+813
-487
No files matched your search
@@ -86,6 +86,13 @@ pub async fn create_session(
|
||||
if let Err(e) = agent.net_guard.check_url(&config.app_url) {
|
||||
return Err((StatusCode::BAD_REQUEST, e.to_string()));
|
||||
}
|
||||
// The test-user cleanup talks to the target's identity provider, also
|
||||
// a tenant-chosen URL.
|
||||
if let Some(access) = &config.auth.cleanup {
|
||||
if let Err(e) = agent.net_guard.check_url(&access.base_url()) {
|
||||
return Err((StatusCode::BAD_REQUEST, e.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
// Look up or auto-create DastTarget by app_url
|
||||
let target = match db
|
||||
@@ -187,35 +194,21 @@ pub async fn create_session(
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-populate test user record for auto-register sessions
|
||||
if let Some(ref cfg) = session.config {
|
||||
if cfg.auth.mode == AuthMode::AutoRegister {
|
||||
let verification_email = cfg.auth.verification_email.clone();
|
||||
// Build plus-addressed email for this session
|
||||
let test_email = verification_email.as_deref().map(|email| {
|
||||
let parts: Vec<&str> = email.splitn(2, '@').collect();
|
||||
if parts.len() == 2 {
|
||||
format!("{}+{}@{}", parts[0], session_id_str, parts[1])
|
||||
} else {
|
||||
email.to_string()
|
||||
}
|
||||
});
|
||||
|
||||
// Detect identity provider from keycloak config
|
||||
let provider = if agent.config.keycloak_url.is_some() {
|
||||
Some(compliance_core::models::pentest::IdentityProvider::Keycloak)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
session.test_user = Some(compliance_core::models::pentest::TestUserRecord {
|
||||
username: None, // LLM will choose; updated after registration
|
||||
email: test_email,
|
||||
provider_user_id: None,
|
||||
provider,
|
||||
cleaned_up: false,
|
||||
});
|
||||
}
|
||||
// The test user an auto-register session registers, kept on the
|
||||
// stored session so cleanup and the report find it.
|
||||
if let Some(cfg) = &session.config {
|
||||
session.test_user = crate::pentest::cleanup::planned_test_user(cfg, &session_id_str);
|
||||
}
|
||||
if let (Some(sid), Some(test_user)) = (session.id, &session.test_user) {
|
||||
let record = mongodb::bson::to_bson(test_user)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
|
||||
db.pentest_sessions()
|
||||
.update_one(
|
||||
doc! { "_id": sid },
|
||||
doc! { "$set": { "test_user": record } },
|
||||
)
|
||||
.await
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("DB error: {e}")))?;
|
||||
}
|
||||
|
||||
let initial_message = config
|
||||
|
||||
@@ -87,8 +87,6 @@ fn build_config(app_env: AppEnv) -> Result<AgentConfig, AgentError> {
|
||||
.unwrap_or_else(|| "/data/compliance-scanner/artifacts".to_string()),
|
||||
keycloak_url: env_var_opt("KEYCLOAK_URL"),
|
||||
keycloak_realm: env_var_opt("KEYCLOAK_REALM"),
|
||||
keycloak_admin_username: env_var_opt("KEYCLOAK_ADMIN_USERNAME"),
|
||||
keycloak_admin_password: env_secret_opt("KEYCLOAK_ADMIN_PASSWORD"),
|
||||
pentest_verification_email: env_var_opt("PENTEST_VERIFICATION_EMAIL"),
|
||||
pentest_imap_host: env_var_opt("PENTEST_IMAP_HOST"),
|
||||
pentest_imap_port: env_var_opt("PENTEST_IMAP_PORT").and_then(|p| p.parse().ok()),
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -14,6 +14,7 @@ use crate::database::Database;
|
||||
use crate::llm::{
|
||||
ChatMessage, LlmClient, LlmResponse, ToolCallRequest, ToolCallRequestFunction, ToolDefinition,
|
||||
};
|
||||
use crate::pentest::cleanup::CleanupOutcome;
|
||||
|
||||
/// Maximum duration for a single pentest session before timeout
|
||||
const SESSION_TIMEOUT: Duration = Duration::from_secs(30 * 60); // 30 minutes
|
||||
@@ -24,6 +25,8 @@ pub struct PentestOrchestrator {
|
||||
pub(crate) db: Database,
|
||||
pub(crate) event_tx: broadcast::Sender<PentestEvent>,
|
||||
pub(crate) pause_rx: Option<watch::Receiver<bool>>,
|
||||
/// Outbound policy for tenant-chosen URLs, the test-user cleanup's too.
|
||||
pub(crate) net_guard: NetGuard,
|
||||
}
|
||||
|
||||
impl PentestOrchestrator {
|
||||
@@ -42,6 +45,55 @@ impl PentestOrchestrator {
|
||||
db,
|
||||
event_tx,
|
||||
pause_rx,
|
||||
net_guard,
|
||||
}
|
||||
}
|
||||
|
||||
/// Delete the session's test user with the access given for the target's
|
||||
/// identity provider, and record on the session what became of it.
|
||||
async fn clean_up_test_user(
|
||||
&self,
|
||||
session_id: Option<mongodb::bson::oid::ObjectId>,
|
||||
test_user: &TestUserRecord,
|
||||
access: Option<&TestUserCleanup>,
|
||||
) {
|
||||
let outcome = match compliance_core::guarded_net::guarded_client_builder(self.net_guard)
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
{
|
||||
Ok(http) => crate::pentest::cleanup::cleanup_test_user(test_user, access, &http).await,
|
||||
Err(e) => Err(format!("no HTTP client: {e}")),
|
||||
};
|
||||
let left_behind = match outcome {
|
||||
Ok(CleanupOutcome::Deleted) | Ok(CleanupOutcome::NotRegistered) => None,
|
||||
Ok(CleanupOutcome::LeftBehind(reason)) => Some(reason),
|
||||
Err(e) => Some(format!("cleanup failed: {e}")),
|
||||
};
|
||||
match &left_behind {
|
||||
None => tracing::info!("Pentest test user deleted"),
|
||||
Some(reason) => {
|
||||
tracing::warn!(reason = %reason, "Pentest test user left behind");
|
||||
let _ = self.event_tx.send(PentestEvent::Message {
|
||||
content: format!(
|
||||
"The test user {} is still registered with the application ({reason}); \
|
||||
delete it by hand.",
|
||||
test_user.email.as_deref().unwrap_or("(unknown)")
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
if let Some(sid) = session_id {
|
||||
let _ = self
|
||||
.db
|
||||
.pentest_sessions()
|
||||
.update_one(
|
||||
doc! { "_id": sid },
|
||||
doc! { "$set": {
|
||||
"test_user.cleaned_up": left_behind.is_none(),
|
||||
"test_user.left_behind": left_behind,
|
||||
} },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,55 +551,12 @@ impl PentestOrchestrator {
|
||||
.await;
|
||||
}
|
||||
|
||||
// Clean up test user via identity provider API if requested
|
||||
if session
|
||||
.config
|
||||
.as_ref()
|
||||
.is_some_and(|c| c.auth.cleanup_test_user)
|
||||
// Delete the test user in the target's identity provider if asked.
|
||||
if let (Some(cfg), Some(test_user)) = (session.config.as_ref(), session.test_user.as_ref())
|
||||
{
|
||||
if let Some(ref test_user) = session.test_user {
|
||||
let http = reqwest::Client::new();
|
||||
// We need the AgentConfig — read from env since orchestrator doesn't hold it
|
||||
let config = crate::config::load_config();
|
||||
match config {
|
||||
Ok(cfg) => {
|
||||
match crate::pentest::cleanup::cleanup_test_user(test_user, &cfg, &http)
|
||||
.await
|
||||
{
|
||||
Ok(true) => {
|
||||
tracing::info!(
|
||||
username = test_user.username.as_deref(),
|
||||
"Test user cleaned up via provider API"
|
||||
);
|
||||
// Mark as cleaned up in DB
|
||||
if let Some(sid) = session.id {
|
||||
let _ = self
|
||||
.db
|
||||
.pentest_sessions()
|
||||
.update_one(
|
||||
doc! { "_id": sid },
|
||||
doc! { "$set": { "test_user.cleaned_up": true } },
|
||||
)
|
||||
.await;
|
||||
}
|
||||
}
|
||||
Ok(false) => {
|
||||
tracing::info!(
|
||||
"Test user cleanup skipped (no provider configured)"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "Test user cleanup failed");
|
||||
let _ = self.event_tx.send(PentestEvent::Error {
|
||||
message: format!("Test user cleanup failed: {e}"),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "Could not load config for cleanup");
|
||||
}
|
||||
}
|
||||
if cfg.auth.cleanup_test_user {
|
||||
self.clean_up_test_user(session.id, test_user, cfg.auth.cleanup.as_ref())
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ use compliance_core::models::sbom::SbomEntry;
|
||||
use super::orchestrator::PentestOrchestrator;
|
||||
|
||||
/// Build additional prompt sections from PentestConfig when present.
|
||||
fn build_config_sections(config: &PentestConfig) -> String {
|
||||
/// `test_email` is the address an auto-register session registers with.
|
||||
fn build_config_sections(config: &PentestConfig, test_email: Option<&str>) -> String {
|
||||
let mut sections = String::new();
|
||||
|
||||
// Authentication section
|
||||
@@ -35,13 +36,11 @@ fn build_config_sections(config: &PentestConfig) -> String {
|
||||
"- **Registration URL**: Not provided — use Playwright to discover the registration page.\n",
|
||||
);
|
||||
}
|
||||
if let Some(ref email) = config.auth.verification_email {
|
||||
if let Some(email) = test_email {
|
||||
sections.push_str(&format!(
|
||||
"- **Verification Email**: Use plus-addressing from `{email}` \
|
||||
(e.g. `{base}+{{session_id}}@{domain}`) for email verification. \
|
||||
The system will poll the IMAP mailbox for verification links.\n",
|
||||
base = email.split('@').next().unwrap_or(email),
|
||||
domain = email.split('@').nth(1).unwrap_or("example.com"),
|
||||
"- **E-mail address**: Register with exactly `{email}` (no other \
|
||||
address): the system polls its mailbox for verification links and \
|
||||
finds the test account by it afterwards.\n",
|
||||
));
|
||||
}
|
||||
sections.push_str(
|
||||
@@ -245,7 +244,10 @@ impl PentestOrchestrator {
|
||||
let config_sections = session
|
||||
.config
|
||||
.as_ref()
|
||||
.map(build_config_sections)
|
||||
.map(|c| {
|
||||
let test_email = session.test_user.as_ref().and_then(|u| u.email.as_deref());
|
||||
build_config_sections(c, test_email)
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
format!(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::{html_escape, tool_category};
|
||||
use compliance_core::models::pentest::{AuthMode, PentestConfig, PentestSession};
|
||||
use compliance_core::models::pentest::{AuthMode, PentestConfig, PentestSession, TestUserRecord};
|
||||
|
||||
pub(super) fn scope(
|
||||
session: &PentestSession,
|
||||
@@ -43,6 +43,9 @@ pub(super) fn scope(
|
||||
AuthMode::AutoRegister => "Auto-register",
|
||||
};
|
||||
rows.push_str(&format!("<tr><td>Auth Mode</td><td>{auth_mode}</td></tr>"));
|
||||
if let Some(user) = &session.test_user {
|
||||
rows.push_str(&test_user_row(user));
|
||||
}
|
||||
if !cfg.scope_exclusions.is_empty() {
|
||||
let excl = cfg
|
||||
.scope_exclusions
|
||||
@@ -125,3 +128,47 @@ pub(super) fn scope(
|
||||
success_rate = session.success_rate(),
|
||||
)
|
||||
}
|
||||
|
||||
/// The report row for the session's test user: deleted, or still registered
|
||||
/// with the application and to be deleted by hand.
|
||||
fn test_user_row(user: &TestUserRecord) -> String {
|
||||
let email = html_escape(user.email.as_deref().unwrap_or("(unknown)"));
|
||||
let state = match (&user.left_behind, user.cleaned_up) {
|
||||
(Some(reason), _) => format!(
|
||||
"<strong>Left behind</strong>: still registered with the application, \
|
||||
delete it by hand ({})",
|
||||
html_escape(reason)
|
||||
),
|
||||
(None, true) => "Deleted after the test".to_string(),
|
||||
(None, false) => "Not deleted (cleanup was not requested)".to_string(),
|
||||
};
|
||||
format!("<tr><td>Test User</td><td><code>{email}</code> — {state}</td></tr>")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_user_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_left_behind_test_user_is_named_with_its_reason() {
|
||||
let user = TestUserRecord {
|
||||
email: Some("pentest+1@mail.example.com".into()),
|
||||
left_behind: Some("no admin access <given>".into()),
|
||||
..Default::default()
|
||||
};
|
||||
let row = test_user_row(&user);
|
||||
assert!(row.contains("pentest+1@mail.example.com"));
|
||||
assert!(row.contains("Left behind"));
|
||||
assert!(row.contains("no admin access <given>"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_deleted_test_user_says_so() {
|
||||
let user = TestUserRecord {
|
||||
email: Some("pentest+1@mail.example.com".into()),
|
||||
cleaned_up: true,
|
||||
..Default::default()
|
||||
};
|
||||
assert!(test_user_row(&user).contains("Deleted after the test"));
|
||||
}
|
||||
}
|
||||
@@ -39,8 +39,6 @@ pub struct AgentConfig {
|
||||
pub artifact_store_base_path: String,
|
||||
pub keycloak_url: Option<String>,
|
||||
pub keycloak_realm: Option<String>,
|
||||
pub keycloak_admin_username: Option<String>,
|
||||
pub keycloak_admin_password: Option<SecretString>,
|
||||
// Pentest defaults
|
||||
pub pentest_verification_email: Option<String>,
|
||||
pub pentest_imap_host: Option<String>,
|
||||
@@ -349,8 +347,6 @@ impl Default for AgentConfig {
|
||||
artifact_store_base_path: "/data/compliance-scanner/artifacts".to_string(),
|
||||
keycloak_url: None,
|
||||
keycloak_realm: None,
|
||||
keycloak_admin_username: None,
|
||||
keycloak_admin_password: None,
|
||||
pentest_verification_email: None,
|
||||
pentest_imap_host: None,
|
||||
pentest_imap_port: None,
|
||||
|
||||
@@ -10,7 +10,7 @@ use super::dast::{DastAuthConfig, DastTarget};
|
||||
use super::onboarding::{
|
||||
Artifact, ArtifactAuth, IssueTrackerConfig, OnboardedTarget, TargetScanConfig,
|
||||
};
|
||||
use super::pentest::{PentestAuthConfig, PentestConfig, PentestSession};
|
||||
use super::pentest::{PentestAuthConfig, PentestConfig, PentestSession, TestUserCleanup};
|
||||
|
||||
/// A record that carries stored credentials.
|
||||
pub trait Credentials {
|
||||
@@ -88,7 +88,20 @@ impl Credentials for IssueTrackerConfig {
|
||||
|
||||
impl Credentials for PentestAuthConfig {
|
||||
fn credentials_mut(&mut self) -> Vec<&mut Option<String>> {
|
||||
vec![&mut self.password, &mut self.imap_password]
|
||||
let mut slots = vec![&mut self.password, &mut self.imap_password];
|
||||
slots.extend(self.cleanup.credentials_mut());
|
||||
slots
|
||||
}
|
||||
}
|
||||
|
||||
impl Credentials for TestUserCleanup {
|
||||
fn credentials_mut(&mut self) -> Vec<&mut Option<String>> {
|
||||
match self {
|
||||
Self::Keycloak { client_secret, .. } | Self::Auth0 { client_secret, .. } => {
|
||||
vec![client_secret]
|
||||
}
|
||||
Self::Okta { api_token, .. } => vec![api_token],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +231,12 @@ mod tests {
|
||||
username: Some("tester".into()),
|
||||
password: Some("pw".into()),
|
||||
imap_password: Some("imap".into()),
|
||||
cleanup: Some(TestUserCleanup::Keycloak {
|
||||
base_url: "https://login.example.com".into(),
|
||||
realm: "app".into(),
|
||||
client_id: "cleanup".into(),
|
||||
client_secret: Some("kc-secret".into()),
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
custom_headers: HashMap::new(),
|
||||
@@ -239,5 +258,14 @@ mod tests {
|
||||
assert_eq!(auth.username.as_deref(), Some("tester"));
|
||||
assert_eq!(auth.password, None);
|
||||
assert_eq!(auth.imap_password, None);
|
||||
assert_eq!(
|
||||
auth.cleanup,
|
||||
Some(TestUserCleanup::Keycloak {
|
||||
base_url: "https://login.example.com".into(),
|
||||
realm: "app".into(),
|
||||
client_id: "cleanup".into(),
|
||||
client_secret: None,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,66 @@ pub struct PentestAuthConfig {
|
||||
pub imap_password: Option<String>,
|
||||
#[serde(default)]
|
||||
pub cleanup_test_user: bool,
|
||||
/// Admin access to the target's own identity provider, given for this
|
||||
/// session, so the test user can be deleted afterwards. Without it the
|
||||
/// test user is left behind and the report says so: the agent never uses
|
||||
/// its own identity provider for this.
|
||||
#[serde(default)]
|
||||
pub cleanup: Option<TestUserCleanup>,
|
||||
}
|
||||
|
||||
/// Where and how the test user of an auto-register session is deleted: the
|
||||
/// target's identity provider, with credentials given for the session.
|
||||
///
|
||||
/// The user is looked up by the session's own e-mail address
|
||||
/// (`base+{session_id}@domain`), which no real account carries.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(tag = "provider", rename_all = "snake_case")]
|
||||
pub enum TestUserCleanup {
|
||||
/// A Keycloak realm, through a confidential client whose service account
|
||||
/// may manage that realm's users (`realm-management: manage-users`).
|
||||
Keycloak {
|
||||
/// Keycloak's base URL, e.g. `https://login.example.com`.
|
||||
base_url: String,
|
||||
/// The realm the test user registered in.
|
||||
realm: String,
|
||||
client_id: String,
|
||||
client_secret: Option<String>,
|
||||
},
|
||||
/// An Auth0 tenant, through a machine-to-machine application with the
|
||||
/// Management API scopes `read:users` and `delete:users`.
|
||||
Auth0 {
|
||||
/// The tenant's domain, e.g. `example.eu.auth0.com`.
|
||||
domain: String,
|
||||
client_id: String,
|
||||
client_secret: Option<String>,
|
||||
},
|
||||
/// An Okta org, through an API token allowed to manage users.
|
||||
Okta {
|
||||
/// The org's domain, e.g. `example.okta.com`.
|
||||
domain: String,
|
||||
api_token: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl TestUserCleanup {
|
||||
/// The identity provider this cleanup acts on.
|
||||
pub fn provider(&self) -> IdentityProvider {
|
||||
match self {
|
||||
Self::Keycloak { .. } => IdentityProvider::Keycloak,
|
||||
Self::Auth0 { .. } => IdentityProvider::Auth0,
|
||||
Self::Okta { .. } => IdentityProvider::Okta,
|
||||
}
|
||||
}
|
||||
|
||||
/// The URL the cleanup talks to, for the outbound check before a session
|
||||
/// starts.
|
||||
pub fn base_url(&self) -> String {
|
||||
match self {
|
||||
Self::Keycloak { base_url, .. } => base_url.trim_end_matches('/').to_string(),
|
||||
Self::Auth0 { domain, .. } | Self::Okta { domain, .. } => format!("https://{domain}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Full wizard configuration for a pentest session
|
||||
@@ -150,7 +210,8 @@ pub struct PentestConfig {
|
||||
pub skip_mode: bool,
|
||||
}
|
||||
|
||||
/// Identity provider type for cleanup routing
|
||||
/// The identity provider that holds a test user. `Firebase` and `Custom`
|
||||
/// remain so older session records still read; neither is cleaned up.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum IdentityProvider {
|
||||
@@ -176,6 +237,10 @@ pub struct TestUserRecord {
|
||||
/// Whether cleanup has been completed
|
||||
#[serde(default)]
|
||||
pub cleaned_up: bool,
|
||||
/// Why the test user was not deleted, when cleanup was asked for: it is
|
||||
/// still in the target's identity provider and has to go by hand.
|
||||
#[serde(default)]
|
||||
pub left_behind: Option<String>,
|
||||
}
|
||||
|
||||
/// A pentest session initiated via the chat interface
|
||||
|
||||
@@ -466,6 +466,7 @@ fn pentest_config_serde_roundtrip() {
|
||||
imap_username: None,
|
||||
imap_password: None,
|
||||
cleanup_test_user: true,
|
||||
cleanup: None,
|
||||
},
|
||||
custom_headers: [("X-Token".to_string(), "abc".to_string())]
|
||||
.into_iter()
|
||||
@@ -525,6 +526,7 @@ fn test_user_record_serde_roundtrip() {
|
||||
provider_user_id: Some("kc-uuid-123".into()),
|
||||
provider: Some(pentest::IdentityProvider::Keycloak),
|
||||
cleaned_up: false,
|
||||
left_behind: None,
|
||||
};
|
||||
let json = serde_json::to_string(&r).unwrap();
|
||||
let back: pentest::TestUserRecord = serde_json::from_str(&json).unwrap();
|
||||
@@ -559,6 +561,7 @@ fn pentest_session_with_test_user() {
|
||||
provider_user_id: None,
|
||||
provider: Some(pentest::IdentityProvider::Auth0),
|
||||
cleaned_up: false,
|
||||
left_behind: None,
|
||||
});
|
||||
let bson_doc = bson::to_document(&s).unwrap();
|
||||
let back: pentest::PentestSession = bson::from_document(bson_doc).unwrap();
|
||||
@@ -605,3 +608,34 @@ fn opt_bson_datetime_roundtrip_with_some() {
|
||||
let back: pentest::PentestSession = bson::from_document(bson_doc).unwrap();
|
||||
assert!(back.completed_at.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_user_cleanup_is_tagged_by_provider() {
|
||||
let access: pentest::TestUserCleanup = serde_json::from_value(serde_json::json!({
|
||||
"provider": "keycloak",
|
||||
"base_url": "https://login.example.com/",
|
||||
"realm": "app",
|
||||
"client_id": "cleanup",
|
||||
"client_secret": "s"
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(access.provider(), pentest::IdentityProvider::Keycloak);
|
||||
assert_eq!(access.base_url(), "https://login.example.com");
|
||||
|
||||
let okta: pentest::TestUserCleanup = serde_json::from_value(serde_json::json!({
|
||||
"provider": "okta", "domain": "example.okta.com", "api_token": "t"
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(okta.base_url(), "https://example.okta.com");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_older_test_user_record_still_reads() {
|
||||
let back: pentest::TestUserRecord = serde_json::from_value(serde_json::json!({
|
||||
"username": null, "email": "a+1@b.c", "provider_user_id": null,
|
||||
"provider": "firebase", "cleaned_up": false
|
||||
}))
|
||||
.unwrap();
|
||||
assert_eq!(back.left_behind, None);
|
||||
assert_eq!(back.provider, Some(pentest::IdentityProvider::Firebase));
|
||||
}
|
||||
@@ -32,6 +32,7 @@ Click **New Pentest** on the dashboard to open the 4-step onboarding wizard:
|
||||
- **Registration URL** (optional) — auto-discovered via Playwright if omitted
|
||||
- **Verification Email** (optional) — override the agent's default mailbox. Uses plus-addressing (`base+sessionid@domain`) and polls IMAP for verification links
|
||||
- **IMAP Settings** — collapsible section to override host/port/credentials
|
||||
- **Delete the test user afterwards** — deletes the account in the application's own identity provider when the session ends. It needs admin access to that provider, given for the session through the API (`config.auth.cleanup`): a Keycloak realm (a client whose service account may manage users), an Auth0 tenant (a machine-to-machine application with `read:users` and `delete:users`) or an Okta org (an API token). The account is found by the session's own address and deleted only if exactly one account carries it. Without that access, or if the provider refuses, the report lists the test user as **left behind**, to be deleted by hand. Prüfwerk never uses its own login service for this.
|
||||
|
||||
### Step 3 — Strategy & Instructions
|
||||
|
||||
|
||||
@@ -417,6 +417,7 @@ Every connection the agent opens, in one place. **Guarded** means: the HTTP clie
|
||||
| Git remotes (clone, fetch, submodules, linked artifacts) | `pipeline/git.rs`, `ingest/` | `check_git_url` and the resolved address before every clone and fetch; redirects off |
|
||||
| Gitea API of a git source or tracker (managed Git) | `git_source/gitea.rs`, `trackers/gitea.rs` | guarded |
|
||||
| DAST and pentest targets | `api/handlers/dast.rs`, `pentest/orchestrator.rs`, `compliance-dast` | base URL checked with `check_url`; the DAST tools share a guarded client |
|
||||
| The target's identity provider, for deleting a pentest test user (Keycloak, Auth0, Okta; given per session) | `pentest/cleanup.rs` | URL checked with `check_url` when the session is created; guarded client |
|
||||
|
||||
### Operator-configured services (not guarded)
|
||||
|
||||
@@ -428,7 +429,6 @@ These are set by the operator in the agent's environment, not by a tenant, and o
|
||||
| Tenant registry (entitlements, projects) | `registry.rs` | `TENANT_REGISTRY_URL` |
|
||||
| breakpilot-compliance OSCAL catalog | `controls/oscal_provider.rs` | `BREAKPILOT_BASE_URL` |
|
||||
| GitLab and Jira issue trackers | `trackers/gitlab.rs`, `trackers/jira.rs` | `GITLAB_URL`, `JIRA_URL` |
|
||||
| Identity providers for pentest test-user cleanup (Keycloak, Auth0, Okta) | `pentest/cleanup.rs` | `KEYCLOAK_URL`, `AUTH0_DOMAIN`, `OKTA_DOMAIN` |
|
||||
| Headless Chrome for PDF reports | `pentest/report/pdf.rs` | `CHROME_WS_URL` |
|
||||
| MongoDB | `database.rs` | `MONGODB_URI` |
|
||||
| ClamAV service (clamd, plain TCP; the tree's files are streamed to it) | `pipeline/clamav.rs` | `CLAMD_ADDRESS` |
|
||||
|
||||
Reference in new issue
Block a user