Skip to content

fix(cira): reject CIRA API calls with 403 when CIRA is disabled#1033

Draft
madhavilosetty-intel wants to merge 1 commit into
mainfrom
fix/disable-cira-api
Draft

fix(cira): reject CIRA API calls with 403 when CIRA is disabled#1033
madhavilosetty-intel wants to merge 1 commit into
mainfrom
fix/disable-cira-api

Conversation

@madhavilosetty-intel
Copy link
Copy Markdown
Contributor

Add a middleware on the CIRA route groups that returns 403 with "CIRA is disabled on this instance" when the flag is set. Routes stay registered so the OpenAPI spec remains accurate; the 403 response is declared on the CIRA config and certificate endpoints.

@madhavilosetty-intel madhavilosetty-intel requested a review from a team as a code owner June 1, 2026 22:32
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 45.16129% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.69%. Comparing base (f01cb2b) to head (e1ed4d8).

Files with missing lines Patch % Lines
internal/controller/openapi/cira.go 0.00% 5 Missing ⚠️
internal/controller/openapi/route_options.go 0.00% 5 Missing ⚠️
internal/controller/httpapi/router.go 0.00% 2 Missing ⚠️
internal/controller/httpapi/v1/ciracert.go 50.00% 2 Missing ⚠️
internal/controller/httpapi/v1/ciraconfigs.go 75.00% 0 Missing and 2 partials ⚠️
internal/controller/openapi/ciracert.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1033      +/-   ##
==========================================
+ Coverage   41.66%   41.69%   +0.03%     
==========================================
  Files         135      136       +1     
  Lines       12433    12442       +9     
==========================================
+ Hits         5180     5188       +8     
- Misses       6698     6699       +1     
  Partials      555      555              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@madhavilosetty-intel madhavilosetty-intel marked this pull request as draft June 1, 2026 22:52
Add a middleware on the CIRA route groups that returns 403 with
"CIRA is disabled on this instance" when the flag is set. Routes stay
registered so the OpenAPI spec remains accurate; the 403 response is
declared on the CIRA config and certificate endpoints.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enforces APP_DISABLE_CIRA at the HTTP API layer by adding a Gin middleware to reject CIRA-related endpoints with HTTP 403 when CIRA is disabled, while keeping routes registered so the OpenAPI spec remains complete.

Changes:

  • Added a ciraDisabledMiddleware that returns 403 {"error":"CIRA is disabled on this instance"} when CIRA is disabled.
  • Wired the middleware into the v1 Gin route groups for CIRA config and CIRA root cert endpoints, and updated route constructors to accept *config.Config.
  • Updated OpenAPI route options for CIRA endpoints to declare the 403 response; added/updated unit tests for the disabled behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/controller/openapi/route_options.go Adds CIRA-specific protected route options including documented 403 when disabled.
internal/controller/openapi/ciracert.go Switches CIRACert OpenAPI route to use the CIRA-specific protected options.
internal/controller/openapi/cira.go Switches CIRA config OpenAPI routes to use the CIRA-specific protected options.
internal/controller/httpapi/v1/ciradisabled.go Introduces the Gin middleware and shared disabled message.
internal/controller/httpapi/v1/ciraconfigs.go Applies the middleware to the CIRA configs route group; updates constructor signature to accept config.
internal/controller/httpapi/v1/ciraconfigs_test.go Updates constructor calls and adds a 403-on-disabled test case.
internal/controller/httpapi/v1/ciracert.go Applies the middleware to the CIRACert route group; updates constructor signatures to accept config.
internal/controller/httpapi/v1/ciracert_test.go Updates constructor calls and adds a 403-on-disabled test case.
internal/controller/httpapi/router.go Passes cfg into the updated CIRA route constructors.

Comment on lines +309 to +333
// No expectations: the guard must reject before the feature is reached.
mockCtl := gomock.NewController(t)
ciraconfig := mocks.NewMockCIRAConfigsFeature(mockCtl)

NewCIRAConfigRoutes(handler, ciraconfig, log, &config.Config{App: config.App{DisableCIRA: true}})

cases := []struct {
method string
url string
}{
{http.MethodGet, "/api/v1/admin/ciraconfigs"},
{http.MethodGet, "/api/v1/admin/ciraconfigs/example"},
{http.MethodPost, "/api/v1/admin/ciraconfigs"},
{http.MethodPatch, "/api/v1/admin/ciraconfigs"},
{http.MethodDelete, "/api/v1/admin/ciraconfigs/example"},
}

for _, tc := range cases {
tc := tc

t.Run(tc.method+" "+tc.url, func(t *testing.T) {
t.Parallel()

req, err := http.NewRequestWithContext(context.Background(), tc.method, tc.url, http.NoBody)
require.NoError(t, err)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants