Skip to content

Commit d2ab1c9

Browse files
authored
Merge pull request #104 from angaduom/fix-jira-auth-detection
fix: MCP-first Jira auth and diagnose Ambient env var accessibility
2 parents 2239b41 + af906eb commit d2ab1c9

5 files changed

Lines changed: 537 additions & 48 deletions

File tree

workflows/cve-fixer/.ambient/ambient.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "CVE Fixer",
33
"description": "Automate remediation of CVE issues reported by ProdSec team in Jira by creating pull requests with dependency updates and patches",
44
"systemPrompt": "You are a CVE remediation assistant for the Ambient Code Platform. Your role is to help users remediate CVE issues that have been reported by the ProdSec team in Jira by automatically creating pull requests with fixes.\n\nKEY RESPONSIBILITIES:\n- Guide users through the CVE remediation workflow for Jira-tracked vulnerabilities\n- Execute slash commands to perform specific security tasks\n- Find CVE issues opened by ProdSec team in Jira\n- Implement secure fixes that resolve vulnerabilities without breaking functionality\n- Create pull requests with dependency updates, patches, and comprehensive test results\n\nWORKFLOW METHODOLOGY:\n1. FIND - Find CVEs already reported in Jira for a component\n2. FIX - Implement remediation strategies (dependency updates, patches, code changes, PR creation)\n\nAVAILABLE COMMANDS:\n/cve.find - Find CVEs reported in Jira for a specific component\n/cve.fix - Implement fixes for discovered CVEs and create pull requests\n\nOUTPUT LOCATIONS:\n- Create all Jira CVE findings in: artifacts/cve-fixer/find/\n- Create all fix implementations in: artifacts/cve-fixer/fixes/\n\nNote: Commands will guide you through required setup steps on first use. If the user's component is not in component-repository-mappings.json, direct them to the \"Team Onboarding\" section in README.md.",
5-
"startupPrompt": "Greet the user and introduce yourself as a CVE remediation assistant. Explain that you help remediate CVE issues reported by ProdSec in Jira by creating pull requests. Mention the two commands: /cve.find to discover CVEs and /cve.fix to implement fixes. If this is their first time, point them to README.md Team Onboarding for setup. Suggest starting with /cve.find and ask what they'd like to work on.",
5+
"startupPrompt": "Greet the user and introduce yourself as a CVE remediation assistant. Explain that you help remediate CVE issues reported by ProdSec in Jira by creating pull requests. Mention the three commands: /onboard to add a new component, /cve.find to discover CVEs, and /cve.fix to implement fixes. If this is their first time or their component is not yet onboarded, suggest starting with /onboard. Otherwise suggest /cve.find and ask what they'd like to work on.",
66
"results": {
77
"Jira CVE Issues": "artifacts/cve-fixer/find/**/*.md",
88
"Fix Implementations": "artifacts/cve-fixer/fixes/**/*"

workflows/cve-fixer/.claude/commands/cve.find.md

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,46 @@ Report: artifacts/cve-fixer/find/cve-issues-20260226-145018.md
5454

5555
2. **Verify Jira Access**
5656

57-
Secrets may be injected by the Ambient session, a secrets manager, or an MCP server — do NOT rely solely on bash env var checks. Instead, attempt a lightweight test API call and let the response determine whether credentials are available.
57+
**ALWAYS check for a Jira MCP server first** before attempting any curl/env var approach.
58+
59+
**2.1: Check for Jira MCP server — follow these exact steps in order**
60+
61+
**Step A**: If `mcp__session__refresh_credentials` is in the deferred tools list, call it now.
62+
This activates workspace integrations including Jira.
63+
64+
**Step B**: Immediately after (or if no refresh was needed), attempt to fetch the Jira
65+
tool directly using `select:` syntax — do this regardless of whether you think it exists:
66+
67+
```
68+
ToolSearch: select:mcp__mcp-atlassian__jira_search
69+
```
70+
71+
**Step C**: If Step B returns the tool schema → use it for all Jira queries. Done.
72+
Print: "✅ Using mcp__mcp-atlassian__jira_search"
73+
74+
**NEVER run a generic keyword ToolSearch like "jira search atlassian" or "jira MCP".
75+
Generic searches return unrelated tools and cause false "not found" conclusions.
76+
The `select:` syntax either returns the exact tool or nothing — use only that.**
77+
78+
If `select:mcp__mcp-atlassian__jira_search` returns nothing → the tool is not available
79+
in this session. Proceed to Step 2.2 (curl fallback).
80+
81+
**2.2: Fallback — curl with credentials (always attempt, even if bash says vars are unset)**
82+
83+
If no Jira MCP tool is available, attempt the curl auth call regardless of whether the
84+
bash env var check shows the vars as set or not. Ambient secrets can be injected at the
85+
curl level even when not visible to shell variable checks — the only reliable test is the
86+
actual API call response.
5887

5988
```bash
6089
JIRA_BASE_URL="https://redhat.atlassian.net"
61-
AUTH=$(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64)
90+
AUTH=$(echo -n "${JIRA_EMAIL}:${JIRA_API_TOKEN}" | base64 | tr -d '\n')
91+
92+
# Diagnostic only — do NOT stop if these are "no"
93+
echo "JIRA_API_TOKEN in bash env: $([ -n "${JIRA_API_TOKEN}" ] && echo yes || echo no)"
94+
echo "JIRA_EMAIL in bash env: $([ -n "${JIRA_EMAIL}" ] && echo yes || echo no)"
95+
echo "Attempting Jira API call regardless..."
6296

63-
# Retry once on network failure (curl exit code 000 = timeout/no response)
6497
for ATTEMPT in 1 2; do
6598
TEST_RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X GET \
6699
--connect-timeout 10 --max-time 15 \
@@ -74,29 +107,22 @@ Report: artifacts/cve-fixer/find/cve-issues-20260226-145018.md
74107
```
75108

76109
- **HTTP 200** → credentials valid, proceed
77-
- **HTTP 401** → credentials missing or invalid. Note: `/rest/api/3/myself` returns 401 for all authentication failures — there is no separate 403 for this endpoint. Only now inform the user:
78-
- Check if `JIRA_API_TOKEN` and `JIRA_EMAIL` are configured as Ambient session secrets
79-
- If not, generate a token at https://id.atlassian.com/manage-profile/security/api-tokens and export:
80-
81-
```bash
82-
export JIRA_API_TOKEN="your-token-here"
83-
export JIRA_EMAIL="your-email@redhat.com"
84-
```
85-
- **HTTP 000 after retry** → persistent network issue — inform user and stop
86-
87-
**Do NOT pre-check env vars with `[ -z "$JIRA_API_TOKEN" ]` and stop.** The variables may be available to the API call even if not visible to the shell check (e.g. Ambient secrets injection).
110+
- **HTTP 401** → credentials truly not available or expired. Only now stop and inform user:
111+
configure `JIRA_API_TOKEN` and `JIRA_EMAIL` as Ambient workspace secrets or export them
112+
- **HTTP 000 after retry** → network issue — inform user and stop
88113

89114
3. **Query Jira for CVE Issues**
90115

91-
a. Set up variables (AUTH already set from Step 2):
116+
a. Set up variables:
92117

93118
```bash
94119
COMPONENT_NAME="[from step 1]"
95120
JIRA_BASE_URL="https://redhat.atlassian.net"
96-
# AUTH already constructed in Step 2 — reuse it
121+
# If using MCP (Step 2.1): pass JQL directly to MCP tool — no AUTH needed
122+
# If using curl (Step 2.2): AUTH already constructed in Step 2 — reuse it
97123
```
98124

99-
b. Construct JQL query and execute API call:
125+
b. Construct JQL query and execute via MCP or curl:
100126

101127
```bash
102128
# Normalize component name with case-insensitive lookup against mapping file

0 commit comments

Comments
 (0)