Skip to content

Commit

Permalink
Return dummy values in service list for posture checks if no posture …
Browse files Browse the repository at this point in the history
…checks are defined. Fixes #1576
  • Loading branch information
plorenz committed Mar 20, 2024
1 parent 37e5394 commit a089ca7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion controller/internal/routes/service_api_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package routes

import (
"fmt"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/foundation/v2/stringz"
Expand Down Expand Up @@ -148,8 +149,20 @@ func MapServiceToRestModel(ae *env.AppEnv, rc *response.RequestContext, service

policyPostureCheckMap := ae.GetManagers().EdgeService.GetPolicyPostureChecks(rc.Identity.Id, *ret.ID)

for policyId, policyPostureChecks := range policyPostureCheckMap {
if len(policyPostureCheckMap) == 0 {
for _, permission := range ret.Permissions {
passing := true
id := fmt.Sprintf("dummy %s policy: no posture checks defined", strings.ToLower(string(permission)))
ret.PostureQueries = append(ret.PostureQueries, &rest_model.PostureQueries{
PolicyID: &id,
PostureQueries: []*rest_model.PostureQuery{},
PolicyType: permission,
IsPassing: &passing,
})
}
}

for policyId, policyPostureChecks := range policyPostureCheckMap {
isPolicyPassing := true
policyIdCopy := policyId
querySet := &rest_model.PostureQueries{
Expand Down
4 changes: 4 additions & 0 deletions controller/model/edge_service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ func (self *EdgeServiceManager) GetPolicyPostureChecks(identityId, serviceId str
policyTypeSymbol := self.env.GetStores().ServicePolicy.GetSymbol(db.FieldServicePolicyType)

_ = self.GetDb().View(func(tx *bbolt.Tx) error {
if !self.env.GetStores().PostureCheck.IterateIds(tx, ast.BoolNodeTrue).IsValid() {
return nil
}

policyCursor := self.env.GetStores().Identity.GetRelatedEntitiesCursor(tx, identityId, db.EntityTypeServicePolicies, true)
policyCursor = ast.NewFilteredCursor(policyCursor, func(policyId []byte) bool {
return serviceLinks.IsLinked(tx, policyId, []byte(serviceId))
Expand Down

0 comments on commit a089ca7

Please sign in to comment.