@@ -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
30933082func (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
31873122func init () {
0 commit comments