-
Notifications
You must be signed in to change notification settings - Fork 150
feat: Add measured boot trust approvals #3464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kfelternv
wants to merge
4
commits into
NVIDIA:main
Choose a base branch
from
kfelternv:v21-measurables-rest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,247 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package handler | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/labstack/echo/v4" | ||
|
|
||
| "github.com/NVIDIA/infra-controller/rest-api/api/pkg/api/handler/util/common" | ||
| "github.com/NVIDIA/infra-controller/rest-api/api/pkg/api/model" | ||
| sc "github.com/NVIDIA/infra-controller/rest-api/api/pkg/client/site" | ||
| cutil "github.com/NVIDIA/infra-controller/rest-api/common/pkg/util" | ||
| cdb "github.com/NVIDIA/infra-controller/rest-api/db/pkg/db" | ||
| corev1 "github.com/NVIDIA/infra-controller/rest-api/proto/core/gen/v1" | ||
| ) | ||
|
|
||
| type measurementTrustHandler struct { | ||
| dbSession *cdb.Session | ||
| scp *sc.ClientPool | ||
| tracerSpan *cutil.TracerSpan | ||
| } | ||
|
|
||
| func newMeasurementTrustHandler(dbSession *cdb.Session, scp *sc.ClientPool) measurementTrustHandler { | ||
| return measurementTrustHandler{ | ||
| dbSession: dbSession, | ||
| scp: scp, | ||
| tracerSpan: cutil.NewTracerSpan(), | ||
| } | ||
| } | ||
|
|
||
| // CreateMeasurementTrustedMachineHandler creates a machine trust approval. | ||
| type CreateMeasurementTrustedMachineHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewCreateMeasurementTrustedMachineHandler returns a machine trust approval creation handler. | ||
| func NewCreateMeasurementTrustedMachineHandler(dbSession *cdb.Session, scp *sc.ClientPool) CreateMeasurementTrustedMachineHandler { | ||
| return CreateMeasurementTrustedMachineHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle creates a machine trust approval. | ||
| func (h CreateMeasurementTrustedMachineHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedMachine", "Create", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| var apiReq model.APIMeasurementTrustedMachineCreateRequest | ||
| if err := c.Bind(&apiReq); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, "Invalid request body", nil) | ||
| } | ||
| if err := apiReq.Validate(); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, err.Error(), nil) | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: apiReq.SiteID, | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.AddMeasurementTrustedMachineResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_AddMeasurementTrustedMachine_FullMethodName, apiReq.ToProto(), coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to create machine trust approval") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| return c.JSON(http.StatusCreated, model.NewAPIMeasurementTrustedMachine(coreResp.GetApprovalRecord())) | ||
| } | ||
|
|
||
| // ListMeasurementTrustedMachinesHandler lists machine trust approvals. | ||
| type ListMeasurementTrustedMachinesHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewListMeasurementTrustedMachinesHandler returns a machine trust approval list handler. | ||
| func NewListMeasurementTrustedMachinesHandler(dbSession *cdb.Session, scp *sc.ClientPool) ListMeasurementTrustedMachinesHandler { | ||
| return ListMeasurementTrustedMachinesHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle lists machine trust approvals. | ||
| func (h ListMeasurementTrustedMachinesHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedMachine", "List", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: c.QueryParam("siteId"), | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.ListMeasurementTrustedMachinesResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_ListMeasurementTrustedMachines_FullMethodName, &corev1.ListMeasurementTrustedMachinesRequest{}, coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to list machine trust approvals") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| var resp model.APIMeasurementTrustedMachines | ||
| resp.FromProto(coreResp.GetApprovalRecords()) | ||
| return c.JSON(http.StatusOK, resp) | ||
| } | ||
|
|
||
| // DeleteMeasurementTrustedMachineHandler deletes a machine trust approval. | ||
| type DeleteMeasurementTrustedMachineHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewDeleteMeasurementTrustedMachineHandler returns a machine trust approval deletion handler. | ||
| func NewDeleteMeasurementTrustedMachineHandler(dbSession *cdb.Session, scp *sc.ClientPool) DeleteMeasurementTrustedMachineHandler { | ||
| return DeleteMeasurementTrustedMachineHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle deletes a machine trust approval. | ||
| func (h DeleteMeasurementTrustedMachineHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedMachine", "Delete", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| apiReq := model.APIMeasurementTrustedMachineDeleteRequest{Selector: c.QueryParam("selector"), ID: c.Param("id")} | ||
| if err := apiReq.Validate(); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, err.Error(), nil) | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: c.QueryParam("siteId"), | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.RemoveMeasurementTrustedMachineResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_RemoveMeasurementTrustedMachine_FullMethodName, apiReq.ToProto(), coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to delete machine trust approval") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| return c.JSON(http.StatusOK, model.NewAPIMeasurementTrustedMachine(coreResp.GetApprovalRecord())) | ||
| } | ||
|
|
||
| // CreateMeasurementTrustedProfileHandler creates a profile trust approval. | ||
| type CreateMeasurementTrustedProfileHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewCreateMeasurementTrustedProfileHandler returns a profile trust approval creation handler. | ||
| func NewCreateMeasurementTrustedProfileHandler(dbSession *cdb.Session, scp *sc.ClientPool) CreateMeasurementTrustedProfileHandler { | ||
| return CreateMeasurementTrustedProfileHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle creates a profile trust approval. | ||
| func (h CreateMeasurementTrustedProfileHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedProfile", "Create", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| var apiReq model.APIMeasurementTrustedProfileCreateRequest | ||
| if err := c.Bind(&apiReq); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, "Invalid request body", nil) | ||
| } | ||
| if err := apiReq.Validate(); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, err.Error(), nil) | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: apiReq.SiteID, | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.AddMeasurementTrustedProfileResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_AddMeasurementTrustedProfile_FullMethodName, apiReq.ToProto(), coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to create profile trust approval") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| return c.JSON(http.StatusCreated, model.NewAPIMeasurementTrustedProfile(coreResp.GetApprovalRecord())) | ||
| } | ||
|
|
||
| // ListMeasurementTrustedProfilesHandler lists profile trust approvals. | ||
| type ListMeasurementTrustedProfilesHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewListMeasurementTrustedProfilesHandler returns a profile trust approval list handler. | ||
| func NewListMeasurementTrustedProfilesHandler(dbSession *cdb.Session, scp *sc.ClientPool) ListMeasurementTrustedProfilesHandler { | ||
| return ListMeasurementTrustedProfilesHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle lists profile trust approvals. | ||
| func (h ListMeasurementTrustedProfilesHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedProfile", "List", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: c.QueryParam("siteId"), | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.ListMeasurementTrustedProfilesResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_ListMeasurementTrustedProfiles_FullMethodName, &corev1.ListMeasurementTrustedProfilesRequest{}, coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to list profile trust approvals") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| var resp model.APIMeasurementTrustedProfiles | ||
| resp.FromProto(coreResp.GetApprovalRecords()) | ||
| return c.JSON(http.StatusOK, resp) | ||
| } | ||
|
|
||
| // DeleteMeasurementTrustedProfileHandler deletes a profile trust approval. | ||
| type DeleteMeasurementTrustedProfileHandler struct{ measurementTrustHandler } | ||
|
|
||
| // NewDeleteMeasurementTrustedProfileHandler returns a profile trust approval deletion handler. | ||
| func NewDeleteMeasurementTrustedProfileHandler(dbSession *cdb.Session, scp *sc.ClientPool) DeleteMeasurementTrustedProfileHandler { | ||
| return DeleteMeasurementTrustedProfileHandler{newMeasurementTrustHandler(dbSession, scp)} | ||
| } | ||
|
|
||
| // Handle deletes a profile trust approval. | ||
| func (h DeleteMeasurementTrustedProfileHandler) Handle(c echo.Context) error { | ||
| org, dbUser, ctx, logger, handlerSpan := common.SetupHandler("MeasurementTrustedProfile", "Delete", c, h.tracerSpan) | ||
| if handlerSpan != nil { | ||
| defer handlerSpan.End() | ||
| } | ||
|
|
||
| apiReq := model.APIMeasurementTrustedProfileDeleteRequest{Selector: c.QueryParam("selector"), ID: c.Param("id")} | ||
| if err := apiReq.Validate(); err != nil { | ||
| return cutil.NewAPIErrorResponse(c, http.StatusBadRequest, err.Error(), nil) | ||
| } | ||
|
|
||
| stc, siteID, apiErr := common.AuthorizeProviderSiteForCore(common.AuthorizeProviderSiteForCoreInput{ | ||
| Ctx: ctx, Logger: logger, DBSession: h.dbSession, SCP: h.scp, Org: org, User: dbUser, SiteID: c.QueryParam("siteId"), | ||
| }) | ||
| if apiErr != nil { | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, apiErr.Data) | ||
| } | ||
|
|
||
| coreResp := &corev1.RemoveMeasurementTrustedProfileResponse{} | ||
| apiErr = common.ExecuteCoreGRPC(ctx, stc, corev1.Forge_RemoveMeasurementTrustedProfile_FullMethodName, apiReq.ToProto(), coreResp, siteID) | ||
| if apiErr != nil { | ||
| logAPIError(logger, apiErr, "failed to delete profile trust approval") | ||
| return cutil.NewAPIErrorResponse(c, apiErr.Code, apiErr.Message, nil) | ||
| } | ||
| return c.JSON(http.StatusOK, model.NewAPIMeasurementTrustedProfile(coreResp.GetApprovalRecord())) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the requested approval or target ID is syntactically valid but no approval row exists, Core's delete path (
crates/api-core/src/measured_boot/rpc/site.rs) callsfetch_oneand wrapsRowNotFoundas an internal error, soExecuteCoreGRPCyields a 500 and this line forwards it. The new DELETE REST contract advertises 404 for missing IDs; map that not-found case before returning here (and in the analogous trusted-profile delete handler) so normal absent-resource deletes do not surface as server failures.Useful? React with 👍 / 👎.