Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,14 @@ warning at startup if the policy file is group- or other-writable.
this one from starting at all — if it names a rule `default`,
`min_bug_age_days` or `unavailable`, ends a name with `:unreadable-metadata`,
leaves a name blank, or uses one name twice. The error names the offending
rule; rename it and the file loads unchanged. Nothing else about the file's
rule; rename it and the file loads unchanged. A negative `min_bug_age_days`
or `younger_than_days` is refused the same way. For `min_bug_age_days` write
`0` or remove the key; a negative value was already inert. For
`younger_than_days` the two are not the same: `0` keeps the rule from
matching anything but a bug dated in the future, much as a small negative
count did, while removing the key makes the rule match on its other
criteria, or every bug if it has none.
Decide which was meant, or delete the rule. Nothing else about the file's
meaning changed.

A complete, commented example ships in
Expand All @@ -805,7 +812,7 @@ A complete, commented example ships in

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| `min_bug_age_days` | integer | `0` (disabled) | Bugs created less than N days ago are **invisible** — treated exactly like nonexistent bugs, evaluated before any rule. A bug whose `creation_time` is missing or unparsable is denied (fail closed) |
| `min_bug_age_days` | integer | `0` (disabled) | Bugs created less than N days ago are **invisible** — treated exactly like nonexistent bugs, evaluated before any rule. A bug whose `creation_time` is missing or unparsable is denied (fail closed). A negative value is refused at startup |
| `allow_private_comments` | boolean | `false` | Master switch for **all** private content: comments, attachment metadata, and attachment downloads. Even when `true`, each call must also pass `include_private = true`. On an attachment download a *missing* privacy flag counts as private |
| `read_only` | boolean | `false` | Strip write capabilities from every grant and remove write tools from the tool listing. The `--read-only` flag ORs into this |
| `disabled_tools` | array of strings | `[]` | Tool names to remove from the tool listing entirely |
Expand Down Expand Up @@ -854,7 +861,7 @@ write two consecutive rules.
| `whiteboard_contains` | array of strings | case-insensitive substring search in the whiteboard |
| `summary_contains` | array of strings | case-insensitive substring search in the bug's one-line summary |
| `group_restricted` | boolean | `true` matches bugs readable only through at least one Bugzilla group, `false` matches world-readable bugs |
| `younger_than_days` | integer | matches bugs created within the last N days |
| `younger_than_days` | integer | matches bugs created within the last N days; a negative N is refused at startup |
| `created_by_me` | boolean | whether the caller's account authored the bug, compared case-insensitively to the bug's creator. `true` matches the caller's own reports, `false` everyone else's. How the caller's login is resolved depends on `global.identity_source` (default `whoami`): see the source × custody table below. Either source costs at most one lookup per tool call — `whoami` a fresh `GET /rest/whoami`, `declared` zero HTTP requests, since it was verified once at startup — and none at all under a policy without an access-covering `created_by_me` rule (a rule scoped to `operations = ["create"]` alone never triggers one). An unresolvable identity makes the criterion **unknown**, which denies (see Unreadable metadata); a policy that consults this criterion therefore denies everything it reaches while identity cannot be resolved. In the create gate the prospective bug always counts as created by the caller — no lookup happens there (a `create_bug` whose custom fields name Bug ID targets resolves the caller once, for those existing bugs only). Older bugwarden versions reject a policy using this key, or `global.identity_source`/`global.identity_login`, at startup (strict parsing fails closed) |

Identity resolution by source and API-key custody:
Expand Down
2 changes: 1 addition & 1 deletion crates/bugwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ workspace = true

[dependencies]
anyhow = "1"
chrono = { version = "0.4.34", features = ["serde"] }
jiff = { version = "0.2.46", default-features = false, features = ["std"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["rt"] }
Expand Down
16 changes: 5 additions & 11 deletions crates/bugwarden-core/benches/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::hint::black_box;

use bugwarden_core::guard::Guard;
use bugwarden_core::policy::{BugMeta, Operation, Policy};
use chrono::{DateTime, Utc};
use iai_callgrind::{
library_benchmark, library_benchmark_group, main, Callgrind, EventKind, LibraryBenchmarkConfig,
};
use jiff::Timestamp;
use serde_json::{json, Value};

const POLICY: &str = r#"
Expand All @@ -33,10 +33,8 @@ capabilities = ["summary"]
products = ["SUSE*"]
"#;

fn now() -> DateTime<Utc> {
DateTime::parse_from_rfc3339("2026-01-15T00:00:00Z")
.expect("fixed instant")
.with_timezone(&Utc)
fn now() -> Timestamp {
"2026-01-15T00:00:00Z".parse().expect("fixed instant")
}

fn meta(product: Option<&str>, groups: Option<&[&str]>, creation: Option<&str>) -> BugMeta {
Expand All @@ -51,19 +49,15 @@ fn meta(product: Option<&str>, groups: Option<&[&str]>, creation: Option<&str>)
keywords: Some(vec![]),
groups: groups.map(|g| g.iter().map(|s| (*s).to_owned()).collect()),
whiteboard: Some(String::new()),
creation_time: creation.map(|s| {
DateTime::parse_from_rfc3339(s)
.expect("fixture time")
.with_timezone(&Utc)
}),
creation_time: creation.map(|s| s.parse().expect("fixture time")),
created_by_me: Some(false),
}
}

struct ClassifyFix {
policy: Policy,
bug: BugMeta,
now: DateTime<Utc>,
now: Timestamp,
}

fn classify_allow() -> ClassifyFix {
Expand Down
22 changes: 12 additions & 10 deletions crates/bugwarden-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};

use anyhow::{anyhow, bail, Result};
use chrono::{DateTime, Utc};
use jiff::Timestamp;
use serde_json::Value;

tokio::task_local! {
Expand Down Expand Up @@ -351,12 +351,12 @@ impl BugzillaClient {
&self,
key: &str,
id: u64,
new_since: Option<DateTime<Utc>>,
new_since: Option<Timestamp>,
) -> Result<Value> {
let path = format!("/bug/{id}/history");
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(ts) = new_since {
query.push(("new_since", ts.format(TIMESTAMP_FORMAT).to_string()));
query.push(("new_since", ts.strftime(TIMESTAMP_FORMAT).to_string()));
}
let v = self.get_json(key, &path, &query).await?;
Ok(v.get("bugs")
Expand All @@ -374,12 +374,12 @@ impl BugzillaClient {
&self,
key: &str,
id: u64,
new_since: Option<DateTime<Utc>>,
new_since: Option<Timestamp>,
) -> Result<Vec<Value>> {
let path = format!("/bug/{id}/comment");
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(ts) = new_since {
query.push(("new_since", ts.format(TIMESTAMP_FORMAT).to_string()));
query.push(("new_since", ts.strftime(TIMESTAMP_FORMAT).to_string()));
}
let v = self.get_json(key, &path, &query).await?;
let id_key = id.to_string();
Expand Down Expand Up @@ -422,7 +422,7 @@ impl BugzillaClient {
include_fields: &str,
limit: u32,
offset: u32,
changed_since: Option<DateTime<Utc>>,
changed_since: Option<Timestamp>,
) -> Result<Value> {
let quicksearch = if status.is_empty() {
query.to_string()
Expand All @@ -437,7 +437,10 @@ impl BugzillaClient {
("order", "relevance".to_string()),
];
if let Some(ts) = changed_since {
params.push(("last_change_time", ts.format(TIMESTAMP_FORMAT).to_string()));
params.push((
"last_change_time",
ts.strftime(TIMESTAMP_FORMAT).to_string(),
));
}
self.get_json(key, "/bug", &params).await
}
Expand Down Expand Up @@ -852,7 +855,6 @@ fn parse_response(status: reqwest::StatusCode, body: &str) -> Result<Value> {
#[cfg(test)]
mod tests {
use super::*;
use chrono::TimeZone;
use reqwest::StatusCode;

/// Stands in for a real program's identity, naming neither this crate
Expand Down Expand Up @@ -903,9 +905,9 @@ mod tests {

#[test]
fn timestamp_format_renders_utc_z() {
let ts = Utc.with_ymd_and_hms(2024, 1, 2, 3, 4, 5).unwrap();
let ts: Timestamp = "2024-01-02T05:04:05.999+02:00".parse().unwrap();
assert_eq!(
ts.format(TIMESTAMP_FORMAT).to_string(),
ts.strftime(TIMESTAMP_FORMAT).to_string(),
"2024-01-02T03:04:05Z"
);
}
Expand Down
Loading
Loading