use crate::Verdict;
mod words;
pub const DEFAULT: &str = "default";
pub const DEFAULT_PREFIX: &str = "default.";
pub const DEFAULT_NET: &str = "default.net";
pub const UNPARSEABLE: &str = "unparseable";
pub const UNCHECKED: &str = "unchecked";
pub const PROTECTED_CONTENTS: &str = "protected-contents";
pub const EXECUTABLES: &str = "executables";
pub const SESSION_TAINT: &str = "session-taint";
pub const REQUEST_RULE: &str = "request-rule";
pub const INJECTED_INPUT: &str = "injected-input";
pub const MCP_CROSS_SERVER: &str = "mcp-cross-server";
pub const LETHAL_TRIFECTA: &str = "lethal-trifecta";
pub const KERNEL_INTEGRITY: &str = "kernel-integrity";
pub const KERNEL_ERROR: &str = "kernel-error";
pub const HOOK_DEADLINE: &str = "hook-deadline";
pub const UNGOVERNED: &str = "ungoverned";
pub const APPROVED_SESSION: &str = "approved-session";
pub const PROTECTION_REQUIRED: &str = "protection-required";
pub const PROJECT_SETTINGS: &str = "project-settings";
pub const SESSION_WRITTEN_CODE: &str = "session-written-code";
pub const UNATTENDED: &str = "unattended";
pub const CONFIG_CHANGE: &str = "config-change";
pub const SESSION_START: &str = "session-start";
pub const SETTINGS_DRIFT: &str = "settings-drift";
pub const CANARY: &str = "canary";
pub const PUSH_SECRET: &str = "push-secret";
pub const PUSH_RUNS_LATER: &str = "push-runs-later";
pub const PUSH_UNCHECKED: &str = "push-unchecked";
pub const MCP_SERVER_CHANGED: &str = "mcp-server-changed";
pub const FOREIGN_HOOK: &str = "foreign-hook";
pub const MCP_PROXY: &str = "mcp-proxy";
pub const MCP_TOOL_HELD: &str = "mcp-tool-held";
pub const MCP_UNATTRIBUTED: &str = "mcp-unattributed";
pub const MCP_SERVER_REQUEST: &str = "mcp-server-request";
pub const MCP_SERVER_TEXT: &str = "mcp-server-text";
pub const APPROVED_REMOTE: &str = "approved-remote";
pub const REMOTE_APPROVED: &str = "remote-approved";
pub const REMOTE_DENIED: &str = "remote-denied";
pub const REMOTE_REFUSED: &str = "remote-refused";
pub const REMOTE_EXPIRED: &str = "remote-expired";
pub const REVIEW_RAN_AS_SHOWN: &str = "review-ran-as-shown";
pub const REVIEW_RAN_CHANGED: &str = "review-ran-changed";
pub const RUN_SESSION: &str = "run-session";
pub const RUN_NO_ISOLATE: &str = "run-no-isolate";
pub const RUN_ISOLATION_UNAVAILABLE: &str = "run-isolation-unavailable";
pub const RUN_PROJECT_TOP_OPEN: &str = "run-project-top-open";
pub const RUN_PROJECT_HOOK_OFF: &str = "run-project-hook-off";
pub const RUN_PROJECT_HOOK_OFF_OVERRIDDEN: &str = "run-project-hook-off-overridden";
pub const RUN_PROJECT_HOOK_OFF_REFUSED: &str = "run-project-hook-off-refused";
pub const RUN_OWN_SETTINGS_HOOK_OFF: &str = "run-own-settings-hook-off";
pub const RUN_BOUNDARY: &str = "run-boundary";
pub const RUN_GUARD_OUTSIDE: &str = "run-guard-outside";
pub const RUN_GUARD_TOKEN: &str = "run-guard-token";
pub const RUN_GUARD_HOST: &str = "run-guard-host";
pub const RUN_GUARD_SESSION: &str = "run-guard-session";
pub const PROXY_CREDENTIAL: &str = "proxy-credential";
pub const PROXY_SESSION: &str = "proxy-session";
pub const PROXY_SECRET: &str = "proxy-secret";
pub const PROXY_SECRET_EXPIRED: &str = "proxy-secret-expired";
pub const PROXY_HELPER: &str = "proxy-helper";
pub const PROXY_SECRET_ROUTE: &str = "proxy-secret-route";
pub const PROXY_ADDRESS: &str = "proxy-address";
pub const PROXY_SNI: &str = "proxy-sni";
pub const PROXY_REQUEST: &str = "proxy-request";
pub const PROXY_UPSTREAM: &str = "proxy-upstream";
pub const PROXY_AUDIT: &str = "proxy-audit";
pub const PROXY_TLS: &str = "proxy-tls";
pub const PROXY_PORT: &str = "proxy-port";
pub const PROXY_CAPACITY: &str = "proxy-capacity";
pub const AUDIT_DELIVERY_OVERFLOW: &str = "audit-delivery-overflow";
pub const AUDIT_DELIVERY_TOO_LARGE: &str = "audit-delivery-too-large";
pub const AUDIT_DELIVERY_PARTIAL: &str = "audit-delivery-partial";
pub const AUDIT_DELIVERY_TEST: &str = "audit-delivery-test";
pub const POLICY_CHANGE: &str = "policy-change";
pub const GATE_REFUSED: &str = "gate-refused";
pub const DIFF_PATH: &str = "diff-path";
pub const DIFF_SECRET: &str = "diff-secret";
pub const DIFF_POLICY: &str = "diff-policy";
pub const DIFF_LINK: &str = "diff-link";
pub const DIFF_SUBMODULE: &str = "diff-submodule";
pub const DIFF_UNCHECKED: &str = "diff-unchecked";
pub const DIFF_WIDENS: &str = "diff-widens";
pub const KERNEL_SELF: &str = "kernel-self";
pub const AGENT_CREDENTIALS: &str = "agent-credentials";
pub const KERBEROS_TICKETS: &str = "kerberos-tickets";
pub const BUILD_CREDENTIALS: &str = "build-credentials";
pub const ENV_DUMP: &str = "env-dump";
pub const ENV_SECRETS: &str = "env-secrets";
pub const STAGING_EGRESS: &str = "staging-egress";
pub const AGENT_TEMP: &str = "agent-temp";
pub const SECRETS_PATHS: &str = "secrets-paths";
pub const POLICY_RULES: &[&str] = &[
KERNEL_SELF,
AGENT_CREDENTIALS,
KERBEROS_TICKETS,
AGENT_TEMP,
SECRETS_PATHS,
BUILD_CREDENTIALS,
ENV_DUMP,
ENV_SECRETS,
STAGING_EGRESS,
];
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Words {
pub title: &'static str,
pub why: &'static str,
pub next: Option<(Verdict, &'static str)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BuiltinRule {
pub id: &'static str,
pub words: Option<&'static Words>,
}
const fn quiet(id: &'static str) -> BuiltinRule {
BuiltinRule { id, words: None }
}
const fn worded(id: &'static str, words: &'static Words) -> BuiltinRule {
BuiltinRule {
id,
words: Some(words),
}
}
pub const BUILTIN_RULES: &[BuiltinRule] = &[
worded(UNPARSEABLE, &words::UNPARSEABLE),
worded(UNCHECKED, &words::UNCHECKED),
worded(PROTECTED_CONTENTS, &words::PROTECTED_CONTENTS),
worded(EXECUTABLES, &words::EXECUTABLES),
worded(SESSION_TAINT, &words::SESSION_TAINT),
worded(REQUEST_RULE, &words::REQUEST_RULE),
worded(INJECTED_INPUT, &words::INJECTED_INPUT),
worded(MCP_CROSS_SERVER, &words::MCP_CROSS_SERVER),
worded(LETHAL_TRIFECTA, &words::LETHAL_TRIFECTA),
worded(KERNEL_INTEGRITY, &words::KERNEL_INTEGRITY),
worded(KERNEL_ERROR, &words::KERNEL_ERROR),
quiet(HOOK_DEADLINE),
worded(UNGOVERNED, &words::UNGOVERNED),
quiet(APPROVED_SESSION),
worded(PROTECTION_REQUIRED, &words::PROTECTION_REQUIRED),
worded(PROJECT_SETTINGS, &words::PROJECT_SETTINGS),
worded(SESSION_WRITTEN_CODE, &words::SESSION_WRITTEN_CODE),
worded(UNATTENDED, &words::UNATTENDED),
quiet(CONFIG_CHANGE),
quiet(SESSION_START),
quiet(SETTINGS_DRIFT),
worded(CANARY, &words::CANARY),
worded(PUSH_SECRET, &words::PUSH_SECRET),
worded(PUSH_RUNS_LATER, &words::PUSH_RUNS_LATER),
worded(PUSH_UNCHECKED, &words::PUSH_UNCHECKED),
worded(MCP_SERVER_CHANGED, &words::MCP_SERVER_CHANGED),
worded(FOREIGN_HOOK, &words::FOREIGN_HOOK),
quiet(MCP_PROXY),
quiet(MCP_TOOL_HELD),
quiet(MCP_UNATTRIBUTED),
quiet(MCP_SERVER_REQUEST),
quiet(MCP_SERVER_TEXT),
quiet(APPROVED_REMOTE),
quiet(REMOTE_APPROVED),
quiet(REMOTE_DENIED),
quiet(REMOTE_REFUSED),
quiet(REMOTE_EXPIRED),
quiet(REVIEW_RAN_AS_SHOWN),
quiet(REVIEW_RAN_CHANGED),
quiet(RUN_SESSION),
quiet(RUN_NO_ISOLATE),
quiet(RUN_ISOLATION_UNAVAILABLE),
quiet(RUN_PROJECT_TOP_OPEN),
quiet(RUN_PROJECT_HOOK_OFF),
quiet(RUN_PROJECT_HOOK_OFF_OVERRIDDEN),
quiet(RUN_PROJECT_HOOK_OFF_REFUSED),
quiet(RUN_OWN_SETTINGS_HOOK_OFF),
quiet(RUN_BOUNDARY),
quiet(RUN_GUARD_OUTSIDE),
quiet(RUN_GUARD_TOKEN),
quiet(RUN_GUARD_HOST),
quiet(RUN_GUARD_SESSION),
quiet(PROXY_CREDENTIAL),
quiet(PROXY_SESSION),
quiet(PROXY_SECRET),
quiet(PROXY_SECRET_EXPIRED),
quiet(PROXY_HELPER),
quiet(PROXY_SECRET_ROUTE),
quiet(PROXY_ADDRESS),
quiet(PROXY_SNI),
quiet(PROXY_REQUEST),
quiet(PROXY_UPSTREAM),
quiet(PROXY_AUDIT),
quiet(PROXY_TLS),
quiet(PROXY_PORT),
quiet(PROXY_CAPACITY),
quiet(AUDIT_DELIVERY_OVERFLOW),
quiet(AUDIT_DELIVERY_TOO_LARGE),
quiet(AUDIT_DELIVERY_PARTIAL),
quiet(AUDIT_DELIVERY_TEST),
quiet(POLICY_CHANGE),
quiet(GATE_REFUSED),
quiet(DIFF_PATH),
quiet(DIFF_SECRET),
quiet(DIFF_POLICY),
quiet(DIFF_LINK),
quiet(DIFF_SUBMODULE),
quiet(DIFF_UNCHECKED),
quiet(DIFF_WIDENS),
];
#[must_use]
pub fn builtin(id: &str) -> Option<&'static BuiltinRule> {
BUILTIN_RULES.iter().find(|r| r.id == id)
}
#[must_use]
pub fn words(id: &str) -> Option<&'static Words> {
builtin(id).and_then(|r| r.words)
}
#[must_use]
pub fn resolves(id: &str, policy: &crate::Policy) -> bool {
id == DEFAULT
|| id
.strip_prefix(DEFAULT_PREFIX)
.is_some_and(|kind| kind.parse::<crate::Kind>().is_ok())
|| builtin(id).is_some()
|| policy.own_group(id).is_some()
|| policy.repo_review.iter().any(|g| g.id == id)
}
#[cfg(test)]
mod tests;