#!/usr/bin/env bash # Authentication and authorization and IETF NACM # NACM protocol operation rules # @see RFC 8341 A.1 and A.3 (and permit-all from A.2) # Tests for three protocol operation rules (all apply to module ietf-netconf) # deny-kill-session: This rule prevents the "limited" group or the # "guest" group from invoking the NETCONF protocol # operation. # deny-delete-config: This rule prevents the "limited" group or the # "guest" group from invoking the NETCONF protocol # operation. # permit-edit-config: This rule allows the "limited" group to invoke # the NETCONF protocol operation. This rule will have # no real effect unless the "exec-default" leaf is set to "deny". # # From RFC8040, I conclude that commit/discard should be done automatically # BY THE SYSTEM # Otherwise, if the device supports :candidate, all edits to # configuration nodes in {+restconf}/data are performed in the # candidate configuration datastore. The candidate MUST be # automatically committed to running immediately after each successful # edit. # Which means that restconf -X DELETE /data translates to edit-config + commit # which is allowed. # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example # Common NACM scripts . ./nacm.sh cfg=$dir/conf_yang.xml fyang=$dir/nacm-example.yang # Define default restconfig config: RESTCONFIG RESTCONFIG=$(restconf_config user false) cat < $cfg $cfg ietf-netconf:startup ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/run/$APPNAME.pidfile /usr/local/var/$APPNAME internal none true $RESTCONFIG EOF cat < $fyang module nacm-example{ yang-version 1.1; namespace "urn:example:nacm"; prefix nex; import ietf-netconf-acm { prefix nacm; } leaf x{ type int32; description "something to edit"; } } EOF # The groups are slightly modified from RFC8341 A.1 # The rule-list is from A.2 RULES=$(cat < false deny permit deny $NGROUPS guest-limited-acl limited guest deny-kill-session ietf-netconf kill-session exec deny Do not allow the 'limited' group or the 'guest' group to kill another session. deny-delete-config ietf-netconf delete-config exec deny Do not allow the 'limited' group or the 'guest' group to delete any configurations. limited-acl limited permit-edit-config ietf-netconf edit-config exec permit Allow the 'limited' group to edit the configuration. $NADMIN 0 EOF ) new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend if [ $RC -ne 0 ]; then new "kill old restconf daemon" stop_restconf_pre new "start restconf daemon" start_restconf -f $cfg fi new "wait restconf" wait_restconf new "auth set authentication config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$RULES" "" "" new "commit it" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "enable nacm" expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-netconf-acm:enable-nacm": true}' $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" 0 "HTTP/$HVER 204" #--------------- nacm enabled new "admin get nacm" expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "HTTP/$HVER 200" '{"nacm-example:x":0}' # Rule 1: deny-kill-session new "deny-kill-session: limited fail (netconf)" expecteof_netconf "$clixon_netconf -qf $cfg -U wilma" 0 "$DEFAULTHELLO" "44" "" "applicationaccess-deniederroraccess denied" new "deny-kill-session: guest fail (netconf)" expecteof_netconf "$clixon_netconf -qf $cfg -U guest" 0 "$DEFAULTHELLO" "44" "" "applicationaccess-deniederroraccess denied" new "deny-kill-session: admin ok (netconf)" expecteof_netconf "$clixon_netconf -qf $cfg -U andy" 0 "$DEFAULTHELLO" "44" "" "" # Rule 2: deny-delete-config new "deny-delete-config: limited fail (netconf)" expecteof_netconf "$clixon_netconf -qf $cfg -U wilma" 0 "$DEFAULTHELLO" "" "" "applicationaccess-deniederroraccess denied" new "deny-delete-config: guest fail (restconf)" expectpart "$(curl -u guest:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 403" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}' # In restconf delete-config is translated to edit-config which is permitted new "deny-delete-config: limited fail (restconf) ok" expectpart "$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 204" new "admin get nacm (should fail)" expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "HTTP/$HVER 404" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}' new "deny-delete-config: admin ok (restconf)" expectpart "$(curl -u andy:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 204" # Here the whole config is gone so we need to start again new "auth set authentication config (restart)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$RULES" "" "" new "commit it" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "enable nacm" expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-netconf-acm:enable-nacm": true}' $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" 0 "HTTP/$HVER 204" # Rule 3: permit-edit-config new "permit-edit-config: limited ok restconf" expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"nacm-example:x":2}' $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "HTTP/$HVER 204" new "permit-edit-config: guest fail restconf" expectpart "$(curl -u guest:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"nacm-example:x":2}' $RCPROTO://localhost/restconf/data/nacm-example:x)" 0 "HTTP/$HVER 403" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}}' if [ $RC -ne 0 ]; then new "Kill restconf daemon" stop_restconf fi if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi rm -rf $dir new "endtest" endtest