-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Config Protection Proposal - Bounty #30 ($75) #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Config Protection for UbiquityOS Plugins | ||
|
|
||
| **Issue:** [#30](https://github.com/ubiquity-os/plugins-wishlist/issues/30) | ||
| **Reward:** $75 | ||
| **Status:** Proposal | ||
|
|
||
| ## Problem | ||
|
|
||
| Plugin configuration files control money flow, pricing, and reward distribution in UbiquityOS. Currently, any collaborator with write access can modify these configs, creating a fraud risk. By default, only admins or billing managers should be authorized to change configuration that affects financial operations, but this can be configured per repository. | ||
|
|
||
| ## Proposed Solution | ||
|
|
||
| A multi-layered configuration protection mechanism: | ||
|
|
||
| ### Layer 1: CODEOWNERS Gate | ||
|
|
||
| Add a `CODEOWNERS` file that restricts review approval on config files to designated admins/billing managers: | ||
|
|
||
| ```codeowners | ||
| # Config files require admin approval | ||
| /ubiquity.config.* @ubiquity/admins | ||
| /.github/ubiquity.config.* @ubiquity/admins | ||
| /**/pricing.yml @ubiquity/admins | ||
| /**/config.yml @ubiquity/admins | ||
| ``` | ||
|
|
||
| Combined with branch protection requiring CODEOWNERS approval on the default branch, this ensures config changes cannot be merged without admin review. | ||
|
|
||
| ### Layer 2: Webhook-Level Rollback | ||
|
|
||
| On `push` events, a UbiquityOS plugin detects whether config files were modified: | ||
|
|
||
| 1. **Diff Detection:** Compare the config file SHA before and after the push using the GitHub Compare API. | ||
| 2. **Authorization Check:** Verify the pusher has `admin` or `billing_manager` role via the repository collaborator API (`GET /repos/{owner}/{repo}/collaborators/{username}/permission`). | ||
| 3. **Automatic Rollback:** If the change is unauthorized, immediately create a new commit restoring the previous config version, authored by `ubiquibot[bot]`. | ||
|
|
||
| ```text | ||
| Push → Detect config change → Check author role | ||
| ├─ Authorized → Allow, log the change | ||
| └─ Unauthorized → Auto-rollback commit, notify admins | ||
| ``` | ||
|
|
||
| ### Layer 3: Audit Trail | ||
|
|
||
| All config changes (authorized or rolled back) are logged: | ||
| - Comment on the relevant issue/PR with the change details | ||
| - Post to a designated audit channel | ||
| - Store a SHA-256 hash chain of config states for tamper detection | ||
|
|
||
| ## Implementation Plan | ||
|
|
||
| ### Phase 1: Core Plugin (MVP) | ||
|
|
||
| 1. **Create `config-protection` plugin** — a new UbiquityOS plugin listening to `push` events. | ||
| 2. **Config diff detection** — On each push, check if watched config files changed: | ||
| ```typescript | ||
| const CONFIG_PATTERNS = ["ubiquity.config.*", "pricing.yml", ".github/ubiquity.config.*"]; | ||
| ``` | ||
| 3. **Permission check** — Use `octokit.repos.getCollaboratorPermissionLevel()` to verify the pusher's role. | ||
| 4. **Rollback mechanism** — If unauthorized: | ||
| ```typescript | ||
| // Get previous commit's config content | ||
| const previousConfig = await octokit.repos.getContent({ ref: previousSha, ... }); | ||
| // Create rollback commit via Trees API | ||
| await octokit.git.createCommit({ | ||
| message: "🔒 Unauthorized config change rolled back", | ||
| tree: previousTreeSha, | ||
| parents: [currentCommitSha] | ||
| }); | ||
| ``` | ||
| 5. **Notification** — Comment on the repo or open an issue alerting admins. | ||
|
|
||
| ### Phase 2: Hardening | ||
|
|
||
| 6. **CODEOWNERS setup** — Generate and maintain CODEOWNERS based on org admin list. | ||
| 7. **Hash chain** — Store config hashes in a dedicated branch (`config-audit`) for tamper-proof history. | ||
| 8. **Dashboard** — Web view of config change history. | ||
|
|
||
| ### Phase 3: Organization-Wide | ||
|
|
||
| 9. **Org-level enforcement** — Apply across all repos in the UbiquityOS organization via a GitHub App. | ||
| 10. **Tie-breaker mechanism** — For orgs with multiple admins, require N-of-M approval for sensitive config changes. | ||
|
|
||
| ## Technical Details | ||
|
|
||
| ### Event Flow | ||
|
|
||
| ```text | ||
| GitHub Push Event | ||
| → Plugin receives webhook | ||
| → Check if config files changed (list modified files from commits) | ||
| → If changed: | ||
| → GET /repos/{owner}/{repo}/collaborators/{pusher}/permission | ||
| → If permission != "admin" && role != "billing_manager": | ||
| → Revert commit (Git Data API: create commit pointing to previous tree) | ||
| → Update ref (force push the branch back) | ||
| → POST notification (issue comment / discussion) | ||
| ``` | ||
|
|
||
| ### Key Design Decisions | ||
|
|
||
| - **Why rollback over rejection?** Webhooks are post-event; the commit already exists. Rollback is the only option. | ||
| - **Why not pre-commit hooks?** Pre-commit hooks are client-side and can be bypassed. Server-side enforcement via webhooks is reliable. | ||
| - **Why CODEOWNERS + webhook?** Defense in depth. CODEOWNERS prevents merging unauthorized PRs; webhook catches direct pushes. | ||
|
|
||
| ### Config Schema | ||
|
|
||
| ```json | ||
| { | ||
| "protectedFiles": ["ubiquity.config.ts", "pricing.yml"], | ||
| "authorizedRoles": ["admin", "billing_manager"], | ||
| "rollbackBot": "ubiquibot[bot]", | ||
| "notifyChannel": "config-audit" | ||
| } | ||
| ``` | ||
|
|
||
| ## Testing Plan | ||
|
|
||
| 1. **Unit tests:** Config diff detection, permission checks, rollback logic. | ||
| 2. **Integration tests:** Simulate push events with modified configs from different user roles. | ||
| 3. **E2E test:** Push an unauthorized config change to a test repo and verify rollback. | ||
|
|
||
| ## References | ||
|
|
||
| - [Assistive Pricing get-base-rate-changes](https://github.com/ubiquibot/assistive-pricing/blob/d259e29b2896026a164e7c1af4f2b72ce31fe90c/src/handlers/get-base-rate-changes.ts) | ||
| - [GitHub CODEOWNERS docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners) | ||
| - [GitHub Collaborator Permission API](https://docs.github.com/en/rest/collaborators/collaborators) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
What are the valid permission levels returned by GitHub's GET /repos/{owner}/{repo}/collaborators/{username}/permission API?💡 Result:
GET /repos/{owner}/{repo}/collaborators/{username}/permissionreturns apermissionvalue that is one of the legacy base roles:adminwritereadnone[1](If you need the non-legacy role, use the
role_namefield, which can includemaintain,triage, or a custom repository role name.) [1]Sources:
[1] GitHub Docs – “Get repository permissions for a user” (REST API: Collaborators) (docs.github.com)
Citations:
GitHub API endpoint doesn't support "billing_manager" role.
The
GET /repos/{owner}/{repo}/collaborators/{username}/permissionAPI returns only:admin,write,read,none(ormaintain,triageviarole_name). Define how authorization checks will identify billing managers—via GitHub team membership or custom metadata instead.