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