Repository navigation
feat(dir): add prune-untrusted job - #2220
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
339d8af to
81e4635
Compare
tkircsi
left a comment
There was a problem hiding this comment.
scan_severity is a free-form string that nothing validates, and the database layer responds to a value it doesn't recognize by silently dropping the severity condition from the SQL rather than by returning an error. The task's query then degenerates from "untrusted AND scanning at MEDIUM or worse" to just "untrusted", and the task deletes everything that comes back. Check : dir/server/database/gorm/record.go / scanSeveritiesGTE - returns nil for "MEDUIM"
Optionally extend the existing TestConfig_GetScanSeverity neighbourhood in reconciler/tasks/pruneuntrusted/task_test.go with a case asserting NewTask(Config{ScanSeverity: "MEDUIM"}, ...) returns an error.
tkircsi
left a comment
There was a problem hiding this comment.
No limit and no dry-run for a destructive policy. Is it safe?
81e4635 to
c592980
Compare
0e9ad87 to
4a8740f
Compare
Great find, thanks @tkircsi ! I did some refactoring on scan severities and added a validation |
c3f5cdf to
25a7ef5
Compare
It's a good point about limit, I added it. About the dry-run... ok, I added it and enabled it by default. However, I'm not sure this is really necessary |
25a7ef5 to
f9671ef
Compare
1c739d8 to
16eceb9
Compare
| createdBefore := "<" + time.Now().Add(-olderThan).UTC().Format(time.RFC3339) | ||
|
|
||
| cids, err := t.db.GetRecordCIDs( | ||
| types.WithTrusted(t.config.Criteria.Trusted), | ||
| types.WithScanSeverities(t.config.GetMinSeverity()), | ||
| types.WithCreatedAts(createdBefore), | ||
| types.WithLimit(t.config.GetLimit()), | ||
| ) |
There was a problem hiding this comment.
The age floor doesn't protect what it was added to protect. older_than filters on the record's self-declared OASF timestamp, because WithCreatedAts maps to records.oasf_created_at (server/database/gorm/record.go:546), a nullable string column populated verbatim from record.GetCreatedAt().
Three consequences.
- First,
created_atis optional on a record, and the repo's own comment at server/database/gorm/record_exclude.go:56-57 states that "AddRecord always writes '' today" — and '' < '2026-09-29T...' is TRUE in SQL, so any record omitting created_at gets no grace period at all and is eligible on the first run. - Second, the value is attacker-controlled for exactly the records this task targets: an untrusted record claiming created_at: 2099-… is never pruned, one claiming 1970 is pruned immediately.
- Third, it's a lexicographic string comparison rather than a timestamp one, so non-UTC offsets or fractional seconds misorder near the cutoff.
Proposal
Switch the age floor from the record's self-declared oasf_created_at to the index's own records.created_at, which is the local first-seen timestamp. That column already exists on the model (server/database/gorm/record.go:48), it just has no filter option. Make it a time.Time compared as a timestamp rather than a string.
There was a problem hiding this comment.
I added a WithIndexedBefore filter option for this
16eceb9 to
3e373c5
Compare
Signed-off-by: Bendegúz Csirmaz <[email protected]>
3e373c5 to
c1eb756
Compare
ramizpolic
left a comment
There was a problem hiding this comment.
LGTM w/ nit
please create an issue for the verification state UNKNOWN vs FAILED so that we can patch it up later
|
#2136
Adds the prune job to reconciler.
The behaviour is similar to the prune-untrusted K8S CronJob.