-
Notifications
You must be signed in to change notification settings - Fork 0
feat(privacy): refuse untrusted intake without a grant #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seonghobae
wants to merge
10
commits into
main
Choose a base branch
from
agent/intake-authorization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f96cbff
feat(privacy): record provider field codes without source text
seonghobae 97e603b
feat(privacy): refuse untrusted intake without a grant
seonghobae 0196a24
Merge remote-tracking branch 'origin/main' into review/pr141-current
seonghobae 89dca1c
style: apply workspace rustfmt
seonghobae f46a14b
Merge remote-tracking branch 'origin/main' into review/pr114-current
seonghobae 387e42d
test: derive crate contract from workspace manifest
seonghobae 5082f94
docs: remove duplicate traceability rows
seonghobae 13256dd
Merge remote-tracking branch 'origin/agent/intake-authorization' into…
seonghobae 46b2849
fix: register provider receipt in workspace
seonghobae a562add
docs(workspace): register provider receipt crate
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # CodeGraph data files — local to each machine, not for committing. | ||
| # Ignore everything in .codegraph/ except this file itself, so transient | ||
| # files (the database, daemon.pid, sockets, logs) never show up in git. | ||
| * | ||
| !.gitignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "intake_authorization" | ||
| description = "Untrusted intake fails closed without a grant; bounds are not authorization." | ||
| version.workspace = true | ||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| license.workspace = true | ||
| authors.workspace = true | ||
| repository.workspace = true | ||
| homepage.workspace = true | ||
| readme.workspace = true | ||
| keywords.workspace = true | ||
| categories.workspace = true | ||
| publish = false | ||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Fail-closed intake-authorization errors. | ||
|
|
||
| use std::fmt; | ||
|
|
||
| /// A fail-closed intake-authorization error. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| #[non_exhaustive] | ||
| pub enum IntakeAuthorizationError { | ||
| /// Intake was attempted without a purpose-bound grant. | ||
| MissingGrant, | ||
| /// Size, identity, or provenance bounds were treated as authorization. | ||
| BoundsAreNotAuthorization, | ||
| /// A recovery slice was empty or length-mismatched. | ||
| InvalidIntakePayload, | ||
| } | ||
|
|
||
| impl fmt::Display for IntakeAuthorizationError { | ||
| fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let message = match self { | ||
| Self::MissingGrant => "untrusted intake requires a purpose-bound grant", | ||
| Self::BoundsAreNotAuthorization => { | ||
| "identity, provenance, size, and depth bounds are not authorization" | ||
| } | ||
| Self::InvalidIntakePayload => "invalid intake-authorization payload", | ||
| }; | ||
| formatter.write_str(message) | ||
| } | ||
| } | ||
|
|
||
| impl std::error::Error for IntakeAuthorizationError {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::IntakeAuthorizationError; | ||
|
|
||
| #[test] | ||
| fn error_messages_are_stable() { | ||
| for (error, message) in [ | ||
| ( | ||
| IntakeAuthorizationError::MissingGrant, | ||
| "untrusted intake requires a purpose-bound grant", | ||
| ), | ||
| ( | ||
| IntakeAuthorizationError::BoundsAreNotAuthorization, | ||
| "identity, provenance, size, and depth bounds are not authorization", | ||
| ), | ||
| ( | ||
| IntakeAuthorizationError::InvalidIntakePayload, | ||
| "invalid intake-authorization payload", | ||
| ), | ||
| ] { | ||
| assert_eq!(error.to_string(), message); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| //! Grant presence required at untrusted intake. | ||
|
|
||
| use crate::IntakeAuthorizationError; | ||
|
|
||
| /// Closed vocabulary of untrusted inbound kinds that require a grant. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum IntakeKind { | ||
| /// External document bytes. | ||
| Document, | ||
| /// Serialized domain or wire record. | ||
| SerializedRecord, | ||
| /// Model checkpoint or artifact bytes. | ||
| ModelCheckpoint, | ||
| /// LLM or agent output. | ||
| LlmOutput, | ||
| } | ||
|
|
||
| impl IntakeKind { | ||
| /// Return the stable wire intake-kind name. | ||
| #[must_use] | ||
| pub const fn wire_name(self) -> &'static str { | ||
| match self { | ||
| Self::Document => "document", | ||
| Self::SerializedRecord => "serialized_record", | ||
| Self::ModelCheckpoint => "model_checkpoint", | ||
| Self::LlmOutput => "llm_output", | ||
| } | ||
| } | ||
|
|
||
| /// Parse a stable wire intake-kind name. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`IntakeAuthorizationError::InvalidIntakePayload`] for | ||
| /// unrecognized names. | ||
| pub fn from_wire_name(name: &str) -> Result<Self, IntakeAuthorizationError> { | ||
| match name { | ||
| "document" => Ok(Self::Document), | ||
| "serialized_record" => Ok(Self::SerializedRecord), | ||
| "model_checkpoint" => Ok(Self::ModelCheckpoint), | ||
| "llm_output" => Ok(Self::LlmOutput), | ||
| _ => Err(IntakeAuthorizationError::InvalidIntakePayload), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Whether a purpose-bound grant is present at intake. | ||
| #[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
| pub enum GrantPresence { | ||
| /// A grant exists for this intake. | ||
| Present, | ||
| /// No grant exists for this intake. | ||
| Absent, | ||
| } | ||
|
|
||
| /// Refuse untrusted intake that has no purpose-bound grant. | ||
| /// | ||
| /// Cross-purpose reuse of a present grant is owned by `purpose_authorization`. | ||
| /// Identity, provenance, size, and depth are owned by `payload_bound`. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`IntakeAuthorizationError::MissingGrant`] when `grant` is | ||
| /// [`GrantPresence::Absent`]. | ||
| pub fn refuse_intake_without_grant( | ||
| kind: IntakeKind, | ||
| grant: GrantPresence, | ||
| ) -> Result<(), IntakeAuthorizationError> { | ||
| let _ = kind.wire_name(); | ||
| match grant { | ||
| GrantPresence::Absent => Err(IntakeAuthorizationError::MissingGrant), | ||
| GrantPresence::Present => Ok(()), | ||
| } | ||
| } | ||
|
|
||
| /// Refuse to treat size, identity, or provenance bounds as authorization. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Always returns [`IntakeAuthorizationError::BoundsAreNotAuthorization`]. | ||
| pub fn refuse_bounds_as_authorization() -> Result<(), IntakeAuthorizationError> { | ||
| Err(IntakeAuthorizationError::BoundsAreNotAuthorization) | ||
| } | ||
|
|
||
| /// Fraction of recovered grant-presence flags that match known truth. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`IntakeAuthorizationError::InvalidIntakePayload`] when either | ||
| /// slice is empty or the lengths differ. | ||
| pub fn identity_recovery_rate( | ||
| truth: &[bool], | ||
| decided: &[bool], | ||
| ) -> Result<f64, IntakeAuthorizationError> { | ||
| if truth.is_empty() || truth.len() != decided.len() { | ||
| return Err(IntakeAuthorizationError::InvalidIntakePayload); | ||
| } | ||
| let mut matches = 0_u32; | ||
| for (truth_flag, decided_flag) in truth.iter().zip(decided) { | ||
| if truth_flag == decided_flag { | ||
| matches += 1; | ||
| } | ||
| } | ||
| Ok(f64::from(matches) / truth.len() as f64) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::{ | ||
| GrantPresence, IntakeKind, identity_recovery_rate, refuse_bounds_as_authorization, | ||
| refuse_intake_without_grant, | ||
| }; | ||
| use crate::IntakeAuthorizationError; | ||
|
|
||
| #[test] | ||
| fn local_branches_cover_kinds_grants_and_payloads() { | ||
| for kind in [ | ||
| IntakeKind::Document, | ||
| IntakeKind::SerializedRecord, | ||
| IntakeKind::ModelCheckpoint, | ||
| IntakeKind::LlmOutput, | ||
| ] { | ||
| assert_eq!( | ||
| refuse_intake_without_grant(kind, GrantPresence::Absent), | ||
| Err(IntakeAuthorizationError::MissingGrant) | ||
| ); | ||
| refuse_intake_without_grant(kind, GrantPresence::Present).expect("present"); | ||
| assert_eq!( | ||
| IntakeKind::from_wire_name(kind.wire_name()).expect("round-trip"), | ||
| kind | ||
| ); | ||
| } | ||
| assert_eq!( | ||
| refuse_bounds_as_authorization(), | ||
| Err(IntakeAuthorizationError::BoundsAreNotAuthorization) | ||
| ); | ||
| assert_eq!( | ||
| IntakeKind::from_wire_name("trusted"), | ||
| Err(IntakeAuthorizationError::InvalidIntakePayload) | ||
| ); | ||
| let matched = identity_recovery_rate(&[true], &[true]).expect("rate"); | ||
| assert!((matched - 1.0).abs() < f64::EPSILON); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[], &[]), | ||
| Err(IntakeAuthorizationError::InvalidIntakePayload) | ||
| ); | ||
| assert_eq!( | ||
| identity_recovery_rate(&[true], &[]), | ||
| Err(IntakeAuthorizationError::InvalidIntakePayload) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #![forbid(unsafe_code)] | ||
| #![deny(missing_docs)] | ||
| #![allow(clippy::cast_precision_loss)] | ||
| //! Untrusted intake fails closed without a grant; bounds are not authorization. | ||
| //! | ||
| //! Documents, serialized records, checkpoints, and LLM outputs require a | ||
| //! purpose-bound grant at the intake boundary. Passing size or identity | ||
| //! bounds is not that grant (ADR 0009; AGENTS.md). | ||
|
|
||
| mod error; | ||
| mod intake; | ||
|
|
||
| /// Fail-closed intake-authorization errors. | ||
| pub use error::IntakeAuthorizationError; | ||
| /// Whether a purpose-bound grant is present at intake. | ||
| pub use intake::GrantPresence; | ||
| /// Closed vocabulary of untrusted inbound kinds that require a grant. | ||
| pub use intake::IntakeKind; | ||
| /// Fraction of recovered grant-presence flags that match known truth. | ||
| pub use intake::identity_recovery_rate; | ||
| /// Refuse to treat size, identity, or provenance bounds as authorization. | ||
| pub use intake::refuse_bounds_as_authorization; | ||
| /// Refuse untrusted intake that has no purpose-bound grant. | ||
| pub use intake::refuse_intake_without_grant; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| //! Integration contract for the `intake_authorization` package identity. | ||
|
|
||
| #[test] | ||
| fn package_identity_is_stable() { | ||
| let observed = std::hint::black_box(env!("CARGO_PKG_NAME")); | ||
| assert_eq!(observed, "intake_authorization"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.