diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-12 17:40:25 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-12 17:40:25 +0000 |
| commit | c29191b1e1239e931c575a926ec9480e594476d6 (patch) | |
| tree | 6fcb776ba34b6fab766ceb613997b07b18e780df /docs/explanation | |
| parent | 2b8992631b9dedcfd4ea44e8565b14ac8a5ed8ea (diff) | |
feat(grasp-05): implement archive mode for backup/mirror operation
Implements GRASP-05 specification for accepting repository announcements
that don't list this relay, enabling archive, mirror, and backup use cases.
Core Features:
- Three whitelist formats: <npub>, <npub>/<identifier>, <identifier>
- Archive-all mode for complete ecosystem mirrors
- Fail-fast npub validation at startup
- Read-only enforcement (archived repos reject pushes)
- Full GRASP-02 sync (git data + Nostr events)
- Dynamic archive status (no flags/metadata)
Implementation:
- Add ArchiveWhitelistEntry enum with Pubkey/Repository/Identifier variants
- Add ArchiveConfig with validation and matching logic
- Update AnnouncementResult to include AcceptArchive variant
- Refactor validate_announcement() to return AnnouncementResult with archive check
- Update AnnouncementPolicy with catch-all pattern for cleaner code
- Wire archive config through builder and policy layers
Configuration:
- NGIT_ARCHIVE_ALL: Accept all announcements (⚠️ storage risk)
- NGIT_ARCHIVE_WHITELIST: Comma-separated whitelist entries
- Updated docs, .env.example, and nix/module.nix
Testing:
- 28 unit tests for config parsing and whitelist matching
- 7 integration tests for archive mode validation
- All 296 tests passing
Validation Priority:
1. Lists our service → Accept (GRASP-01, read/write)
2. Is maintainer → AcceptMaintainer (multi-maintainer, read/write)
3. Matches archive config → AcceptArchive (GRASP-05, read-only)
4. None of above → Reject
Security Considerations:
- Archive-all mode has storage/bandwidth DoS risk
- Identifier-only format matches any pubkey (use npub/identifier for high-value)
- Invalid npubs cause startup failure (fail-fast)
Documentation:
- Concise explanation focused on rationale
- Reference docs updated with all config options
- README updated to reflect completed feature
- Removed from roadmap, added to compliance section
See docs/explanation/grasp-05-archive.md for details.
Diffstat (limited to 'docs/explanation')
| -rw-r--r-- | docs/explanation/grasp-05-archive.md | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/docs/explanation/grasp-05-archive.md b/docs/explanation/grasp-05-archive.md new file mode 100644 index 0000000..e43a87e --- /dev/null +++ b/docs/explanation/grasp-05-archive.md | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | # GRASP-05 Archive Mode | ||
| 2 | |||
| 3 | **Purpose:** Understand archive/mirror/backup functionality | ||
| 4 | **Audience:** Operators and developers | ||
| 5 | |||
| 6 | --- | ||
| 7 | |||
| 8 | ## What It Does | ||
| 9 | |||
| 10 | GRASP-05 enables ngit-grasp to accept repository announcements that **don't list your relay**, allowing you to run an archive, mirror, or backup service. | ||
| 11 | |||
| 12 | **Standard GRASP-01:** Announcement must list your service → You host it (read/write) | ||
| 13 | **GRASP-05 Extension:** Announcement matches your whitelist → You archive it (read-only) | ||
| 14 | |||
| 15 | ## Why It Exists | ||
| 16 | |||
| 17 | ### Problem | ||
| 18 | In GRASP-01 strict mode, you can only host repositories whose maintainers explicitly list your relay. This prevents: | ||
| 19 | - Creating backup archives of critical projects without maintainer cooperation | ||
| 20 | - Building comprehensive mirrors of the Nostr Git ecosystem | ||
| 21 | - Providing disaster recovery for projects that might disappear | ||
| 22 | |||
| 23 | ### Solution | ||
| 24 | Archive mode relaxes the "must list service" requirement for whitelisted repositories, enabling passive mirroring while maintaining read-only guarantees. | ||
| 25 | |||
| 26 | ## How It Works | ||
| 27 | |||
| 28 | ### Three Whitelist Formats | ||
| 29 | |||
| 30 | | Format | Example | Archives | | ||
| 31 | |--------|---------|----------| | ||
| 32 | | `<npub>` | `npub1alice...` | All repos from Alice | | ||
| 33 | | `<npub>/<identifier>` | `npub1bob.../linux` | Only Bob's linux repo | | ||
| 34 | | `<identifier>` | `bitcoin-core` | Any bitcoin-core repo (⚠️ any pubkey) | | ||
| 35 | |||
| 36 | **Configuration:** | ||
| 37 | ```bash | ||
| 38 | # Specific repos (safest) | ||
| 39 | NGIT_ARCHIVE_WHITELIST=npub1torvalds.../linux,npub1satoshi.../bitcoin | ||
| 40 | |||
| 41 | # All repos from trusted maintainers | ||
| 42 | NGIT_ARCHIVE_WHITELIST=npub1alice...,npub1bob... | ||
| 43 | |||
| 44 | # Archive everything (⚠️ storage risk) | ||
| 45 | NGIT_ARCHIVE_ALL=true | ||
| 46 | ``` | ||
| 47 | |||
| 48 | ### Validation Priority | ||
| 49 | |||
| 50 | Announcements are checked in this order: | ||
| 51 | |||
| 52 | 1. **Lists your service?** → `Accept` (GRASP-01, read/write) | ||
| 53 | 2. **Is author a maintainer?** → `AcceptMaintainer` (multi-maintainer, read/write) | ||
| 54 | 3. **Matches archive config?** → `AcceptArchive` (GRASP-05, read-only) | ||
| 55 | 4. **None of the above** → `Reject` | ||
| 56 | |||
| 57 | This ensures GRASP-01 compliant repos are always writable, even if they match the archive whitelist. | ||
| 58 | |||
| 59 | ### Storage Model | ||
| 60 | |||
| 61 | Archived repos use the same directory structure as hosted repos: | ||
| 62 | ``` | ||
| 63 | <git_data_path>/ | ||
| 64 | npub1alice.../ | ||
| 65 | hosted-repo.git/ # Lists your service (writable) | ||
| 66 | archived-repo.git/ # Whitelisted (read-only) | ||
| 67 | ``` | ||
| 68 | |||
| 69 | **No flags or metadata** - archive status determined dynamically from config + announcement contents. | ||
| 70 | |||
| 71 | ### Full Sync | ||
| 72 | |||
| 73 | Archived repositories trigger complete GRASP-02 sync: | ||
| 74 | - ✅ Nostr events (PRs, issues, patches) | ||
| 75 | - ✅ Git data via purgatory | ||
| 76 | - ✅ Same validation as hosted repos | ||
| 77 | |||
| 78 | Archive mode is a **complete mirror**, not just git-only backup. | ||
| 79 | |||
| 80 | ## Security Considerations | ||
| 81 | |||
| 82 | ### 1. Archive-All Mode (Dangerous) | ||
| 83 | |||
| 84 | **Don't use `NGIT_ARCHIVE_ALL=true` unless:** | ||
| 85 | - You have unlimited storage/bandwidth | ||
| 86 | - You trust the relay network | ||
| 87 | - You've implemented monitoring | ||
| 88 | |||
| 89 | **Attack vector:** Anyone can publish announcements → unlimited storage consumption. | ||
| 90 | |||
| 91 | ### 2. Identifier-Only Format (Risky) | ||
| 92 | |||
| 93 | ```bash | ||
| 94 | NGIT_ARCHIVE_WHITELIST=bitcoin-core # Matches ANY pubkey! | ||
| 95 | ``` | ||
| 96 | |||
| 97 | Malicious users can publish fake repos with popular identifiers. Use `<npub>/<identifier>` for high-value archives. | ||
| 98 | |||
| 99 | ### 3. Npub Validation | ||
| 100 | |||
| 101 | Invalid npubs → server fails to start (fail-fast). Identifiers aren't validated (any string allowed). | ||
| 102 | |||
| 103 | ## Operational Guide | ||
| 104 | |||
| 105 | ### Start Small | ||
| 106 | |||
| 107 | ```bash | ||
| 108 | # Day 1: One critical repo | ||
| 109 | NGIT_ARCHIVE_WHITELIST=npub1torvalds.../linux | ||
| 110 | |||
| 111 | # Week 1: Add trusted maintainers | ||
| 112 | NGIT_ARCHIVE_WHITELIST=npub1alice...,npub1bob... | ||
| 113 | |||
| 114 | # Month 1: Consider popular identifiers (with monitoring) | ||
| 115 | NGIT_ARCHIVE_WHITELIST=npub1alice...,bitcoin-core | ||
| 116 | ``` | ||
| 117 | |||
| 118 | ### Monitor Growth | ||
| 119 | |||
| 120 | Watch for: | ||
| 121 | - Storage consumption rate | ||
| 122 | - Purgatory git fetch failures | ||
| 123 | - Bandwidth usage spikes | ||
| 124 | |||
| 125 | ### Whitelist Changes | ||
| 126 | |||
| 127 | **Current:** Static config - edit `.env`, restart server | ||
| 128 | **Future:** REST API for dynamic management (no restart) | ||
| 129 | |||
| 130 | ## Comparison: Hosted vs Archived | ||
| 131 | |||
| 132 | | Aspect | Hosted (GRASP-01) | Archived (GRASP-05) | | ||
| 133 | |--------|-------------------|---------------------| | ||
| 134 | | Announcement must list you | ✅ Required | ❌ Whitelisted instead | | ||
| 135 | | Git pushes | ✅ Accepted | ❌ Rejected (read-only) | | ||
| 136 | | GRASP-02 sync | ✅ Full sync | ✅ Full sync | | ||
| 137 | | Relay discovery | ✅ Listed | ❌ Not listed | | ||
| 138 | | Use case | Hosting workspace | Backup/mirror | | ||
| 139 | |||
| 140 | ## Related Documentation | ||
| 141 | |||
| 142 | - [Configuration Reference](../reference/configuration.md) - `NGIT_ARCHIVE_*` options | ||
| 143 | - [GRASP-05 Spec](https://gitworkshop.dev/danconwaydev.com/grasp/05.md) - Protocol specification | ||
| 144 | - [GRASP-02 Sync](./grasp-02-proactive-sync.md) - How sync works | ||
| 145 | |||
| 146 | --- | ||
| 147 | |||
| 148 | _Part of the [ngit-grasp explanation documentation](./)_ | ||