Skip to content

Commit c2ac463

Browse files
committed
fix: address felix review comments on AAA
1 parent 6390402 commit c2ac463

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
@@ -2941,15 +2941,12 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29412941
}
29422942
}
29432943

2944-
// Process server groups
29452944
for _, group := range req.AAA.Spec.ServerGroups {
29462945
switch group.Type {
29472946
case v1alpha1.AAAServerGroupTypeTACACS:
2948-
// Enable TACACS+ feature
29492947
tacacsFeature := TACACSFeatureEnabled
29502948
conf = append(conf, &tacacsFeature)
29512949

2952-
// Configure individual TACACS+ server hosts
29532950
for _, server := range group.Servers {
29542951
srv := &TacacsPlusProvider{
29552952
Name: server.Address,
@@ -2967,7 +2964,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29672964
conf = append(conf, srv)
29682965
}
29692966

2970-
// Configure the TACACS+ server group
29712967
grp := &TacacsPlusProviderGroup{
29722968
Name: group.Name,
29732969
Vrf: group.VrfName,
@@ -2979,7 +2975,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29792975
conf = append(conf, grp)
29802976

29812977
case v1alpha1.AAAServerGroupTypeRADIUS:
2982-
// Configure individual RADIUS server hosts
29832978
for _, server := range group.Servers {
29842979
srv := &RadiusProvider{
29852980
Name: server.Address,
@@ -2998,7 +2993,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
29982993
conf = append(conf, srv)
29992994
}
30002995

3001-
// Configure the RADIUS server group
30022996
grp := &RadiusProviderGroup{
30032997
Name: group.Name,
30042998
Vrf: group.VrfName,
@@ -3011,7 +3005,6 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
30113005
}
30123006
}
30133007

3014-
// Configure AAA default authentication (from core API flat method list)
30153008
if req.AAA.Spec.Authentication != nil && len(req.AAA.Spec.Authentication.Methods) > 0 {
30163009
methods := req.AAA.Spec.Authentication.Methods
30173010
authen := &AAADefaultAuth{
@@ -3028,24 +3021,22 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
30283021
conf = append(conf, authen)
30293022
}
30303023

3031-
// Configure AAA console authentication (from Cisco AAAConfig)
30323024
if cfg.Spec.ConsoleAuthentication != nil && len(cfg.Spec.ConsoleAuthentication.Methods) > 0 {
30333025
methods := cfg.Spec.ConsoleAuthentication.Methods
30343026
consoleAuth := &AAAConsoleAuth{
30353027
ErrEn: cfg.Spec.LoginErrorEnable,
3036-
Fallback: MapNXOSFallback(methods),
3037-
Local: MapNXOSLocal(methods),
3028+
Fallback: MapFallback(methods),
3029+
Local: MapLocal(methods),
30383030
}
30393031
if methods[0].Type == "Group" {
30403032
consoleAuth.Realm = MapRealmFromGroup(methods[0].GroupName, req.AAA.Spec.ServerGroups)
30413033
consoleAuth.ProviderGroup = methods[0].GroupName
30423034
} else {
3043-
consoleAuth.Realm = MapNXOSRealm(methods[0].Type)
3035+
consoleAuth.Realm = MapRealm(methods[0].Type)
30443036
}
30453037
conf = append(conf, consoleAuth)
30463038
}
30473039

3048-
// Configure AAA authorization (from core API flat method list)
30493040
if req.AAA.Spec.Authorization != nil && len(req.AAA.Spec.Authorization.Methods) > 0 {
30503041
methods := req.AAA.Spec.Authorization.Methods
30513042
author := &AAADefaultAuthor{
@@ -3058,20 +3049,18 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
30583049
conf = append(conf, author)
30593050
}
30603051

3061-
// Configure AAA config-commands authorization (from Cisco AAAConfig)
30623052
if cfg.Spec.ConfigCommandsAuthorization != nil && len(cfg.Spec.ConfigCommandsAuthorization.Methods) > 0 {
30633053
methods := cfg.Spec.ConfigCommandsAuthorization.Methods
30643054
author := &AAADefaultAuthor{
30653055
CmdType: "config",
3066-
LocalRbac: MapNXOSLocal(methods) == AAAValueYes,
3056+
LocalRbac: MapLocal(methods) == AAAValueYes,
30673057
}
30683058
if methods[0].Type == "Group" {
30693059
author.ProviderGroup = methods[0].GroupName
30703060
}
30713061
conf = append(conf, author)
30723062
}
30733063

3074-
// Configure AAA accounting (from core API flat method list)
30753064
if req.AAA.Spec.Accounting != nil && len(req.AAA.Spec.Accounting.Methods) > 0 {
30763065
methods := req.AAA.Spec.Accounting.Methods
30773066
acct := &AAADefaultAcc{
@@ -3091,97 +3080,43 @@ func (p *Provider) EnsureAAA(ctx context.Context, req *provider.EnsureAAARequest
30913080
}
30923081

30933082
func (p *Provider) DeleteAAA(ctx context.Context, req *provider.DeleteAAARequest) error {
3094-
var conf []gnmiext.Configurable
3095-
3096-
// Read Cisco-specific config from ProviderConfig
3097-
var cfg nxv1alpha1.AAAConfig
3098-
if req.ProviderConfig != nil {
3099-
if err := req.ProviderConfig.Into(&cfg); err != nil {
3100-
return err
3101-
}
3102-
}
3103-
3104-
// Reset AAA accounting to local
3105-
if req.AAA.Spec.Accounting != nil {
3106-
conf = append(conf, &AAADefaultAcc{
3107-
Name: "Accounting",
3108-
Realm: AAARealmLocal,
3109-
LocalRbac: true,
3110-
})
3111-
}
3112-
3113-
// Reset AAA authorization to local
3114-
if req.AAA.Spec.Authorization != nil || cfg.Spec.ConfigCommandsAuthorization != nil {
3115-
conf = append(conf, &AAADefaultAuthor{
3116-
CmdType: "config",
3117-
ProviderGroup: "",
3118-
LocalRbac: true,
3119-
})
3083+
// Reset all AAA method config to device defaults unconditionally.
3084+
// gNMI deletes are idempotent, so it is safe to reset even if a field
3085+
// was never configured.
3086+
conf := []gnmiext.Configurable{
3087+
&AAADefaultAcc{Name: "Accounting", Realm: AAARealmLocal, LocalRbac: true},
3088+
&AAADefaultAuthor{CmdType: "config", LocalRbac: true},
3089+
&AAADefaultAuth{Realm: AAARealmLocal, Local: AAAValueYes, Fallback: AAAValueYes},
3090+
&AAAConsoleAuth{Realm: AAARealmLocal, Local: AAAValueYes, Fallback: AAAValueYes},
31203091
}
31213092

3122-
// Reset AAA authentication to local
3123-
if req.AAA.Spec.Authentication != nil {
3124-
conf = append(conf, &AAADefaultAuth{
3125-
Realm: AAARealmLocal,
3126-
Local: AAAValueYes,
3127-
Fallback: AAAValueYes,
3128-
ErrEn: false,
3129-
})
3130-
}
3131-
3132-
// Reset console authentication to local
3133-
if cfg.Spec.ConsoleAuthentication != nil {
3134-
conf = append(conf, &AAAConsoleAuth{
3135-
Realm: AAARealmLocal,
3136-
Local: AAAValueYes,
3137-
Fallback: AAAValueYes,
3138-
ErrEn: false,
3139-
})
3140-
}
3141-
3142-
// Delete server groups and hosts
3143-
hasTACACS := false
31443093
for _, group := range req.AAA.Spec.ServerGroups {
31453094
switch group.Type {
31463095
case v1alpha1.AAAServerGroupTypeTACACS:
3147-
hasTACACS = true
3148-
3149-
grp := &TacacsPlusProviderGroup{Name: group.Name}
3150-
if err := p.client.Delete(ctx, grp); err != nil {
3096+
if err := p.client.Delete(ctx, &TacacsPlusProviderGroup{Name: group.Name}); err != nil {
31513097
return err
31523098
}
31533099
for _, server := range group.Servers {
3154-
srv := &TacacsPlusProvider{Name: server.Address}
3155-
if err := p.client.Delete(ctx, srv); err != nil {
3100+
if err := p.client.Delete(ctx, &TacacsPlusProvider{Name: server.Address}); err != nil {
31563101
return err
31573102
}
31583103
}
3104+
tacacsFeature := TACACSFeatureDisabled
3105+
conf = append(conf, &tacacsFeature)
31593106

31603107
case v1alpha1.AAAServerGroupTypeRADIUS:
3161-
grp := &RadiusProviderGroup{Name: group.Name}
3162-
if err := p.client.Delete(ctx, grp); err != nil {
3108+
if err := p.client.Delete(ctx, &RadiusProviderGroup{Name: group.Name}); err != nil {
31633109
return err
31643110
}
31653111
for _, server := range group.Servers {
3166-
srv := &RadiusProvider{Name: server.Address}
3167-
if err := p.client.Delete(ctx, srv); err != nil {
3112+
if err := p.client.Delete(ctx, &RadiusProvider{Name: server.Address}); err != nil {
31683113
return err
31693114
}
31703115
}
31713116
}
31723117
}
31733118

3174-
// Disable TACACS+ feature
3175-
if hasTACACS {
3176-
tacacsFeature := TACACSFeatureDisabled
3177-
conf = append(conf, &tacacsFeature)
3178-
}
3179-
3180-
if len(conf) > 0 {
3181-
return p.Update(ctx, conf...)
3182-
}
3183-
3184-
return nil
3119+
return p.Update(ctx, conf...)
31853120
}
31863121

31873122
func init() {

0 commit comments

Comments
 (0)