policy-based access
note
policy-based access is supported in the standalone matlab® web app server™ product and not the development version included in matlab compiler™. for details, see .
prerequisites
enable ssl on the server. for more information, see .
enable authentication on the server. for more information, see authentication.
create webapps_acc_ctl.json
file
enabling policy-based access on the server lets you create attribute-based rules that permit authenticated subjects to access web apps on the server.
to enable policy-based access:
check if ssl is enabled. for more information, see .
check if authentication is enabled and verify that either or both the
userattributename
andgroupattributename
values have been specified in thewebapps_authn.json
file. for details, see authentication.check if folders exist within the
apps
root folder on the server. while folders are not necessary to enable policy-based access, having folders lets you organize web apps and specify them as a resource that can be accessed. for details, see .create a file named
webapps_acc_ctl.json
and place it in thewebapps_private
folder.the
webapps_private
folder can be found in:operating system folder location windows®
%programdata%\mathworks\webapps\r2023a\config\webapps_private
linux®
/local/mathworks/webapps/r2023a/config/webapps_private
macos
/library/application support/mathworks/webapps/r2023a/config/webapps_private
the json schema for webapps_acc_ctl.json
is:
{
"version": "..",
"policy": [
{
"id": "",
"description": "",
"rule": [
{
"id": "",
"description": "",
"subject": { "": [ "" ] },
"resource": { "": [ "" ] },
"action": [ "" ]
},
{
"id": "",
"description": "",
"subject": { "": [ "" ] },
"resource": { "": [ "" ] },
"action": [ "" ]
}
]
}
]
}
version: specify the version of the json schema. the default value for r2023a is
1.0.0
.policy: the policy block contains a list of policies required for policy-based access. only a single policy can be specified in a policy file.
id: specify a policy id for the policy. the policy id must be a set of alphanumeric characters. any leading or trailing white space is removed. for example:
"id" : "policy420"
description: specify a description for the policy. for example:
"description" : "company policy for accessing web apps."
rule: the rule block contains a list of rule objects. multiple rules can exist in a rule block. an id is required for each rule and
must be unique for each rule.id: specify a unique rule id for each rule. the rule id must be a set of alphanumeric characters. any leading or trailing white space is removed. for example:
"id" : "rule101"
description: specify a description for each rule. for example:
"description" : "only the hercules group can run the bloodpressure app."
subject: specify an attribute name-value pair of an authenticated subject that can access resources.
for example:
"subject": { "memberof": ["cn=middle,ou=middle,ou=groups,dc=school,dc=com"] }
"subject": { "groups": ["sales"] }
"subject": { "uid": ["fbueller", "cfrye"] }
if you are using an azure® active directory and need to retrieve group ids, see .
resource: specify the type and name of the resources that can be accessed. only resources of type
app
orfolder
are supported. if you do not specify a resource, then an authenticated subject will not have access to the app or folder even if it exists on the server. for information on how to create folders, see .for example, to specify access to an app at the root level:
"resource": { "app": ["bloodpressure"] }
for example, to specify access to an app in a particular folder:
"resource": { "app": ["magicfolder/cardtricks"] }
for example, to specify access to all apps in a particular folder:
"resource": { "folder": ["magicfolder"] }
for example, to specify access to all apps in the root folder:
"resource": { "folder": ["/"] }
action: specify the type of action the authenticated subject can perform. if the resource type is
app
, the action supported isexecute
, which lets the subject run a web app. if the resource type isfolder
, the actions supported areexecute
andmodify
. theexecute
action, in this case, lets the subject run all the web apps in a specified folder. themodify
action lets the subject upload or delete a web app to or from a folder if the subject is assigned the role of author in thewebapps_app_roles.json
role-based access file. a subject assigned the role of user in thewebapps_app_roles.json
role-based access file cannot upload or delete a web app to or from a folder even if they are assigned amodify
action. for example:"action": ["execute", "modify"]
for details, see role-based access.
example webapps_acc_ctl.json
file for ldap authentication
{
"version": "1.0.0",
"policy" : [
{
"id": "policy1001",
"description": "web apps access control policy",
"rule": [
{
"id": "rule101",
"description": "sales group can run the bloodpressure app.",
"subject": { "memberof": ["cn=sales,ou=sales,ou=groups,dc=myboston,dc=com"] },
"resource": { "app": ["bloodpressure"] },
"action": ["execute"]
},
{
"id": "rule102",
"description": "specified subjects can run the cardtricks app in the magicdir folder.",
"subject": { "uid": ["erooney"] },
"resource": { "app": ["magicdir/cardtricks"] },
"action": ["execute"]
},
{
"id": "rule103",
"description": "specified subjects can run all apps in the magicdir folder and modify (upload or delete) apps in magicdir folder.",
"subject": { "uid": ["fbueller"] },
"resource": { "folder": ["magicdir"] },
"action": ["execute", "modify"]
},
{
"id": "rule104",
"description": "specified subjects can run all apps under the dayoff folder.",
"subject": { "uid": ["cfrye", "psloane"] },
"resource": { "folder": ["dayoff"] },
"action": ["execute"]
},
{
"id": "rule105",
"description": "specified subjects can run all apps in the apps root folder and modify (upload or delete) apps in the apps root folder.",
"subject": { "uid": ["jbueller"] },
"resource": { "folder": ["/"] },
"action": ["execute", "modify"]
}
]
}
]
}
caution
the json schema syntax for webapps_acc_ctl.json
is
strictly enforced. errors in the schema syntax may result in the server not
starting, or you being denied access to the server when you try to log
in.
using policy-based access with authentication and role-based access
policy-based access with authentication
if you use policy-based access, you must include the following properties in the
appconfig
block of thewebapps_authn.json
authentication file and set appropriate values:userattributename
groupattributename
a failure to include and set values for these properties results in the server not starting. for details, see authentication.
if you use policy-based access, and set values for
userattributename
andgroupattributename
in thewebapps_authn.json
authentication file, then the attributes specified for thesubject
property in thewebapps_acc_ctl.json
policy-based access file must match the values you set in the authentication file.authentication file (webapps_authn.json) policy-based access file (webapps_acc_ctl.json) "userattributename": "
", "groupattributename": "
""subject": { "
": ["..."] } "subject": { "
": ["..."] }for example, if you set the following values in the
webapps_authn.json
authentication file:"userattributename": "uid", "groupattributename": "memberof"
then, the
webapps_acc_ctl.json
policy-based access file must use the same values:"subject": { "uid": ["..."] }
"subject": { "memberof": ["..."] }
a mismatch of attributes in the json files results in the server not starting. for details, see policy-based access.
note
you can use policy-based access with authentication independent of role-based access. however, this type of access results in authenticated subjects being able to only execute web apps but not modify them.
policy-based and role-based access with authentication
if you use policy-based access and role-based access simultaneously, and set values for
userattributename
and/orgroupattributename
in thewebapps_authn.json
authentication file, then the attributes specified for thesubject
property in thewebapps_acc_ctl.json
policy-based access file and the attributes specified for thegroups
andusers
properties must match the values you set in the authentication file.authentication file ( webapps_authn.json
)policy-based access file ( webapps_acc_ctl.json
)role-based access file ( webapps_app_roles.json
)"userattributename": "
", "groupattributename": "
""subject": { "
": ["..."] } "subject": { "
": ["..."] }"users": { "
": ["..."] } "groups": { "
": ["..."] }for example, if you set the following values in the
webapps_authn.json
authentication file:"userattributename": "uid", "groupattributename": "memberof"
then, the
webapps_app_roles.json
role-based access file must use the same attributes:"approles": [ { "id": "user", "description": "user role info", "groups": { "memberof": ["..."] }, "users": { "uid": ["..."] } }, { "id": "author", "description": "author role info", "groups": { "memberof": ["..."] }, "users": { "uid": ["..."] } } ]
and, the
webapps_acc_ctl.json
policy-based access file must use the same values:"subject": { "memberof": ["..."] }
"subject": { "uid": ["..."] }
a mismatch of values results in the server not starting. for details, see role-based access.
note
when you use policy-based access and role-based access with
authentication, an authenticated subject must be assigned the role of
author in the
webapps_app_roles.json
role-based access file and
have modify
as an action in the
webapps_acc_ctl.json
policy-based access file in
order for the subject to be able to modify web apps.