#!/bin/bash # Authentication and authorization and IETF NACM # NACM data node rule # @see RFC 8341 A.1 and A.4 (and permit-all from A.2) # Tests for: # deny-nacm: This rule denies the "guest" group any access to the # /nacm subtree. # permit-acme-config: This rule gives the "limited" group read-write # access to the acme . # permit-dummy-interface: This rule gives the "limited" and "guest" # groups read-update access to the acme entry named # "dummy". This entry cannot be created or deleted by these groups; # it can only be altered. # permit-interface: This rule gives the "admin" group read-write # access to all acme entries. APPNAME=example # include err() and new() functions and creates $dir . ./lib.sh . ./nacm.sh cfg=$dir/conf_yang.xml fyang=$dir/test.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 # The rule-list is from A.2 RULES=$(cat < false deny deny deny $NGROUPS guest-acl guest deny-nacm /n:nacm * deny Deny the 'guest' group any access to the /nacm data. limited-acl limited permit-acme-config /acme:acme-netconf/acme:config-parameters read create update delete permit Allow the 'limited' group complete access to the acme NETCONF configuration parameters. Showing long form of 'access-operations' instead of shorthand. guest-limited-acl guest limited permit-dummy-interface /acme:interfaces/acme:interface[acme:name='dummy'] read update permit Allow the 'limited' and 'guest' groups read and update access to the dummy interface. admin-acl admin permit-interface /acme:interfaces/acme:interface * permit Allow the 'admin' group full access to all acme interfaces. $NADMIN 0 EOF ) exit # XXX 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 new2 "auth get (wrong passwd: access denied)" expecteq "$(curl -u andy:foo -sS -X GET http://localhost/restconf/data)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "The requested URL was unauthorized"}}} ' new2 "auth get (access)" expecteq "$(curl -u andy:bar -sS -X GET http://localhost/restconf/data/example:x)" '{"example:x": 0} ' #----------------Enable NACM 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)" "" new2 "admin get nacm" expecteq "$(curl -u andy:bar -sS -X GET http://localhost/restconf/data/example:x)" '{"example:x": 0} ' new2 "limited get nacm" expecteq "$(curl -u wilma:bar -sS -X GET http://localhost/restconf/data/example:x)" '{"example:x": 0} ' new2 "guest get nacm" expecteq "$(curl -u guest:bar -sS -X GET http://localhost/restconf/data/example:x)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "The requested URL was unauthorized"}}} ' new "admin edit nacm" expecteq "$(curl -u andy:bar -sS -X PUT -d '{"x": 1}' http://localhost/restconf/data/example:x)" "" new2 "limited edit nacm" expecteq "$(curl -u wilma:bar -sS -X PUT -d '{"x": 2}' http://localhost/restconf/data/example:x)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "default deny"}}} ' new2 "guest edit nacm" expecteq "$(curl -u guest:bar -sS -X PUT -d '{"x": 3}' http://localhost/restconf/data/example:x)" '{"ietf-restconf:errors" : {"error": {"error-type": "protocol","error-tag": "access-denied","error-severity": "error","error-message": "The requested URL was unauthorized"}}} ' 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