Prevent panic in BackfillFeatures (#62920)

Use the nil safe GetMonthlyRequestLimit getter to avoid panics.
This commit is contained in:
rosstimothy
2026-01-16 15:19:44 +00:00
committed by GitHub
parent 88e835963a
commit 4bbbc08aa8
2 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ func BackfillFeatures(features *proto.Features) {
// set default Identity fields to legacy feature value
features.Entitlements[string(AccessLists)] = &proto.EntitlementInfo{Enabled: true, Limit: features.GetAccessList().GetCreateLimit()}
features.Entitlements[string(AccessMonitoring)] = &proto.EntitlementInfo{Enabled: features.GetAccessMonitoring().GetEnabled(), Limit: features.GetAccessMonitoring().GetMaxReportRangeLimit()}
features.Entitlements[string(AccessRequests)] = &proto.EntitlementInfo{Enabled: features.GetAccessRequests().MonthlyRequestLimit > 0, Limit: features.GetAccessRequests().GetMonthlyRequestLimit()}
features.Entitlements[string(AccessRequests)] = &proto.EntitlementInfo{Enabled: features.GetAccessRequests().GetMonthlyRequestLimit() > 0, Limit: features.GetAccessRequests().GetMonthlyRequestLimit()}
features.Entitlements[string(DeviceTrust)] = &proto.EntitlementInfo{Enabled: features.GetDeviceTrust().GetEnabled(), Limit: features.GetDeviceTrust().GetDevicesUsageLimit()}
// override Identity Package features if Identity is enabled: set true and clear limit
if features.GetIdentityGovernance() {
+18 -1
View File
@@ -19,7 +19,9 @@ package entitlements
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/testing/protocmp"
"github.com/gravitational/teleport/api/client/proto"
apiutils "github.com/gravitational/teleport/api/utils"
@@ -286,13 +288,28 @@ func TestBackfillFeatures(t *testing.T) {
string(OktaUserSync): {Enabled: false},
},
},
{
name: "no entitlements",
features: &proto.Features{},
expected: func() map[string]*proto.EntitlementInfo {
out := map[string]*proto.EntitlementInfo{
string(AccessLists): {Enabled: true},
}
for _, e := range AllEntitlements {
if _, ok := out[string(e)]; !ok {
out[string(e)] = &proto.EntitlementInfo{}
}
}
return out
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cloned := apiutils.CloneProtoMsg(tt.features)
BackfillFeatures(cloned)
require.Equal(t, tt.expected, cloned.Entitlements)
require.Empty(t, cmp.Diff(tt.expected, cloned.Entitlements, protocmp.Transform()))
})
}
}