|
| 1 | +# Golang CVE Rebuild Agent |
| 2 | + |
| 3 | +Automates rebuilding RHEL 9.x and 10.x z-stream components affected by Golang CVE fixes. Integrates with ai-workflows infrastructure using GitLab MR workflow for all submissions. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +``` |
| 8 | +Engineer adds comment to Jira ticket with build instructions (optional) |
| 9 | + | |
| 10 | +Engineer applies "golang-rebuild-queue" label to trigger the agent |
| 11 | + | |
| 12 | +Agent reads comment --> parses side-tag, commit hash, extra jiras, custom message |
| 13 | + | |
| 14 | +Agent forks dist-git repo on GitLab (via MCP gateway) |
| 15 | + | |
| 16 | +Agent bumps spec file: release version + changelog entry |
| 17 | + | |
| 18 | +If commit hash provided: updates %global commit0, spectool -g, rhpkg new-sources |
| 19 | + | |
| 20 | +Agent triggers scratch build (rhpkg scratch-build --srpm) |
| 21 | + | |
| 22 | +Agent posts scratch build result to Jira --> STOPS |
| 23 | + | |
| 24 | +Engineer reviews scratch build, adds "golang-rebuild-approved" label |
| 25 | + | |
| 26 | +Agent commits, pushes to fork, opens GitLab MR for review |
| 27 | + | |
| 28 | +Official build happens when MR is merged (via GitLab pipeline) |
| 29 | +``` |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +### System Tools |
| 34 | + |
| 35 | +```bash |
| 36 | +# Verify these are installed |
| 37 | +rhpkg --version |
| 38 | +brew --version |
| 39 | +spectool --version |
| 40 | +kinit -V |
| 41 | +git --version |
| 42 | +``` |
| 43 | + |
| 44 | +### Authentication |
| 45 | + |
| 46 | +**Kerberos** (for rhpkg/brew): |
| 47 | +```bash |
| 48 | +kinit <username>@REDHAT.COM |
| 49 | +klist # verify ticket |
| 50 | +``` |
| 51 | + |
| 52 | +**Jira API** (for reading tickets and posting comments): |
| 53 | +```bash |
| 54 | +# Create ~/.rh-jira-mcp.env with: |
| 55 | +JIRA_URL=https://redhat.atlassian.net |
| 56 | +JIRA_EMAIL=your.email@redhat.com |
| 57 | +JIRA_API_TOKEN=<your-api-token> |
| 58 | + |
| 59 | +# Load before running: |
| 60 | +source ~/.rh-jira-mcp.env |
| 61 | +export JIRA_USERNAME="$JIRA_EMAIL" |
| 62 | +export JIRA_PASSWORD="$JIRA_API_TOKEN" |
| 63 | +``` |
| 64 | + |
| 65 | +To get a Jira API token: https://id.atlassian.com/manage-profile/security/api-tokens |
| 66 | + |
| 67 | +### MCP Gateway |
| 68 | + |
| 69 | +The agent uses ai-workflows's MCP gateway for GitLab operations (fork, push, open MR). Set: |
| 70 | +```bash |
| 71 | +export MCP_GATEWAY_URL=http://mcp-gateway:8000/sse |
| 72 | +``` |
| 73 | + |
| 74 | +### Python Dependencies |
| 75 | + |
| 76 | +```bash |
| 77 | +pip install jira pyyaml click rich pydantic aiofiles pytest pytest-asyncio |
| 78 | +``` |
| 79 | + |
| 80 | +## Setup |
| 81 | + |
| 82 | +1. Clone ai-workflows and ensure the `ymir/agents/golang_rebuild/` directory is present |
| 83 | +2. Copy and customize config: |
| 84 | + ```bash |
| 85 | + # Edit config.yaml to update allowed components and RHEL versions |
| 86 | + vi ymir/agents/golang_rebuild/config.yaml |
| 87 | + ``` |
| 88 | +3. Set environment variables: |
| 89 | + ```bash |
| 90 | + source ~/.rh-jira-mcp.env |
| 91 | + export JIRA_USERNAME="$JIRA_EMAIL" |
| 92 | + export JIRA_PASSWORD="$JIRA_API_TOKEN" |
| 93 | + export MCP_GATEWAY_URL=http://mcp-gateway:8000/sse |
| 94 | + export GOLANG_REBUILD_CONFIG=/path/to/config.yaml # optional, auto-detected |
| 95 | + ``` |
| 96 | + |
| 97 | +## Usage |
| 98 | + |
| 99 | +### For Engineers (Jira-based workflow) |
| 100 | + |
| 101 | +#### Simple rebuild (no special instructions) |
| 102 | + |
| 103 | +1. Find the component Jira ticket (e.g., RHEL-149580 for buildah) |
| 104 | +2. Verify the parent Golang CVE ticket status is "Integration", "Release Pending", or "Done" |
| 105 | +3. Apply label: **`golang-rebuild-queue`** |
| 106 | +4. Agent will: |
| 107 | + - Auto-detect CVE IDs and RHEL version from ticket |
| 108 | + - Bump spec release and add changelog |
| 109 | + - Trigger scratch build |
| 110 | + - Post result to Jira |
| 111 | +5. Review the scratch build result |
| 112 | +6. If OK, apply label: **`golang-rebuild-approved`** |
| 113 | +7. Agent opens a GitLab MR for final review and merge |
| 114 | + |
| 115 | +#### Rebuild with side-tag (custom golang version) |
| 116 | + |
| 117 | +When the buildroot has an older golang and you need a newer version: |
| 118 | + |
| 119 | +1. Add a comment to the component ticket **before** applying the label: |
| 120 | + ``` |
| 121 | + side-tag: rhel-9.4.0-z-gotoolset-stack-gate |
| 122 | + release: rhel-9.4.0 |
| 123 | + ``` |
| 124 | +2. Apply label: **`golang-rebuild-queue`** |
| 125 | +3. Agent uses the side-tag for scratch build |
| 126 | + |
| 127 | +#### Rebuild with new commit hash |
| 128 | + |
| 129 | +When sources need updating (new upstream commit): |
| 130 | + |
| 131 | +1. Add a comment: |
| 132 | + ``` |
| 133 | + commit: abc123def456789 |
| 134 | + ``` |
| 135 | +2. Apply label: **`golang-rebuild-queue`** |
| 136 | +3. Agent updates `%global commit0`, runs `spectool -g`, `rhpkg new-sources` |
| 137 | + |
| 138 | +#### Full example comment (all options) |
| 139 | + |
| 140 | +``` |
| 141 | +side-tag: rhel-9.4.0-z-gotoolset-stack-gate |
| 142 | +release: rhel-9.4.0 |
| 143 | +commit: abc123def456789 |
| 144 | +jiras: RHEL-158645 RHEL-147034 RHEL-146820 |
| 145 | +message: Rebuilding with golang 1.25.8 for critical security fix |
| 146 | +``` |
| 147 | + |
| 148 | +All fields are optional. If no comment is found, agent uses defaults. |
| 149 | + |
| 150 | +### Comment Fields Reference |
| 151 | + |
| 152 | +| Field | Description | Example | |
| 153 | +|-------|-------------|---------| |
| 154 | +| `side-tag` | Brew side-tag target (overrides default) | `rhel-9.4.0-z-gotoolset-stack-gate` | |
| 155 | +| `release` | `--release` flag for rhpkg (required with side-tag) | `rhel-9.4.0` | |
| 156 | +| `commit` | New commit hash for `%global commit0` | `abc123def456789` | |
| 157 | +| `jiras` | Additional Jira IDs for changelog/commit | `RHEL-158645 RHEL-147034` | |
| 158 | +| `message` | Custom changelog/commit message | `Rebuilding with golang 1.25.8 for security fix` | |
| 159 | + |
| 160 | +### Jira Labels Reference |
| 161 | + |
| 162 | +| Label | Purpose | Applied by | |
| 163 | +|-------|---------|-----------| |
| 164 | +| `golang-rebuild-queue` | Triggers the agent to process this ticket | Engineer | |
| 165 | +| `golang-rebuild-approved` | Approves official build after scratch succeeds | Engineer | |
| 166 | +| `jotnar_golang_rebuild_in_progress` | Agent is currently processing | Agent | |
| 167 | +| `jotnar_golang_rebuild_completed` | Rebuild completed successfully | Agent | |
| 168 | +| `jotnar_golang_rebuild_failed` | Rebuild failed | Agent | |
| 169 | +| `jotnar_golang_rebuild_errored` | Unexpected error occurred | Agent | |
| 170 | + |
| 171 | +### CLI (for manual/testing use) |
| 172 | + |
| 173 | +```bash |
| 174 | +# Process a specific ticket |
| 175 | +python -m ymir.agents.golang_rebuild.cli process RHEL-158645 |
| 176 | + |
| 177 | +# Process with dry-run (no actual changes) |
| 178 | +python -m ymir.agents.golang_rebuild.cli --dry-run process RHEL-158645 |
| 179 | + |
| 180 | +# List tickets in queue |
| 181 | +python -m ymir.agents.golang_rebuild.cli list-tickets |
| 182 | + |
| 183 | +# Check authentication |
| 184 | +python -m ymir.agents.golang_rebuild.cli check-auth |
| 185 | +``` |
| 186 | + |
| 187 | +### Direct Mode (environment variables) |
| 188 | + |
| 189 | +```bash |
| 190 | +export GOLANG_TICKET=RHEL-158645 |
| 191 | +export DRY_RUN=true |
| 192 | +export MCP_GATEWAY_URL=http://mcp-gateway:8000/sse |
| 193 | +python -m ymir.agents.golang_rebuild |
| 194 | +``` |
| 195 | + |
| 196 | +### Queue Mode (Redis, for deployment) |
| 197 | + |
| 198 | +```bash |
| 199 | +export REDIS_URL=redis://valkey:6379/0 |
| 200 | +export MCP_GATEWAY_URL=http://mcp-gateway:8000/sse |
| 201 | +export CONTAINER_VERSION=c9s |
| 202 | +python ymir/agents/golang_rebuild/workflow.py |
| 203 | +``` |
| 204 | + |
| 205 | +## What the Agent Produces |
| 206 | + |
| 207 | +### Changelog Entry |
| 208 | + |
| 209 | +``` |
| 210 | +* Mon May 05 2026 Golang Rebuild Agent <jotnar@redhat.com> - 2:1.33.13-3.1 |
| 211 | +- Rebuilding with golang 1.25.8 to fix net/http vulnerability |
| 212 | +- Fixes: CVE-2025-12345 CVE-2025-67890 |
| 213 | +- Resolves: RHEL-149580 RHEL-158645 RHEL-147034 |
| 214 | +``` |
| 215 | + |
| 216 | +### Commit Message |
| 217 | + |
| 218 | +``` |
| 219 | +Rebuilding with golang 1.25.8 to fix net/http vulnerability |
| 220 | +Fixes: CVE-2025-12345 CVE-2025-67890 |
| 221 | +Resolves: RHEL-149580 RHEL-158645 RHEL-147034 |
| 222 | +
|
| 223 | +Signed-off-by: Golang Rebuild Agent <jotnar@redhat.com> |
| 224 | +``` |
| 225 | + |
| 226 | +### GitLab MR |
| 227 | + |
| 228 | +Title: `Rebuild buildah for golang CVE fix` |
| 229 | + |
| 230 | +Description includes scratch build NVR, Brew link, CVE list, and resolved Jira tickets. |
| 231 | + |
| 232 | +## Configuration |
| 233 | + |
| 234 | +Edit `config.yaml` to customize: |
| 235 | + |
| 236 | +- **RHEL versions**: Add/remove z-stream versions with branch and build target |
| 237 | +- **Component filter**: Control which components are processed |
| 238 | +- **Brew settings**: Adjust polling interval and timeout for scratch builds |
| 239 | + |
| 240 | +See `config.yaml` for inline documentation. |
| 241 | + |
| 242 | +## File Structure |
| 243 | + |
| 244 | +``` |
| 245 | +ymir/agents/golang_rebuild/ |
| 246 | + __init__.py # Package init |
| 247 | + __main__.py # Entry point (python -m ymir.agents.golang_rebuild) |
| 248 | + workflow.py # Main orchestrator (async, queue + direct mode) |
| 249 | + comment_parser.py # Parses Jira comments for build instructions |
| 250 | + jira_queries.py # Read-only Jira queries (CVE discovery) |
| 251 | + brew_client.py # Async Brew/rhpkg scratch builds |
| 252 | + git_client.py # Async git/rhpkg operations |
| 253 | + specfile.py # RPM spec file parsing and modification |
| 254 | + models.py # Pydantic data models |
| 255 | + constants.py # Agent identity, component list, templates |
| 256 | + utils.py # Helpers (CVE extraction, config loading) |
| 257 | + cli.py # Click-based CLI for manual use |
| 258 | + config.yaml # Configuration file |
| 259 | + README.md # This file |
| 260 | + tests/ # Unit tests (63 tests) |
| 261 | +``` |
| 262 | + |
| 263 | +## Supported RHEL Versions |
| 264 | + |
| 265 | +| Version | Branch | Build Target | Status | |
| 266 | +|---------|--------|-------------|--------| |
| 267 | +| RHEL 9.4.z | rhel-9.4.0 | rhel-9.4.0-candidate | Supported | |
| 268 | +| RHEL 9.6.z | rhel-9.6.0 | rhel-9.6.0-candidate | Supported | |
| 269 | +| RHEL 9.7.z | rhel-9.7.0 | rhel-9.7.0-candidate | Supported | |
| 270 | +| RHEL 10.1.z | c10s | c10s-candidate | Supported | |
| 271 | +| RHEL 8.x | - | - | Not supported | |
| 272 | + |
| 273 | +## Running Tests |
| 274 | + |
| 275 | +```bash |
| 276 | +cd ai-workflows |
| 277 | +PYTHONPATH=$(pwd) python -m pytest ymir/agents/golang_rebuild/tests/ -v |
| 278 | +``` |
| 279 | + |
| 280 | +## Troubleshooting |
| 281 | + |
| 282 | +### "Jira credentials not found" |
| 283 | +```bash |
| 284 | +source ~/.rh-jira-mcp.env |
| 285 | +export JIRA_USERNAME="$JIRA_EMAIL" |
| 286 | +export JIRA_PASSWORD="$JIRA_API_TOKEN" |
| 287 | +``` |
| 288 | + |
| 289 | +### "No module named 'tasks'" |
| 290 | +The `tasks` module is part of ai-workflows agents. Ensure PYTHONPATH includes both the repo root and agents directory: |
| 291 | +```bash |
| 292 | +export PYTHONPATH=/path/to/ai-workflows:/path/to/ai-workflows/agents |
| 293 | +``` |
| 294 | + |
| 295 | +### Scratch build times out |
| 296 | +Increase `max_wait_time` in `config.yaml` under `brew` section (default: 7200 seconds / 2 hours). |
| 297 | + |
| 298 | +### "Branch not found" |
| 299 | +The RHEL version in the ticket may not have a corresponding branch yet. Check that the branch exists in the dist-git repo. |
| 300 | + |
| 301 | +### Kerberos expired |
| 302 | +```bash |
| 303 | +kinit <username>@REDHAT.COM |
| 304 | +``` |
| 305 | + |
| 306 | +## Contact |
| 307 | + |
| 308 | +- Jotnar team: jotnar@redhat.com |
| 309 | +- Slack: #forum-jotnar-package-automation |
0 commit comments