* Top-level default leafs assigned.
* Enforcing RFC 7950 Sec 7.6.1 means unassigned top-level leafs (or leafs under non-presence containers) are assigned default values. * NACM default behaviour is read-only (empty configs are dead-lockedd) * This applies if NACM is loaded and `CLICON_NACM_MODE` is `internal` * Fixed: [default values don't show up in datastores #111](https://github.com/clicon/clixon/issues/111)
This commit is contained in:
parent
65733ffe69
commit
794d51a365
30 changed files with 593 additions and 167 deletions
|
|
@ -2,7 +2,9 @@
|
|||
# Authentication and authorization and IETF NACM
|
||||
# See RFC 8341 A.2
|
||||
# But replaced ietf-netconf-monitoring with *
|
||||
# Note credenials check set to none since USER poses as different users.
|
||||
# Note:
|
||||
# 1. credenials check set to none since USER poses as different users.
|
||||
# 2. CLICON_NACM_DISABLE_ON_EMPTY: start with empty config and add nacm config
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -31,6 +33,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
@ -140,7 +143,7 @@ expectpart "$(curl -u andy:bar $CURLOPTS -X GET $RCPROTO://localhost/restconf/da
|
|||
|
||||
# explicitly disable nacm (regression on netgate bug)
|
||||
new "disable nacm"
|
||||
expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-netconf-acm:enable-nacm": false}' $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" 0 "HTTP/1.1 201 Created"
|
||||
expectpart "$(curl -u andy:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" -d '{"ietf-netconf-acm:enable-nacm": false}' $RCPROTO://localhost/restconf/data/ietf-netconf-acm:nacm/enable-nacm)" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
new "auth set authentication config"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><edit-config><target><candidate/></target><config>$RULES</config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
<CLICON_NACM_CREDENTIALS>$mode</CLICON_NACM_CREDENTIALS>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
<CLICON_XMLDB_FORMAT>$format</CLICON_XMLDB_FORMAT>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
|
@ -62,7 +63,6 @@ EOF
|
|||
# 6: expected return value of test2
|
||||
# 7: expected return value of test3
|
||||
# 8: startup mode: startup or init
|
||||
# 9: Dont set default values (nullify them)
|
||||
testrun(){
|
||||
enablenacm=$1
|
||||
readdefault=$2
|
||||
|
|
@ -72,24 +72,9 @@ testrun(){
|
|||
ret2=$6
|
||||
ret3=$7
|
||||
db=$8
|
||||
nulldef=$9
|
||||
|
||||
# Set default values (or not)
|
||||
if [ $nulldef -ne 0 ]; then
|
||||
# Defaults should be: true permit deny permit:
|
||||
# nacm enabled, exec default permit, read permit (expect fail)"
|
||||
# which means results should be 0 1 3
|
||||
# Also enable-nacm is present since otherwise the nacm container would be removed
|
||||
# since it is non-presence
|
||||
NACM=$(cat <<EOF
|
||||
<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
|
||||
<enable-nacm>${enablenacm}</enable-nacm>
|
||||
</nacm>
|
||||
EOF
|
||||
)
|
||||
else
|
||||
NACM=$(cat <<EOF
|
||||
<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
|
||||
NACM=$(cat <<EOF
|
||||
<nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
|
||||
<enable-nacm>${enablenacm}</enable-nacm>
|
||||
<read-default>${readdefault}</read-default>
|
||||
<write-default>${writedefault}</write-default>
|
||||
|
|
@ -98,7 +83,6 @@ EOF
|
|||
</nacm>
|
||||
EOF
|
||||
)
|
||||
fi
|
||||
# Initial data
|
||||
XML='<x xmlns="urn:example:nacm">42</x>'
|
||||
|
||||
|
|
@ -117,6 +101,7 @@ EOF
|
|||
start_backend -s $db -f $cfg
|
||||
else
|
||||
new "Restart backend as eg follows: -Ff $cfg -s $db"
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
new "waiting"
|
||||
|
|
@ -132,12 +117,16 @@ EOF
|
|||
wait_restconf
|
||||
|
||||
# Use POST (instead of startup)
|
||||
# Note this only works because CLICON_NACM_DISABLED_ON_EMPTY is true
|
||||
if [ $db = init ]; then
|
||||
new "Set Initial data using POST"
|
||||
expectpart "$(curl -u guest:bar $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$XML" $RCPROTO://localhost/restconf/data)" 0 "HTTP/1.1 201 Created"
|
||||
# Must set NACM first
|
||||
new "Set NACM using PATCH"
|
||||
expectpart "$(curl -u guest:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+xml" -d "<data>$NACM$XML</data>" $RCPROTO://localhost/restconf/data)" 0 "HTTP/1.1 204 No Content"
|
||||
|
||||
# new "Set Initial data using POST"
|
||||
# expectpart "$(curl -u guest:bar $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$XML" $RCPROTO://localhost/restconf/data)" 0 "HTTP/1.1 201 Created"
|
||||
|
||||
new "Set NACM using POST"
|
||||
expectpart "$(curl -u guest:bar $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" -d "$NACM" $RCPROTO://localhost/restconf/data)" 0 "HTTP/1.1 201 Created"
|
||||
|
||||
fi
|
||||
|
||||
#----------- First get
|
||||
|
|
@ -204,39 +193,36 @@ EOF
|
|||
# Run a lot of tests with different settings of default read/write/exec
|
||||
# Outer loop either starts from startup or inits config via restconf POST
|
||||
for db in startup init; do
|
||||
new "nacm enabled and all defaults permit"
|
||||
testrun true permit permit permit 0 0 0 $db 0
|
||||
new "1. nacm enabled and all defaults permit"
|
||||
testrun true permit permit permit 0 0 0 $db
|
||||
|
||||
new "nacm disabled and all defaults permit"
|
||||
testrun false permit permit permit 0 0 0 $db 0
|
||||
new "2. nacm disabled and all defaults permit"
|
||||
testrun false permit permit permit 0 0 0 $db
|
||||
|
||||
new "nacm disabled and all defaults deny"
|
||||
testrun false deny deny deny 0 0 0 $db 0
|
||||
new "3. nacm disabled and all defaults deny"
|
||||
testrun false deny deny deny 0 0 0 $db
|
||||
|
||||
new "nacm enabled, all defaults deny (expect fail)"
|
||||
testrun true deny deny deny 1 1 1 $db 0
|
||||
new "4. nacm enabled, all defaults deny (expect fail)"
|
||||
testrun true deny deny deny 1 1 1 $db
|
||||
|
||||
new "nacm enabled, exec default deny - read permit (expect fail)"
|
||||
testrun true permit deny deny 1 1 1 $db 0
|
||||
new "5. nacm enabled, exec default deny - read permit (expect fail)"
|
||||
testrun true permit deny deny 1 1 1 $db
|
||||
|
||||
new "nacm enabled, exec default deny - write permit (expect fail)"
|
||||
testrun true deny permit deny 1 1 1 $db 0
|
||||
new "6. nacm enabled, exec default deny - write permit (expect fail)"
|
||||
testrun true deny permit deny 1 1 1 $db
|
||||
|
||||
new "nacm enabled, exec default deny read/write permit (expect fail)"
|
||||
testrun true permit permit deny 1 1 1 $db 0
|
||||
new "7. nacm enabled, exec default deny read/write permit (expect fail)"
|
||||
testrun true permit permit deny 1 1 1 $db
|
||||
|
||||
new "nacm enabled, exec default permit, all others deny (expect fail)"
|
||||
testrun true deny deny permit 2 1 2 $db 0
|
||||
new "8. nacm enabled, exec default permit, all others deny (expect fail)"
|
||||
testrun true deny deny permit 2 1 2 $db
|
||||
|
||||
new "nacm enabled, exec default permit, read permit (expect fail)"
|
||||
testrun true permit deny permit 0 1 3 $db 0 # This is yang default
|
||||
new "9. nacm enabled, exec default permit, read permit (expect fail)"
|
||||
testrun true permit deny permit 0 1 3 $db # This is yang default
|
||||
|
||||
new "nacm enabled, with default values (no settings - should be same as previous)"
|
||||
# note last 1 means nullify all default values)
|
||||
testrun true xxx xxx xxx 0 1 3 init 1
|
||||
new "10. nacm enabled, exec default permit, write permit (expect fail)"
|
||||
testrun true deny permit permit 2 0 2 $db
|
||||
|
||||
new "nacm enabled, exec default permit, write permit (expect fail)"
|
||||
testrun true deny permit permit 2 0 2 $db 0
|
||||
done
|
||||
|
||||
rm -rf $dir
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ module nacm-example{
|
|||
}
|
||||
prefix nacm;
|
||||
container authentication {
|
||||
description "Example code for enabling www basic auth and some example
|
||||
presence "To keep this from auto-expanding";
|
||||
description "Example code for enabling www basic auth and some example
|
||||
users";
|
||||
leaf basic_auth{
|
||||
description "Basic user / password authentication as in HTTP basic auth";
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_CREDENTIALS>none</CLICON_NACM_CREDENTIALS>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_CREDENTIALS>none</CLICON_NACM_CREDENTIALS>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ module scaling{
|
|||
yang-version 1.1;
|
||||
namespace "urn:example:clixon";
|
||||
prefix ex;
|
||||
import "clixon-config" {
|
||||
prefix cc;
|
||||
}
|
||||
container x {
|
||||
list y {
|
||||
key "a";
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ cat <<EOF > $cfg
|
|||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
<CLICON_NACM_MODE>internal</CLICON_NACM_MODE>
|
||||
<CLICON_NACM_DISABLED_ON_EMPTY>true</CLICON_NACM_DISABLED_ON_EMPTY>
|
||||
</clixon-config>
|
||||
EOF
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ cat <<EOF > $cfg
|
|||
<CLICON_STARTUP_MODE>init</CLICON_STARTUP_MODE>
|
||||
<CLICON_XMLDB_FORMAT>$format</CLICON_XMLDB_FORMAT>
|
||||
</clixon-config>
|
||||
|
||||
EOF
|
||||
|
||||
# Create running-db containin the interface "run" OK
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ module interfaces{
|
|||
reference
|
||||
"RFC 2863: The Interfaces Group MIB";
|
||||
}
|
||||
leaf foo{
|
||||
description "Should not appear";
|
||||
type string;
|
||||
default "bar";
|
||||
}
|
||||
container interfaces {
|
||||
description
|
||||
"Interface configuration parameters.";
|
||||
|
|
@ -52,8 +57,11 @@ module interfaces{
|
|||
leaf description {
|
||||
type string;
|
||||
}
|
||||
|
||||
|
||||
leaf foo{
|
||||
description "Should not appear";
|
||||
type string;
|
||||
default "bar";
|
||||
}
|
||||
leaf type {
|
||||
type string;
|
||||
mandatory true;
|
||||
|
|
@ -124,6 +132,11 @@ module interfaces{
|
|||
reference
|
||||
"RFC 2863: The Interfaces Group MIB";
|
||||
}
|
||||
leaf foo{
|
||||
description "Should not appear";
|
||||
type string;
|
||||
default "fie";
|
||||
}
|
||||
container interfaces {
|
||||
description
|
||||
"Interface configuration parameters.";
|
||||
|
|
@ -133,6 +146,11 @@ module interfaces{
|
|||
leaf name {
|
||||
type string;
|
||||
}
|
||||
leaf foo{
|
||||
description "Should not appear";
|
||||
type string;
|
||||
default "bar";
|
||||
}
|
||||
container docs{
|
||||
description "Original description is wrapped and renamed";
|
||||
leaf descr {
|
||||
|
|
@ -290,7 +308,6 @@ XML='<interfaces xmlns="urn:example:interfaces"><interface><name>e0</name><type>
|
|||
ALL="<config>$MODSTATE$XML</config>"
|
||||
|
||||
# -u means trigger example upgrade
|
||||
new "test params: -s startup -f $cfg -- -u"
|
||||
|
||||
# kill old backend (if any)
|
||||
new "kill old backend"
|
||||
|
|
@ -301,6 +318,7 @@ fi
|
|||
new "start backend -s startup -f $cfg -q -- -u"
|
||||
output=$(sudo $clixon_backend -F -D $DBG -s startup -f $cfg -q -- -u)
|
||||
#echo "$output"
|
||||
|
||||
if [ "$ALL" != "$output" ]; then
|
||||
err "$ALL" "$output"
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue