feat(projects): add new-repo project overview and provisioning plan
- Create projects/new-repo/overview.md with architecture and security model. - Create projects/new-repo/plans/provisioning-cli-plan.md with CLI spec, traits, and milestones.
This commit is contained in:
1 parent
90b77cf1f0
commit
0b154210c2
2 files changed
+189
No files matched your search
@@ -0,0 +1,74 @@
|
|||||||
|
---
|
||||||
|
type: project
|
||||||
|
status: active
|
||||||
|
tags:
|
||||||
|
- gitea
|
||||||
|
- github
|
||||||
|
- rust
|
||||||
|
- automation
|
||||||
|
- cli
|
||||||
|
- homelab
|
||||||
|
---
|
||||||
|
# 🚀 new-repo — Automated Repository Provisioning CLI
|
||||||
|
|
||||||
|
## 🎯 Overview
|
||||||
|
|
||||||
|
`new-repo` is a lightweight native Rust command-line utility designed to automate the creation of new repositories across a hybrid Git topology:
|
||||||
|
- **Primary Forge**: Self-hosted Gitea instance (`gitea.roadtotech.me`).
|
||||||
|
- **Offsite Backup Forge**: GitHub (`github.com`) via automated push mirroring.
|
||||||
|
|
||||||
|
It eliminates repetitive manual setup by providing sensible defaults (Gitea as primary, automated GitHub push mirroring, `UNLICENSE` default, private visibility) while supporting Gitea repository templates and optional standalone configurations.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏛️ System Architecture & Workflow
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
autonumber
|
||||||
|
actor User as Developer (Laptop)
|
||||||
|
participant CLI as new-repo (Rust)
|
||||||
|
participant SOPS as sops (RAM Decrypt)
|
||||||
|
participant Gitea as Gitea API (Primary)
|
||||||
|
participant GitHub as GitHub API (Backup)
|
||||||
|
participant Git as Local Git
|
||||||
|
|
||||||
|
User->>CLI: new-repo <repo-name> [flags]
|
||||||
|
|
||||||
|
alt Using Template (-t <template>)
|
||||||
|
CLI->>Gitea: POST /repos/{owner}/{template}/generate
|
||||||
|
Gitea-->>CLI: Repo created from template
|
||||||
|
else Standard Repo
|
||||||
|
CLI->>Gitea: POST /user/repos (with license & init)
|
||||||
|
Gitea-->>CLI: Repo created
|
||||||
|
end
|
||||||
|
|
||||||
|
opt Mirroring Enabled (Default)
|
||||||
|
CLI->>SOPS: sops -d --extract ["github_mirror_token"]
|
||||||
|
SOPS-->>CLI: In-Memory Token (SecretStr)
|
||||||
|
CLI->>GitHub: POST /user/repos (create target repo)
|
||||||
|
GitHub-->>CLI: 201 Created
|
||||||
|
CLI->>Gitea: POST /repos/{owner}/{repo}/push_mirrors
|
||||||
|
Gitea-->>CLI: Push Mirror Registered
|
||||||
|
end
|
||||||
|
|
||||||
|
opt Auto-clone Enabled (-c / --clone)
|
||||||
|
CLI->>Git: git clone git@gitea.roadtotech.me:user/repo.git
|
||||||
|
Git-->>CLI: Working tree ready
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Security Model
|
||||||
|
|
||||||
|
1. **In-Memory Token Handling**: The GitHub Personal Access Token (`github_mirror_token`) is decrypted strictly in-memory from `secrets.yaml` using `sops`.
|
||||||
|
2. **Zero Command-Line Leaks**: Secrets are transmitted exclusively via native HTTPS request headers (`Authorization: token ...`), preventing token visibility in `/proc/$PID/cmdline` or system process listings (`ps`).
|
||||||
|
3. **Memory Hygiene**: Secret buffers are scrubbed from memory after use.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📑 Project Documents & Plans
|
||||||
|
|
||||||
|
- [**Repository Provisioning CLI Plan**](plans/provisioning-cli-plan.md) — Comprehensive functional specification, trait architecture, API contracts, and implementation milestones.
|
||||||
|
- **Local Implementation Tree**: [`/home/kiskaadee/Projects/active/new-repo`](file:///home/kiskaadee/Projects/active/new-repo)
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
---
|
||||||
|
type: plan
|
||||||
|
status: active
|
||||||
|
project: new-repo
|
||||||
|
tags:
|
||||||
|
- gitea
|
||||||
|
- github
|
||||||
|
- rust
|
||||||
|
- automation
|
||||||
|
- cli
|
||||||
|
- sops
|
||||||
|
---
|
||||||
|
# 📋 Implementation Plan — `new-repo` Provisioning CLI
|
||||||
|
|
||||||
|
## 🎯 Objective
|
||||||
|
Build a fast, type-safe, and self-contained Rust command-line tool (`new-repo`) to provision repositories across self-hosted Gitea and GitHub with automated push mirroring, template generation, and zero plaintext secret leakage.
|
||||||
|
|
||||||
|
**Repository Location**: [`/home/kiskaadee/Projects/active/new-repo`](file:///home/kiskaadee/Projects/active/new-repo)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🛠️ CLI Interface Specification
|
||||||
|
|
||||||
|
Built with `clap` derive macros:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Usage: new-repo <NAME> [OPTIONS]
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
<NAME> Name of the repository to create
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-s, --source <FORGE> Primary forge: 'gitea' (default) or 'github' [default: gitea]
|
||||||
|
-M, --no-mirror Disable offsite push mirroring to GitHub
|
||||||
|
-t, --template <NAME> Optional Gitea template repository to generate from
|
||||||
|
-l, --license <NAME> License identifier [default: UNLICENSE]
|
||||||
|
-p, --public Make repository public (default is private)
|
||||||
|
-c, --clone Automatically clone repository to local directory after creation
|
||||||
|
-h, --help Print help information
|
||||||
|
-V, --version Print version information
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🏛️ Core Architecture & Traits
|
||||||
|
|
||||||
|
The utility adheres to a decoupled architecture separating orchestration from network and secret I/O:
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ main.rs │
|
||||||
|
│ (CLI Parse & Config) │
|
||||||
|
└────────────┬────────────┘
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
┌─────────────────────────┐
|
||||||
|
│ RepoManagerService │
|
||||||
|
│ (Domain Orchestration)│
|
||||||
|
└────────────┬────────────┘
|
||||||
|
│
|
||||||
|
┌──────────────────────┼──────────────────────┐
|
||||||
|
▼ ▼ ▼
|
||||||
|
SecretProvider GiteaClient GitHubClient
|
||||||
|
│ │ │
|
||||||
|
▼ ▼ ▼
|
||||||
|
sops CLI (RAM) HTTPS REST HTTPS REST
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key Traits:
|
||||||
|
|
||||||
|
1. **`SecretProvider`**:
|
||||||
|
- `fn get_github_mirror_token(&self) -> Result<SecretString, Error>`
|
||||||
|
- Invokes `sops -d --extract '["github_mirror_token"]' <secrets_file>` and captures stdout in-memory.
|
||||||
|
2. **`GiteaClient`**:
|
||||||
|
- `fn create_repo(&self, opts: &CreateRepoOptions) -> Result<RepoInfo, Error>`
|
||||||
|
- `fn generate_from_template(&self, template: &str, opts: &GenerateOptions) -> Result<RepoInfo, Error>`
|
||||||
|
- `fn create_push_mirror(&self, repo: &str, mirror: &PushMirrorOptions) -> Result<(), Error>`
|
||||||
|
3. **`GitHubClient`**:
|
||||||
|
- `fn create_repo(&self, name: &str, is_private: bool, license: &str) -> Result<(), Error>`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🔒 Security Invariants
|
||||||
|
|
||||||
|
1. **No Tokens in CLI Flags**: Tokens are injected exclusively via HTTP request headers (`Authorization: token <token>`), preventing process table visibility in `/proc/$PID/cmdline`.
|
||||||
|
2. **In-Memory Lifetime**: Tokens exist only for the duration of the API call and are dropped/zeroized immediately.
|
||||||
|
3. **Fallback Safety**: If GitHub repo creation fails or mirror attachment fails, the Gitea repo is retained and clear diagnostic error messages are returned.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Implementation Milestones
|
||||||
|
|
||||||
|
### Milestone 1 — CLI & Config Definition
|
||||||
|
- Configure `Cargo.toml` dependencies: `clap` (derive), `reqwest` (json, blocking), `serde`, `serde_json`, `thiserror`, `secrecy`.
|
||||||
|
- Define CLI arguments, default values, and parsed configuration structs.
|
||||||
|
|
||||||
|
### Milestone 2 — SOPS Secret Extraction
|
||||||
|
- Implement `SopsSecretProvider` executing `sops` subprocess.
|
||||||
|
- Secure capture of `github_mirror_token` into `SecretString`.
|
||||||
|
|
||||||
|
### Milestone 3 — Gitea API Client
|
||||||
|
- Implement standard repository creation (`POST /user/repos`).
|
||||||
|
- Implement template-based repository generation (`POST /repos/{owner}/{template}/generate`).
|
||||||
|
- Implement push mirror configuration (`POST /repos/{owner}/{repo}/push_mirrors`).
|
||||||
|
|
||||||
|
### Milestone 4 — GitHub API Client
|
||||||
|
- Implement empty repository creation on GitHub (`POST /user/repos`) using the extracted token.
|
||||||
|
|
||||||
|
### Milestone 5 — Service Orchestration & Local Git Workflow
|
||||||
|
- Implement `RepoManagerService` tying together Gitea creation, GitHub target creation, and mirror setup.
|
||||||
|
- Add optional `-c / --clone` execution running `git clone`.
|
||||||
|
|
||||||
|
### Milestone 6 — Testing & Nix Packaging
|
||||||
|
- Write unit tests with mock client implementations.
|
||||||
|
- Package `new-repo` via Nix flake / Home Manager.
|
||||||
Reference in new issue
Block a user