Commit 5c065ca
authored
rust-guard/tools.rs: add BLOCKED_TOOLS const and predicate test coverage (#4943)
`is_blocked_tool()` inlined its list in a `matches!()` expression,
inconsistent with the discoverable
`WRITE_OPERATIONS`/`READ_WRITE_OPERATIONS` const arrays and invisible to
any caller wanting to enumerate blocked tools. Four predicate functions
(`is_merge_operation`, `is_delete_operation`, `is_lock_operation`,
`is_unlock_operation`) had zero test coverage despite being
security-critical paths in `labels/tool_rules.rs`.
## Changes
- **`BLOCKED_TOOLS` const array** — extracted from `is_blocked_tool()`'s
`matches!()` body into a `pub const &[&str]` parallel to
`WRITE_OPERATIONS`/`READ_WRITE_OPERATIONS`, with per-entry comments:
```rust
pub const BLOCKED_TOOLS: &[&str] = &[
"transfer_repository", // irreversible ownership transfer
"archive_repository", // repo settings change; unsupported
"unarchive_repository", // symmetric to archive_repository
"rename_repository", // breaks clone URLs and integrations
"create_agent_task", // unsupported agent-task creation
];
pub fn is_blocked_tool(tool_name: &str) -> bool {
BLOCKED_TOOLS.contains(&tool_name)
}
```
- **Predicate test coverage** — added `test_is_merge_operation`,
`test_is_delete_operation`, `test_is_lock_operation`,
`test_is_unlock_operation` (each with positive, negative, and
empty-string cases), plus
`test_lock_and_unlock_contribute_to_write_operations` to verify
`is_write_operation`'s delegation to the lock/unlock predicates.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build2801713912/b513/launcher.test
/tmp/go-build2801713912/b513/launcher.test
-test.testlogfile=/tmp/go-build2801713912/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ortc�� .cfg
64/src/html/enti-ifaceassert x_amd64/vet . ions =0 x_amd64/vet .cfg��
0430085/b366/_pkg_.a 0430085/b314/ x_amd64/vet --gdwarf-5 rse
p=/opt/hostedtoo--format x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2801713912/b495/config.test
/tmp/go-build2801713912/b495/config.test
-test.testlogfile=/tmp/go-build2801713912/b495/testlog.txt
-test.paniconexit0 -test.timeout=10m0s 0430��
1.80.0/encoding/gzip/gzip.go aw-mcpg/internal/difc/capabilities.go
x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet -I g_.a -I x_amd64/vet
--gdwarf-5 telabs/wazero/ap-atomic -o x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build2801713912/b513/launcher.test
/tmp/go-build2801713912/b513/launcher.test
-test.testlogfile=/tmp/go-build2801713912/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ortc�� .cfg
64/src/html/enti-ifaceassert x_amd64/vet . ions =0 x_amd64/vet .cfg��
0430085/b366/_pkg_.a 0430085/b314/ x_amd64/vet --gdwarf-5 rse
p=/opt/hostedtoo--format x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build2801713912/b513/launcher.test
/tmp/go-build2801713912/b513/launcher.test
-test.testlogfile=/tmp/go-build2801713912/b513/testlog.txt
-test.paniconexit0 -test.timeout=10m0s ortc�� .cfg
64/src/html/enti-ifaceassert x_amd64/vet . ions =0 x_amd64/vet .cfg��
0430085/b366/_pkg_.a 0430085/b314/ x_amd64/vet --gdwarf-5 rse
p=/opt/hostedtoo--format x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build2801713912/b522/mcp.test
/tmp/go-build2801713912/b522/mcp.test
-test.testlogfile=/tmp/go-build2801713912/b522/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -W .cfg k/gh-aw-mcpg/gh--w
x_amd64/vet . --gdwarf2 --64 x_amd64/vet .cfg�� 0430085/b400/_pkg_.a
pkg/mod/go.opentelemetry.io/otel/sdk@v1.43.0/internal/x/x.go x_amd64/vet
--gdwarf-5 g/grpc/internal//usr/bin/runc -o x_amd64/vet` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>1 file changed
Lines changed: 67 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
159 | 172 | | |
160 | 173 | | |
161 | 174 | | |
| |||
174 | 187 | | |
175 | 188 | | |
176 | 189 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 190 | + | |
185 | 191 | | |
186 | 192 | | |
187 | 193 | | |
188 | 194 | | |
189 | 195 | | |
190 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
191 | 207 | | |
192 | 208 | | |
193 | 209 | | |
| |||
420 | 436 | | |
421 | 437 | | |
422 | 438 | | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
423 | 482 | | |
424 | 483 | | |
425 | 484 | | |
| |||
0 commit comments