Coverage / crates/hub/src/history_scan.rs 91.2%
279 of 306 lines run, 48 of 85 functions · run #518 on main · run missed
| 1 | //! The history scan (hub spec §15.4, oxygenhub#277): push protection's | |
| 2 | //! rules run over what a repository already holds, so a secret committed | |
| 3 | //! before push protection existed, or while it was off, is found too. | |
| 4 | //! | |
| 5 | //! What is scanned is every change reachable from the repository's | |
| 6 | //! bookmarks: the lines it inserts and the text blobs it puts in place of | |
| 7 | //! a file's content, exactly what push protection reads in a push. A | |
| 8 | //! repository's progress is a row in `secret_scans`: the heads whose | |
| 9 | //! history is scanned (`done_heads`), and while a scan is under way the | |
| 10 | //! heads it works toward (`target_heads`) and how far it got (`position` | |
| 11 | //! in its list of changes: those reachable from the target and not from | |
| 12 | //! the done heads, in clock order then by hash, so the same list every | |
| 13 | //! pass). A pass scans within a [`Budget`] and saves where it stopped; the | |
| 14 | //! next one resumes there. Once the list is done the target becomes the | |
| 15 | //! done heads, so after a push only the new changes are scanned. A change | |
| 16 | //! of rules (`version` in `push_protection.toml`) or a maintainer's "Scan | |
| 17 | //! history now" scans the whole history again; findings are kept one per | |
| 18 | //! value and file, so a rescan adds nothing already known and keeps what | |
| 19 | //! was resolved. | |
| 20 | //! | |
| 21 | //! The scan is the worker role's `secrets.history_scan` task (docs/roles.md), | |
| 22 | //! one repository at a time, one pass each in turn, on one blocking thread | |
| 23 | //! that rests as long as it works: at most half a core, so it never starves | |
| 24 | //! requests. It reads repositories with the shared lock only, as pages do. | |
| 25 | //! Repositories with push protection off are not scanned. | |
| 26 | | |
| 27 | use crate; | |
| 28 | use crateConfig; | |
| 29 | use crate; | |
| 30 | use crate; | |
| 31 | use crate; | |
| 32 | use crateShared; | |
| 33 | use ; | |
| 34 | use ; | |
| 35 | use Bundle; | |
| 36 | use Repo; | |
| 37 | use ; | |
| 38 | use ; | |
| 39 | ||
| 40 | /// How much one pass over one repository may scan: `bytes` of text (a | |
| 41 | /// change counts at least one, however little it adds) and `time` | |
| 42 | /// wall-clock (resting included), each file or inserted text at most | |
| 43 | /// `file` bytes. At least one change is scanned per pass, so a pass always | |
| 44 | /// gets somewhere. | |
| 45 | | |
| 46 | | |
| 47 | | |
| 48 | | |
| 49 | | |
| 50 | | |
| 51 | ||
| 52 | | |
| 53 | 208× | |
| 54 | 208× | |
| 55 | 208× | |
| 56 | | |
| 57 | ||
| 58 | | |
| 59 | | |
| 60 | 331× | |
| 61 | 331× | |
| 62 | 331× | |
| 63 | 320× | |
| 64 | 320× | |
| 65 | 320× | |
| 66 | 320× | |
| 67 | 331× | |
| 68 | | |
| 69 | ||
| 70 | /// What one pass did. | |
| 71 | | |
| 72 | | |
| 73 | | |
| 74 | | |
| 75 | | |
| 76 | | |
| 77 | | |
| 78 | | |
| 79 | | |
| 80 | | |
| 81 | | |
| 82 | | |
| 83 | ||
| 84 | /// How long the worker waits after starting before its first sweep, so a | |
| 85 | /// starting hub serves first. | |
| 86 | const START_DELAY: Duration = from_secs; | |
| 87 | ||
| 88 | /// How long it rests between repositories. | |
| 89 | const PAUSE: Duration = from_millis; | |
| 90 | ||
| 91 | /// Every repository is looked at again this often, for the pushes the bus | |
| 92 | /// did not tell of (it delivers at most once) and bookmarks moved without | |
| 93 | /// a push (landings). | |
| 94 | const SWEEP_EVERY: Duration = from_secs; | |
| 95 | ||
| 96 | /// The bus topic a "Scan history now" is announced on, its kind the | |
| 97 | /// repository's id. | |
| 98 | pub const REQUEST_TOPIC: &str = "secrets:scan"; | |
| 99 | ||
| 100 | /// The worker role's task: every repository first, then those a push, a | |
| 101 | /// request or a sweep says have something new, each a pass at a time. | |
| 102 | 198× | pub async |
| 103 | 198× | |
| 104 | | |
| 105 | 2× | |
| 106 | | |
| 107 | 196× | |
| 108 | 196× | |
| 109 | 6× | |
| 110 | 6× | |
| 111 | | |
| 112 | 13× | |
| 113 | 13× | |
| 114 | 6× | |
| 115 | 6× | |
| 116 | 7× | |
| 117 | 13× | |
| 118 | 13× | |
| 119 | 13× | |
| 120 | 13× | |
| 121 | 12× | |
| 122 | 12× | |
| 123 | 12× | |
| 124 | 1× | |
| 125 | 11× | |
| 126 | 11× | |
| 127 | 11× | |
| 128 | 11× | |
| 129 | 0× | |
| 130 | 11× | |
| 131 | 11× | |
| 132 | 2× | |
| 133 | | |
| 134 | | |
| 135 | | |
| 136 | | |
| 137 | | |
| 138 | 9× | |
| 139 | | |
| 140 | 0× | |
| 141 | | |
| 142 | 11× | |
| 143 | | |
| 144 | 11× | |
| 145 | 11× | |
| 146 | 4× | |
| 147 | 7× | |
| 148 | | |
| 149 | 7× | |
| 150 | 7× | |
| 151 | | |
| 152 | 13× | |
| 153 | 13× | |
| 154 | 9× | |
| 155 | 0× | |
| 156 | 0× | |
| 157 | | |
| 158 | 13× | |
| 159 | | |
| 160 | | |
| 161 | 3× | |
| 162 | | |
| 163 | 3× | |
| 164 | 3× | |
| 165 | 0× | |
| 166 | | |
| 167 | 0× | |
| 168 | ||
| 169 | /// Take the events waiting: the repositories they name go in `dirty`. | |
| 170 | /// Whether events were lost, so everything should be looked at. | |
| 171 | 26× | |
| 172 | | |
| 173 | | |
| 174 | 108× | |
| 175 | 82× | |
| 176 | 82× | |
| 177 | 27× | |
| 178 | 55× | |
| 179 | | |
| 180 | 0× | |
| 181 | 26× | |
| 182 | | |
| 183 | | |
| 184 | 26× | |
| 185 | ||
| 186 | /// The repository an event says has something to scan: a push to it | |
| 187 | /// (`repo:N`, `push`), or a maintainer's request. | |
| 188 | 96× | |
| 189 | 96× | |
| 190 | 95× | |
| 191 | 1× | |
| 192 | 94× | |
| 193 | 94× | |
| 194 | 62× | |
| 195 | 32× | |
| 196 | 32× | |
| 197 | 96× | |
| 198 | ||
| 199 | /// Ask for repository `repo_id`'s whole history to be scanned again now | |
| 200 | /// ("Scan history now", maintain role). | |
| 201 | 1× | pub async |
| 202 | 1× | |
| 203 | 1× | |
| 204 | 1× | |
| 205 | 1× | |
| 206 | ||
| 207 | /// Tell the worker that repository `repo_id` may have history to scan (its | |
| 208 | /// push protection was turned back on). | |
| 209 | 3× | |
| 210 | 3× | |
| 211 | 3× | |
| 212 | ||
| 213 | 20× | |
| 214 | 106× | |
| 215 | 20× | |
| 216 | ||
| 217 | 50× | |
| 218 | 50× | |
| 219 | 50× | |
| 220 | ||
| 221 | /// One pass over `row`'s history within `budget`: resume the scan under | |
| 222 | /// way, or start one toward the bookmarks if they moved past what was | |
| 223 | /// scanned; record what it finds and where it stopped. | |
| 224 | 24× | pub async |
| 225 | 24× | |
| 226 | 24× | |
| 227 | 24× | |
| 228 | 24× | |
| 229 | 24× | |
| 230 | 7× | |
| 231 | 7× | |
| 232 | 7× | |
| 233 | 7× | |
| 234 | 7× | |
| 235 | 17× | |
| 236 | 24× | |
| 237 | 24× | |
| 238 | 24× | |
| 239 | 24× | |
| 240 | 24× | |
| 241 | 24× | |
| 242 | 0× | |
| 243 | 0× | |
| 244 | 0× | |
| 245 | 0× | |
| 246 | 0× | |
| 247 | | |
| 248 | | |
| 249 | 24× | |
| 250 | | |
| 251 | 5× | |
| 252 | 19× | |
| 253 | 19× | |
| 254 | 19× | |
| 255 | 19× | |
| 256 | 19× | |
| 257 | 7× | |
| 258 | 7× | |
| 259 | 7× | |
| 260 | 7× | |
| 261 | 7× | |
| 262 | 7× | |
| 263 | 7× | |
| 264 | 7× | |
| 265 | 7× | |
| 266 | 7× | |
| 267 | 7× | |
| 268 | 19× | |
| 269 | 19× | |
| 270 | 19× | |
| 271 | 19× | |
| 272 | 14× | |
| 273 | 14× | |
| 274 | 14× | |
| 275 | 14× | |
| 276 | 14× | |
| 277 | 14× | |
| 278 | 14× | |
| 279 | 14× | |
| 280 | 5× | |
| 281 | 5× | |
| 282 | 5× | |
| 283 | 5× | |
| 284 | 5× | |
| 285 | 19× | |
| 286 | 19× | |
| 287 | 19× | |
| 288 | 19× | |
| 289 | 19× | |
| 290 | 19× | |
| 291 | 24× | |
| 292 | ||
| 293 | /// Save `s` unless a maintainer asked for a new scan while the pass ran: | |
| 294 | /// that request's fresh start wins. | |
| 295 | 19× | async |
| 296 | 19× | |
| 297 | 19× | |
| 298 | 0× | |
| 299 | 19× | |
| 300 | 19× | |
| 301 | 19× | |
| 302 | ||
| 303 | /// Where a scan stands, as read from its row. | |
| 304 | | |
| 305 | | |
| 306 | | |
| 307 | | |
| 308 | | |
| 309 | ||
| 310 | /// What [`scan_in`] did. | |
| 311 | | |
| 312 | | |
| 313 | | |
| 314 | | |
| 315 | | |
| 316 | | |
| 317 | | |
| 318 | | |
| 319 | | |
| 320 | | |
| 321 | | |
| 322 | ||
| 323 | /// The pass itself, on a blocking thread with the repository open. | |
| 324 | 24× | |
| 325 | 24× | |
| 326 | 24× | |
| 327 | 24× | |
| 328 | 54× | |
| 329 | 54× | |
| 330 | | |
| 331 | | |
| 332 | | |
| 333 | 88× | |
| 334 | 54× | |
| 335 | 24× | |
| 336 | 24× | |
| 337 | 24× | |
| 338 | 24× | |
| 339 | 24× | |
| 340 | 24× | |
| 341 | 19× | |
| 342 | 5× | |
| 343 | 14× | |
| 344 | 14× | |
| 345 | 14× | |
| 346 | 5× | |
| 347 | 19× | |
| 348 | 19× | |
| 349 | | |
| 350 | | |
| 351 | 0× | |
| 352 | 0× | |
| 353 | 0× | |
| 354 | 0× | |
| 355 | | |
| 356 | 0× | |
| 357 | | |
| 358 | | |
| 359 | 39× | |
| 360 | 45× | |
| 361 | | |
| 362 | 0× | |
| 363 | 0× | |
| 364 | 0× | |
| 365 | | |
| 366 | | |
| 367 | 19× | |
| 368 | 119× | |
| 369 | 19× | |
| 370 | 19× | |
| 371 | 19× | |
| 372 | 0× | |
| 373 | 19× | |
| 374 | 19× | |
| 375 | 19× | |
| 376 | 19× | |
| 377 | 19× | |
| 378 | 19× | |
| 379 | 63× | |
| 380 | 49× | |
| 381 | 5× | |
| 382 | 44× | |
| 383 | 44× | |
| 384 | 44× | |
| 385 | 44× | |
| 386 | 44× | |
| 387 | 44× | |
| 388 | 44× | |
| 389 | 44× | |
| 390 | 7× | |
| 391 | 7× | |
| 392 | 7× | |
| 393 | 7× | |
| 394 | 7× | |
| 395 | 23× | |
| 396 | 7× | |
| 397 | 7× | |
| 398 | 7× | |
| 399 | 7× | |
| 400 | 37× | |
| 401 | 44× | |
| 402 | 44× | |
| 403 | | |
| 404 | 44× | |
| 405 | 44× | |
| 406 | 0× | |
| 407 | 0× | |
| 408 | 44× | |
| 409 | | |
| 410 | 19× | |
| 411 | 24× | |
| 412 | ||
| 413 | /// `heads` and every change they depend on, by `deps`. | |
| 414 | 25× | |
| 415 | 25× | |
| 416 | 25× | |
| 417 | 105× | |
| 418 | 80× | |
| 419 | 12× | |
| 420 | 68× | |
| 421 | 68× | |
| 422 | 67× | |
| 423 | 1× | |
| 424 | | |
| 425 | 25× | |
| 426 | 25× | |
| 427 | ||
| 428 | /// One stored change as push protection reads a push: the change, and the | |
| 429 | /// blobs (with their chunks, unless over the file budget) its edits put in | |
| 430 | /// place of a file's content. A blob the store does not hold (lazy) is | |
| 431 | /// left out, so it is not scanned. | |
| 432 | 44× | |
| 433 | 44× | |
| 434 | 44× | |
| 435 | 44× | |
| 436 | 52× | |
| 437 | 47× | |
| 438 | 5× | |
| 439 | 5× | |
| 440 | 5× | |
| 441 | 5× | |
| 442 | 5× | |
| 443 | 5× | |
| 444 | 5× | |
| 445 | | |
| 446 | 0× | |
| 447 | 5× | |
| 448 | | |
| 449 | 44× | |
| 450 | 44× | |
| 451 | ||
| 452 | | |
| 453 | | |
| 454 | | |
| 455 | | |
| 456 | | |
| 457 | 1× | |
| 458 | 4× | |
| 459 | 1× | |
| 460 | 1× | |
| 461 | 1× | |
| 462 | 1× | |
| 463 | 1× | |
| 464 | 1× | |
| 465 | | |
| 466 | | |
| 467 | 1× | |
| 468 | 1× | |
| 469 | 1× | |
| 470 | 1× | |
| 471 | 1× | |
| 472 | 1× | |
| 473 | |