#!/bin/bash # Authentication and authorization and IETF NACM # NACM module rules # @see test_nacm.sh is slightly modified - this follows the RFC more closely # See RFC 8341 A.1 and A.2 # Note: use clixon-example instead of ietf-netconf-monitoring since the latter is # not yet implemented # Tests for # deny-ncm: This rule prevents the "guest" group from reading any # monitoring information in the "ietf-netconf-monitoring" YANG # module. # permit-ncm: This rule allows the "limited" group to read the # "ietf-netconf-monitoring" YANG module. # permit-exec: This rule allows the "limited" group to invoke any # protocol operation supported by the server. # permit-all: This rule allows the "admin" group complete access to # all content in the server. No subsequent rule will match for the # "admin" group because of this module rule APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh . ./nacm.sh cfg=$dir/conf_yang.xml fyang=$dir/nacm-example.yang cat < $cfg $cfg /usr/local/share/clixon $IETFRFC $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/$APPNAME/$APPNAME.pidfile 1 /usr/local/var/$APPNAME /usr/local/lib/xmldb/text.so false internal EOF cat < $fyang module nacm-example{ yang-version 1.1; namespace "urn:example:nacm"; prefix nacm; import clixon-example { prefix ex; } import ietf-netconf-acm { prefix nacm; } leaf x{ type int32; description "something to edit"; } } EOF # The groups are slightly modified from RFC8341 A.1 ($USER added in admin group) # The rule-list is from A.2 RULES=$(cat < false deny deny deny $NGROUPS guest-acl guest deny-ncm ietf-netconf-monitoring * deny Do not allow guests any access to the NETCONF monitoring information. limited-acl limited permit-ncm get ietf-netconf-monitoring read permit Allow read access to the NETCONF monitoring information. permit-exec * exec permit Allow invocation of the supported server operations. $NADMIN 42 key42val42 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" sudo $clixon_backend -s init -f $cfg -D $DBG if [ $? -ne 0 ]; then err fi fi new "kill old restconf daemon" sudo pkill -u www-data -f "/www-data/clixon_restconf" sleep 1 new "start restconf daemon (-a is enable basic authentication)" sudo su -c "$clixon_restconf -f $cfg -D $DBG -- -a" -s /bin/sh www-data & sleep $RCWAIT new "auth set authentication config" expecteof "$clixon_netconf -qf $cfg" 0 "$RULES]]>]]>" "^]]>]]>$" new "commit it" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "enable nacm" expecteq "$(curl -u andy:bar -sS -X PUT -d '{"enable-nacm": true}' http://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" "" #--------------- nacm enabled # Read monitoring information from example - (ietf-netconf-monitoring) new2 "admin read ok" expecteq "$(curl -u andy:bar -sS -X GET http://localhost/restconf/data/clixon-example:translate)" '{"clixon-example:translate": [{"k": "key42","value": "val42"}]} ' new2 "limit read ok" expecteq "$(curl -u wilma:bar -sS -X GET http://localhost/restconf/data/clixon-example:translate)" '{"clixon-example:translate": [{"k": "key42","value": "val42"}]} ' new2 "guest read fail" expecteq "$(curl -u guest:bar -sS -X GET http://localhost/restconf/data/clixon-example:translate)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "default deny"}}} ' new2 "guest read other module" expecteq "$(curl -u guest:bar -sS -X GET http://localhost/restconf/data/nacm-example:x)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "default deny"}}} ' new2 "admin read other module OK" expecteq "$(curl -u andy:bar -sS -X GET http://localhost/restconf/data/nacm-example:x)" '{"nacm-example:x": 42} ' new2 "admin rpc ok" expecteq "$(curl -u andy:bar -s -X POST -d '{"clixon-example:input":{"x":42}}' http://localhost/restconf/operations/clixon-example:example)" '{"clixon-example:output": {"x": "42","y": "42"}} ' new2 "limit rpc ok" expecteq "$(curl -u wilma:bar -s -X POST http://localhost/restconf/operations/clixon-example:example -d '{"clixon-example:input":{"x":42}}' )" '{"clixon-example:output": {"x": "42","y": "42"}} ' new2 "guest rpc fail" expecteq "$(curl -u guest:bar -s -X POST http://localhost/restconf/operations/clixon-example:example -d '{"clixon-example:input":{"x":42}}' )" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "default deny"}}} ' new "Kill restconf daemon" sudo pkill -u www-data -f "/www-data/clixon_restconf" if [ $BE -eq 0 ]; then exit # BE fi 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 sudo clixon_backend -z -f $cfg if [ $? -ne 0 ]; then err "kill backend" fi rm -rf $dir