Skip to content

Add OpenFGC Portal Backend#39

Merged
hasithakn merged 163 commits into
wso2:feature/portalfrom
rashmithachamikara:feature/portal-backend
Jul 6, 2026
Merged

Add OpenFGC Portal Backend#39
hasithakn merged 163 commits into
wso2:feature/portalfrom
rashmithachamikara:feature/portal-backend

Conversation

@rashmithachamikara

Copy link
Copy Markdown
Contributor

Purpose

Bootstrap and initialize the OpenFGC Portal backend BFF (Backend-For-Frontend) with API proxying, security hardening, and backend infrastructure.

Goals

  • Bootstrap the backend BFF with a proxy layer
  • Set up linters, configurations, tests, and project structure
  • Add CI/CD scripts for the backend project
  • Set up API proxying between frontend and consent server
  • Implement request forwarding and security middleware

Approach

  • Built the backend using Go with a stateless BFF architecture
  • Implemented request proxying between the portal frontend and consent server
  • Added hop-by-hop header stripping and correlation ID propagation
  • Configured backend project structure, linting, testing, and runtime configuration
  • Included security hardening and proxy validation mechanisms

User stories

  • Backend proxies requests securely to the consent server
  • Frontend applications can communicate through a centralized BFF layer
  • Developers can extend backend proxy routes and middleware cleanly

Documentation

  • README initiated for portal/backend
  • OpenAPI documentation added under portal/backend/openapi/bff.yaml
  • AGENTS.md and Copilot instructions added for development guidance

Automation tests

  • Unit tests added for backend handlers and middleware
  • Integration tests added for proxy configuration and routing behavior

Security checks

✓ Followed secure coding standards in WSO2 Secure Engineering Guidelines
✓ Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

.github/workflows/portal-backend-ci.yml:45

  • The workflow pins golangci-lint-action to install version: v2.12.2. If that golangci-lint version doesn’t exist, CI will fail at linting. Consider using a known golangci-lint release (and matching the version used in portal/backend/Taskfile.yml).
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v9
        with:
          working-directory: portal/backend
          version: v2.12.2

portal/backend/internal/proxy/service.go:325

  • setTrustedHeaders always injects org-id / TPP-client-id from placeholder config when present, even when placeholder identity mode is disabled. This makes it easy to accidentally run with static trusted headers (including in production if misconfigured), undermining the header-trust boundary. Consider only setting these placeholder headers when placeholder mode is enabled (or when an authenticated identity context is available).
func (s *Service) setTrustedHeaders(incoming *http.Request, outgoing *http.Request, trustedClientID string) {
	if s.cfg.PlaceholderOrgID != "" {
		outgoing.Header.Set("org-id", s.cfg.PlaceholderOrgID)
	}
	if trustedClientID != "" {
		outgoing.Header.Set("TPP-client-id", trustedClientID)
	} else if s.cfg.PlaceholderClientID != "" {
		outgoing.Header.Set("TPP-client-id", s.cfg.PlaceholderClientID)
	}

Comment thread portal/backend/internal/system/config/config.go
Comment thread portal/backend/internal/proxy/service.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 4 comments.

Comment thread portal/backend/internal/proxy/service.go
Comment thread portal/backend/internal/proxy/service.go Outdated
Comment thread portal/backend/internal/proxy/service.go
Comment thread portal/backend/internal/system/config/config.go
- Correlation ID fallback now uses UnixNano + pid + atomic
- Client-supplied forwarding headers are stripped
- CORS allowed origins now reject path, query string, and fragment.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 32 out of 33 changed files in this pull request and generated 4 comments.

Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/service.go
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/README.md
- handler.go: MeConsentApprove now routes ErrUpstreamResponseTooLarge through writeProxyError, so it returns the proper 502 UPSTREAM_RESPONSE_TOO_LARGE instead of 400 INVALID_PAYLOAD.
- service.go: proxy header filtering now strips Cookie and Authorization.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread .github/workflows/portal-backend-ci.yml
Comment thread portal/backend/cmd/server/main.go
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/handler.go Outdated
Comment thread portal/backend/internal/proxy/service.go Outdated
Comment thread portal/backend/internal/system/middleware/correlationid.go
- Moved `golangci-lint` before tests in `.github/workflows/portal-backend-ci.yml`.
- Added a comment explaining the `time.Sleep(50 * time.Millisecond)` in `portal/backend/cmd/server/main.go`.
- Changed upstream timeout mapping from `503` to `504` in `portal/backend/internal/proxy/handler.go`.
- Added Phase 3 TODO comments for missing ownership enforcement in:
  - `MeConsentByID`
  - `MeConsentApprove`
  - `MeConsentRevoke`
- Consolidated duplicated correlation ID generation into shared code under `portal/backend/internal/correlation/`.
- Added TODO notes documenting the sequential metadata enrichment limitation in `portal/backend/internal/proxy/handler.go`.
- Updated docs/tests that depended on the timeout status change.
- Updated buildRevokePayload in [handler.go (line 585)](/abs/path/portal/backend/internal/proxy/handler.go:585) to initialize payload as an empty map and keep the final actionBy assignment as the source of truth.
- Added path escaping when forwarding `consentId`.
- Added invalid-consent-ID integration coverage.
- Updated integration fixtures to use valid UUID consent IDs.
Comment thread portal/backend/internal/system/config/config.go
Comment thread portal/backend/internal/system/correlation/id.go
Comment thread portal/backend/internal/me/service.go
@hasithakn
hasithakn merged commit c674911 into wso2:feature/portal Jul 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type/New Feature Represents a request or task for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants