Skip to content

Conversation

@jeremyeder
Copy link
Collaborator

Summary

Fixes the "Invalid or missing token" authentication error users encounter when accessing the UI after running setup-kind.sh and deploy.sh.

Problem

The backend-ingress was intercepting all /api/* requests and routing them directly to the Go backend, bypassing the Next.js frontend's API routes. This caused:

  • Next.js API routes (like /api/me, /api/cluster-info) to return 404
  • Frontend unable to access OC_TOKEN environment variable for authentication
  • Authentication failures preventing UI access

Solution

Removed backend-ingress.yaml from the e2e kustomization overlay. The correct architecture is:

```
Browser → frontend-ingress → Next.js Frontend

/api/* routes (handles auth)

backend-service:8080/api (internal proxy)
```

This follows the API Gateway pattern where Next.js acts as the unified entry point for both UI and API traffic.

Changes

  • `components/manifests/overlays/e2e/kustomization.yaml`: Removed `backend-ingress.yaml` from resources list

Test Plan

  • Local kind cluster deployment via `setup-kind.sh` + `deploy.sh`
  • Frontend accessible at http://localhost:8080
  • Authentication working (no "Invalid or missing token" error)
  • `/api/me` endpoint returns authenticated user info
  • `/api/cluster-info` endpoint working

Impact

  • Users: Can now access the UI immediately after deployment without manual token configuration
  • Architecture: Simplified routing - single ingress point through frontend
  • Security: No change - authentication still enforced via ServiceAccount tokens

🤖 Generated with Claude Code

The backend-ingress was intercepting /api/* requests before they could
reach the Next.js frontend, causing authentication failures. The frontend
serves both the UI and API routes, proxying authenticated requests to the
backend internally via backend-service:8080/api.

This eliminates the "Invalid or missing token" error users saw when
accessing the UI after running setup-kind.sh and deploy.sh.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 11 to +12
- frontend-ingress.yaml
- backend-ingress.yaml
# backend-ingress.yaml removed - frontend handles all routing and proxies to backend internally

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Removing backend ingress never cleans up existing deployments

Commenting out backend-ingress.yaml from the e2e kustomization prevents new deployments from creating the ingress, but e2e/scripts/deploy.sh still uses kubectl apply -k without --prune. Any cluster that previously deployed this overlay will keep the old backend-ingress resource, so /api requests will continue to bypass the frontend and the “Invalid or missing token” problem remains. The fix only works on brand‑new clusters. Consider deleting the old ingress explicitly or switching to a pruned apply so existing environments also receive the change.

Useful? React with 👍 / 👎.

- test-user.yaml
- frontend-ingress.yaml
- backend-ingress.yaml
# backend-ingress.yaml removed - frontend handles all routing and proxies to backend internally
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation Enhancement Suggestion

Great explanatory comment! To make it even more helpful for future developers, consider adding a reference to where this architectural pattern is documented:

Suggested change
# backend-ingress.yaml removed - frontend handles all routing and proxies to backend internally
# backend-ingress.yaml removed - frontend handles all routing and proxies to backend internally
# Architecture: Next.js API Gateway pattern - see components/frontend/src/lib/auth.ts for auth flow

This helps developers understand where to look for the authentication/proxy implementation details.

@github-actions
Copy link
Contributor

Claude Code Review

Summary

This is a critical bug fix that resolves authentication failures in the e2e test environment. The change correctly removes the backend-ingress that was causing routing conflicts by bypassing the Next.js API Gateway pattern. The fix is minimal, correct, and well-documented.

Overall Assessment: ✅ APPROVED - Ready to merge with one minor documentation enhancement suggestion.

Issues by Severity

🔵 Minor Issues

Documentation Enhancement

  • Location: components/manifests/overlays/e2e/kustomization.yaml:12
  • Issue: While the inline comment is good, it could reference the implementation details
  • Suggestion: Add a pointer to components/frontend/src/lib/auth.ts to help future developers understand the auth flow
  • Priority: Low - current documentation is adequate

Positive Highlights

Architecture & Design Excellence

Correct API Gateway Pattern: This change properly implements the recommended architecture where Next.js acts as the unified entry point, handling authentication and proxying to backend services.

Root Cause Analysis: The PR description demonstrates excellent understanding of the problem - the dual ingress configuration was creating routing ambiguity where /api/* requests could hit either the frontend or backend directly.

Minimal Impact: This is a surgical fix - only one line changed (comment added), with no code modifications required. The architecture was already correct; the extra ingress was the only problem.

Security & Authentication

Preserves Auth Flow: The fix maintains the proper authentication chain:

  • Frontend receives OC_TOKEN via environment variables (from frontend-test-patch.yaml)
  • Next.js API routes extract token via buildForwardHeadersAsync()
  • Token forwarded to backend as X-Forwarded-Access-Token
  • Backend validates token for K8s operations

No Security Regression: Removing the direct backend ingress actually improves security by ensuring all requests flow through the authentication layer in the Next.js API routes.

Testing & Validation

Comprehensive Test Plan: PR description shows thorough manual testing of the critical paths

E2E Test Coverage: The existing Cypress tests validate the exact scenarios affected by this bug, providing excellent regression protection.

Code Quality

Clear Documentation: Inline comment explains not just what was removed, but why - the architectural reasoning.

Excellent PR Description: Clear problem statement, root cause analysis with routing diagram, solution explanation, and impact assessment.

Architecture Validation

I reviewed the implementation and confirmed this fix aligns with the established patterns. The correct routing architecture is now:

Browser → frontend-ingress → Next.js Frontend → /api/* routes (auth handling) → backend-service

The previous broken architecture had dual ingress points causing /api/* requests to bypass the frontend auth layer.

Comparison with Other Overlays

local-dev overlay: Uses OpenShift Routes and has both frontend-route.yaml AND backend-route.yaml. May have similar routing conflict worth investigating.

Recommendations

Before Merge (Optional)

  1. Already Done: E2E tests passing validate the fix
  2. 🔵 Consider: Add reference to auth implementation in the comment (see inline suggestion)

Future Work (Not Blocking)

  1. Architecture Documentation: Consider adding an ADR documenting the API Gateway via Next.js pattern
  2. Local-Dev Validation: Test whether local-dev overlay backend-route.yaml needs similar treatment
  3. E2E Test Enhancement: Consider explicitly testing /api/me returns authenticated user info

Technical Review Notes

  • File Changed: 1 file, 1 line modified (comment)
  • Risk Level: ⬇️ Very Low - Removes unused resource, no code changes
  • Backward Compatibility: ✅ Full - No breaking changes
  • Test Coverage: ✅ Excellent - E2E tests cover affected functionality
  • Follows CLAUDE.md: ✅ Yes - Minimal change, good documentation

Verdict: This is an exemplary bug fix PR - clear problem identification, correct solution, minimal change scope, and thorough documentation.

🚢 Ready to merge!

@Gkrumbach07
Copy link
Collaborator

Tracked in Jira: https://issues.redhat.com/browse/RHOAIENG-39124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants