Skip to content

Commit 3e7e0f8

Browse files
committed
fix: address felix review comments on AAA
1 parent 18d0dc1 commit 3e7e0f8

4 files changed

Lines changed: 29 additions & 112 deletions

File tree

api/cisco/nx/v1alpha1/aaaconfig_types.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,23 @@ import (
1313

1414
// AAAConfigSpec defines the desired state of AAAConfig
1515
type AAAConfigSpec struct {
16-
// LoginErrorEnable enables login error messages (NX-OS specific).
17-
// Maps to: aaa authentication login error-enable
16+
// LoginErrorEnable enables login error messages.
1817
// +optional
1918
LoginErrorEnable bool `json:"loginErrorEnable,omitempty"`
2019

2120
// KeyEncryption specifies the default encryption type for TACACS+ keys.
22-
// +kubebuilder:validation:Enum=Type6;Type7;Clear
2321
// +kubebuilder:default=Type7
2422
KeyEncryption TACACSKeyEncryption `json:"keyEncryption,omitempty"`
2523

2624
// RADIUSKeyEncryption specifies the default encryption type for RADIUS server keys.
27-
// +kubebuilder:validation:Enum=Type6;Type7;Clear
2825
// +kubebuilder:default=Type7
2926
RADIUSKeyEncryption RADIUSKeyEncryption `json:"radiusKeyEncryption,omitempty"`
3027

31-
// ConsoleAuthentication defines NX-OS console-specific authentication methods.
32-
// Maps to: aaa authentication login console <methods>
28+
// ConsoleAuthentication defines console-specific authentication methods.
3329
// +optional
3430
ConsoleAuthentication *NXOSMethodList `json:"consoleAuthentication,omitempty"`
3531

36-
// ConfigCommandsAuthorization defines NX-OS config-commands authorization methods.
37-
// Maps to: aaa authorization config-commands default <methods>
32+
// ConfigCommandsAuthorization defines config-commands authorization methods.
3833
// +optional
3934
ConfigCommandsAuthorization *NXOSMethodList `json:"configCommandsAuthorization,omitempty"`
4035
}

api/core/v1alpha1/aaa_types.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212

1313
// AAASpec defines the desired state of AAA.
1414
//
15-
// It models the Authentication, Authorization, and Accounting (AAA) configuration on a network device,
16-
// aligned with the OpenConfig system/aaa YANG model.
15+
// It models the Authentication, Authorization, and Accounting (AAA) configuration on a network device.
1716
// +kubebuilder:validation:XValidation:rule="has(self.serverGroups) || has(self.authentication) || has(self.authorization) || has(self.accounting)",message="at least one of serverGroups, authentication, authorization, or accounting must be set"
1817
type AAASpec struct {
1918
// DeviceName is the name of the Device this object belongs to. The Device object must exist in the same namespace.
@@ -28,25 +27,21 @@ type AAASpec struct {
2827
ProviderConfigRef *TypedLocalObjectReference `json:"providerConfigRef,omitempty"`
2928

3029
// ServerGroups is the list of AAA server groups.
31-
// OpenConfig: /system/aaa/server-groups/server-group
3230
// +optional
3331
// +listType=map
3432
// +listMapKey=name
3533
// +kubebuilder:validation:MaxItems=8
3634
ServerGroups []AAAServerGroup `json:"serverGroups,omitempty"`
3735

3836
// Authentication defines the AAA authentication method list.
39-
// OpenConfig: /system/aaa/authentication
4037
// +optional
4138
Authentication *AAAAuthentication `json:"authentication,omitempty"`
4239

4340
// Authorization defines the AAA authorization method list.
44-
// OpenConfig: /system/aaa/authorization
4541
// +optional
4642
Authorization *AAAAuthorization `json:"authorization,omitempty"`
4743

4844
// Accounting defines the AAA accounting method list.
49-
// OpenConfig: /system/aaa/accounting
5045
// +optional
5146
Accounting *AAAAccounting `json:"accounting,omitempty"`
5247
}
@@ -63,7 +58,6 @@ const (
6358
)
6459

6560
// AAAServerGroup represents a named group of AAA servers.
66-
// OpenConfig: /system/aaa/server-groups/server-group[name]
6761
// +kubebuilder:validation:XValidation:rule="self.type != 'TACACS' || self.servers.all(s, has(s.tacacs))",message="servers in a TACACS group must have tacacs config"
6862
// +kubebuilder:validation:XValidation:rule="self.type != 'RADIUS' || self.servers.all(s, has(s.radius))",message="servers in a RADIUS group must have radius config"
6963
type AAAServerGroup struct {
@@ -78,7 +72,6 @@ type AAAServerGroup struct {
7872
Type AAAServerGroupType `json:"type"`
7973

8074
// Servers is the list of servers in this group.
81-
// OpenConfig: /system/aaa/server-groups/server-group/servers/server
8275
// +required
8376
// +listType=map
8477
// +listMapKey=address
@@ -98,7 +91,6 @@ type AAAServerGroup struct {
9891
}
9992

10093
// AAAServer represents a single AAA server within a group.
101-
// OpenConfig: /system/aaa/server-groups/server-group/servers/server[address]
10294
type AAAServer struct {
10395
// Address is the IP address or hostname of the server.
10496
// +required
@@ -114,13 +106,11 @@ type AAAServer struct {
114106

115107
// TACACS contains TACACS+ specific server configuration.
116108
// Required when the parent server group type is TACACS.
117-
// OpenConfig augmentation: /system/aaa/server-groups/server-group/servers/server/tacacs
118109
// +optional
119110
TACACS *AAAServerTACACS `json:"tacacs,omitempty"`
120111

121112
// RADIUS contains RADIUS specific server configuration.
122113
// Required when the parent server group type is RADIUS.
123-
// OpenConfig augmentation: /system/aaa/server-groups/server-group/servers/server/radius
124114
// +optional
125115
RADIUS *AAAServerRADIUS `json:"radius,omitempty"`
126116
}
@@ -166,7 +156,6 @@ type AAAServerRADIUS struct {
166156
}
167157

168158
// AAAAuthentication defines the AAA authentication method list.
169-
// OpenConfig: /system/aaa/authentication
170159
type AAAAuthentication struct {
171160
// Methods is the ordered list of authentication methods.
172161
// Methods are tried in order until one succeeds or all fail.
@@ -178,7 +167,6 @@ type AAAAuthentication struct {
178167
}
179168

180169
// AAAAuthorization defines the AAA authorization method list.
181-
// OpenConfig: /system/aaa/authorization
182170
type AAAAuthorization struct {
183171
// Methods is the ordered list of authorization methods.
184172
// Methods are tried in order until one succeeds or all fail.
@@ -190,7 +178,6 @@ type AAAAuthorization struct {
190178
}
191179

192180
// AAAAccounting defines the AAA accounting method list.
193-
// OpenConfig: /system/aaa/accounting
194181
type AAAAccounting struct {
195182
// Methods is the ordered list of accounting methods.
196183
// Methods are tried in order until one succeeds or all fail.

internal/provider/cisco/nxos/aaa.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ func MapFallbackFromMethodList(methods []v1alpha1.AAAMethod) string {
268268
return AAAValueNo
269269
}
270270

271-
// MapNXOSRealm maps an NX-OS method type string to NX-OS realm.
272-
func MapNXOSRealm(methodType string) string {
271+
// MapRealm maps a method type string to an NX-OS realm.
272+
func MapRealm(methodType string) string {
273273
switch methodType {
274274
case "Group":
275275
return AAARealmTacacs
@@ -282,8 +282,8 @@ func MapNXOSRealm(methodType string) string {
282282
}
283283
}
284284

285-
// MapNXOSLocal checks if local is in an NX-OS method list.
286-
func MapNXOSLocal(methods []nxv1alpha1.NXOSMethod) string {
285+
// MapLocal checks if local is in a method list.
286+
func MapLocal(methods []nxv1alpha1.NXOSMethod) string {
287287
for _, m := range methods {
288288
if m.Type == "Local" {
289289
return AAAValueYes
@@ -292,8 +292,8 @@ func MapNXOSLocal(methods []nxv1alpha1.NXOSMethod) string {
292292
return AAAValueNo
293293
}
294294

295-
// MapNXOSFallback determines fallback setting from an NX-OS method list.
296-
func MapNXOSFallback(methods []nxv1alpha1.NXOSMethod) string {
295+
// MapFallback determines fallback setting from a method list.
296+
func MapFallback(methods []nxv1alpha1.NXOSMethod) string {
297297
if len(methods) > 1 {
298298
return AAAValueYes
299299
}

internal/provider/cisco/nxos/provider.go

Lines changed: 19 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,15 +2836,12 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
28362836
}
28372837
}
28382838

2839-
// Process server groups
28402839
for _, group := range req.AAA.Spec.ServerGroups {
28412840
switch group.Type {
28422841
case v1alpha1.AAAServerGroupTypeTACACS:
2843-
// Enable TACACS+ feature
28442842
tacacsFeature := TACACSFeatureEnabled
28452843
conf = append(conf, &tacacsFeature)
28462844

2847-
// Configure individual TACACS+ server hosts
28482845
for _, server := range group.Servers {
28492846
srv := &TacacsPlusProvider{
28502847
Name: server.Address,
@@ -2862,7 +2859,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
28622859
conf = append(conf, srv)
28632860
}
28642861

2865-
// Configure the TACACS+ server group
28662862
grp := &TacacsPlusProviderGroup{
28672863
Name: group.Name,
28682864
Vrf: group.VrfName,
@@ -2874,7 +2870,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
28742870
conf = append(conf, grp)
28752871

28762872
case v1alpha1.AAAServerGroupTypeRADIUS:
2877-
// Configure individual RADIUS server hosts
28782873
for _, server := range group.Servers {
28792874
srv := &RadiusProvider{
28802875
Name: server.Address,
@@ -2893,7 +2888,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
28932888
conf = append(conf, srv)
28942889
}
28952890

2896-
// Configure the RADIUS server group
28972891
grp := &RadiusProviderGroup{
28982892
Name: group.Name,
28992893
Vrf: group.VrfName,
@@ -2906,7 +2900,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29062900
}
29072901
}
29082902

2909-
// Configure AAA default authentication (from core API flat method list)
29102903
if req.AAA.Spec.Authentication != nil && len(req.AAA.Spec.Authentication.Methods) > 0 {
29112904
methods := req.AAA.Spec.Authentication.Methods
29122905
authen := &AAADefaultAuth{
@@ -2923,24 +2916,22 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29232916
conf = append(conf, authen)
29242917
}
29252918

2926-
// Configure AAA console authentication (from Cisco AAAConfig)
29272919
if cfg.Spec.ConsoleAuthentication != nil && len(cfg.Spec.ConsoleAuthentication.Methods) > 0 {
29282920
methods := cfg.Spec.ConsoleAuthentication.Methods
29292921
consoleAuth := &AAAConsoleAuth{
29302922
ErrEn: cfg.Spec.LoginErrorEnable,
2931-
Fallback: MapNXOSFallback(methods),
2932-
Local: MapNXOSLocal(methods),
2923+
Fallback: MapFallback(methods),
2924+
Local: MapLocal(methods),
29332925
}
29342926
if methods[0].Type == "Group" {
29352927
consoleAuth.Realm = MapRealmFromGroup(methods[0].GroupName, req.AAA.Spec.ServerGroups)
29362928
consoleAuth.ProviderGroup = methods[0].GroupName
29372929
} else {
2938-
consoleAuth.Realm = MapNXOSRealm(methods[0].Type)
2930+
consoleAuth.Realm = MapRealm(methods[0].Type)
29392931
}
29402932
conf = append(conf, consoleAuth)
29412933
}
29422934

2943-
// Configure AAA authorization (from core API flat method list)
29442935
if req.AAA.Spec.Authorization != nil && len(req.AAA.Spec.Authorization.Methods) > 0 {
29452936
methods := req.AAA.Spec.Authorization.Methods
29462937
author := &AAADefaultAuthor{
@@ -2953,20 +2944,18 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29532944
conf = append(conf, author)
29542945
}
29552946

2956-
// Configure AAA config-commands authorization (from Cisco AAAConfig)
29572947
if cfg.Spec.ConfigCommandsAuthorization != nil && len(cfg.Spec.ConfigCommandsAuthorization.Methods) > 0 {
29582948
methods := cfg.Spec.ConfigCommandsAuthorization.Methods
29592949
author := &AAADefaultAuthor{
29602950
CmdType: "config",
2961-
LocalRbac: MapNXOSLocal(methods) == AAAValueYes,
2951+
LocalRbac: MapLocal(methods) == AAAValueYes,
29622952
}
29632953
if methods[0].Type == "Group" {
29642954
author.ProviderGroup = methods[0].GroupName
29652955
}
29662956
conf = append(conf, author)
29672957
}
29682958

2969-
// Configure AAA accounting (from core API flat method list)
29702959
if req.AAA.Spec.Accounting != nil && len(req.AAA.Spec.Accounting.Methods) > 0 {
29712960
methods := req.AAA.Spec.Accounting.Methods
29722961
acct := &AAADefaultAcc{
@@ -2986,97 +2975,43 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29862975
}
29872976

29882977
func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest) error {
2989-
var conf []gnmiext.Configurable
2990-
2991-
// Read Cisco-specific config from ProviderConfig
2992-
var cfg nxv1alpha1.AAAConfig
2993-
if req.ProviderConfig != nil {
2994-
if err := req.ProviderConfig.Into(&cfg); err != nil {
2995-
return err
2996-
}
2997-
}
2998-
2999-
// Reset AAA accounting to local
3000-
if req.AAA.Spec.Accounting != nil {
3001-
conf = append(conf, &AAADefaultAcc{
3002-
Name: "Accounting",
3003-
Realm: AAARealmLocal,
3004-
LocalRbac: true,
3005-
})
3006-
}
3007-
3008-
// Reset AAA authorization to local
3009-
if req.AAA.Spec.Authorization != nil || cfg.Spec.ConfigCommandsAuthorization != nil {
3010-
conf = append(conf, &AAADefaultAuthor{
3011-
CmdType: "config",
3012-
ProviderGroup: "",
3013-
LocalRbac: true,
3014-
})
2978+
// Reset all AAA method config to device defaults unconditionally.
2979+
// gNMI deletes are idempotent, so it is safe to reset even if a field
2980+
// was never configured.
2981+
conf := []gnmiext.Configurable{
2982+
&AAADefaultAcc{Name: "Accounting", Realm: AAARealmLocal, LocalRbac: true},
2983+
&AAADefaultAuthor{CmdType: "config", LocalRbac: true},
2984+
&AAADefaultAuth{Realm: AAARealmLocal, Local: AAAValueYes, Fallback: AAAValueYes},
2985+
&AAAConsoleAuth{Realm: AAARealmLocal, Local: AAAValueYes, Fallback: AAAValueYes},
30152986
}
30162987

3017-
// Reset AAA authentication to local
3018-
if req.AAA.Spec.Authentication != nil {
3019-
conf = append(conf, &AAADefaultAuth{
3020-
Realm: AAARealmLocal,
3021-
Local: AAAValueYes,
3022-
Fallback: AAAValueYes,
3023-
ErrEn: false,
3024-
})
3025-
}
3026-
3027-
// Reset console authentication to local
3028-
if cfg.Spec.ConsoleAuthentication != nil {
3029-
conf = append(conf, &AAAConsoleAuth{
3030-
Realm: AAARealmLocal,
3031-
Local: AAAValueYes,
3032-
Fallback: AAAValueYes,
3033-
ErrEn: false,
3034-
})
3035-
}
3036-
3037-
// Delete server groups and hosts
3038-
hasTACACS := false
30392988
for _, group := range req.AAA.Spec.ServerGroups {
30402989
switch group.Type {
30412990
case v1alpha1.AAAServerGroupTypeTACACS:
3042-
hasTACACS = true
3043-
3044-
grp := &TacacsPlusProviderGroup{Name: group.Name}
3045-
if err := p.client.Delete(ctx, grp); err != nil {
2991+
if err := p.client.Delete(ctx, &TacacsPlusProviderGroup{Name: group.Name}); err != nil {
30462992
return err
30472993
}
30482994
for _, server := range group.Servers {
3049-
srv := &TacacsPlusProvider{Name: server.Address}
3050-
if err := p.client.Delete(ctx, srv); err != nil {
2995+
if err := p.client.Delete(ctx, &TacacsPlusProvider{Name: server.Address}); err != nil {
30512996
return err
30522997
}
30532998
}
2999+
tacacsFeature := TACACSFeatureDisabled
3000+
conf = append(conf, &tacacsFeature)
30543001

30553002
case v1alpha1.AAAServerGroupTypeRADIUS:
3056-
grp := &RadiusProviderGroup{Name: group.Name}
3057-
if err := p.client.Delete(ctx, grp); err != nil {
3003+
if err := p.client.Delete(ctx, &RadiusProviderGroup{Name: group.Name}); err != nil {
30583004
return err
30593005
}
30603006
for _, server := range group.Servers {
3061-
srv := &RadiusProvider{Name: server.Address}
3062-
if err := p.client.Delete(ctx, srv); err != nil {
3007+
if err := p.client.Delete(ctx, &RadiusProvider{Name: server.Address}); err != nil {
30633008
return err
30643009
}
30653010
}
30663011
}
30673012
}
30683013

3069-
// Disable TACACS+ feature
3070-
if hasTACACS {
3071-
tacacsFeature := TACACSFeatureDisabled
3072-
conf = append(conf, &tacacsFeature)
3073-
}
3074-
3075-
if len(conf) > 0 {
3076-
return p.Update(ctx, conf...)
3077-
}
3078-
3079-
return nil
3014+
return p.Update(ctx, conf...)
30803015
}
30813016

30823017
func init() {

0 commit comments

Comments
 (0)