Skip to content

Commit 8bbf8ca

Browse files
committed
add permissions to control user of rest and xmlrpc API interfaces.
issue2551058: Add new permissions: 'Rest Access' and 'Xmlrpc Access' to allow per-user access control to rest and xmlrpc interfaces using roles. Updated all schemas to add these new perms to all authenticated roles. Error conditions in handle_xmlrpc were not working right in manual testing. I tried to make it a little better, but I don't actually understand how the fault xmlrpc object is supposed to be used. So I may have messed something up. I'll try to ping the people who wrote the xmlrpc code to have them review.
1 parent 86c350c commit 8bbf8ca

File tree

11 files changed

+173
-11
lines changed

11 files changed

+173
-11
lines changed

CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ Features:
9191
- issue2551061: Add rudimentary experimental support for JSON Web
9292
Tokens to allow delegation of limited access rights to third
9393
parties. See doc/rest.txt for details and intent. (John Rouillard)
94-
94+
- issue2551058: Add new permissions: 'Rest Access' and 'Xmlrpc Access'
95+
to allow per-user access control to rest and xmlrpc interfaces using
96+
roles.
9597

9698
Fixed:
9799

doc/rest.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Introduction
1212

1313
After the last 1.6.0 Release, a REST-API developed in 2015 during a
1414
Google Summer of Code (GSOC) by Chau Nguyen, supervised by Ezio
15-
Melotti was integrated. The code was updated by John Rouillard and
16-
Ralf Schlatterbeck to fix some shortcomings and provide the necessary
15+
Melotti was integrated. The code was updated by Ralf Schlatterbeck
16+
and John Rouillard to fix some shortcomings and provide the necessary
1717
functions for a single page web application, e.g. etag support,
1818
pagination, field embedding among others.
1919

@@ -23,6 +23,15 @@ Enabling the REST API
2323
The REST API can be disabled in the ``[web]`` section of ``config.ini``
2424
via the variable ``enable_rest`` which is ``yes`` by default.
2525

26+
Users have to be authorized to use the rest api. The user must have
27+
"Rest Access" permission. To add this to the "User" role change
28+
schema.py to add::
29+
30+
db.security.addPermissionToRole('User', 'Rest Access')
31+
32+
This is usually included near where other permissions like "Web Access"
33+
or "Email Access" are assigned.
34+
2635
The REST api is reached via the ``/rest/`` endpoint of the tracker
2736
URL. Partial URLs paths below (not starting with https) will have
2837
/rest removed for brevity.
@@ -1386,6 +1395,7 @@ proper authorization::
13861395
properties=('id', 'times'),
13871396
description="Allow editing timelog for issue", props_only=False)
13881397
db.security.addPermissionToRole("User:timelog", perm)
1398+
db.security.addPermissionToRole('User:timelog', 'Rest Access')
13891399

13901400
Then role is named to work with the jwt issue rest call. Starting the role
13911401
name with ``User:`` allows the jwt issue code to create a token with

doc/upgrading.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ https://pypi.org/project/MySQL-python/ is still supported, it is
5050
recommended to switch to the updated module from
5151
https://pypi.org/project/mysqlclient/.
5252

53+
XMLRPC Access Role
54+
------------------
55+
56+
A new permission has been added to control access to the XMLRPC
57+
endpoint. If the user doesn't have the new "Xmlrpc Access" permission,
58+
they will not be able to log in using the /xmlrpc end point. To add
59+
this new permission to the "User" role you should change your
60+
tracker's schema.py and add::
61+
62+
db.security.addPermissionToRole('User', 'Xmlrpc Access')
63+
64+
This is usually included near where other permissions like "Web Access"
65+
or "Email Access" are assigned.
66+
5367
Python 3 support
5468
----------------
5569

doc/xmlrpc.txt

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,33 @@ Enabling XML-RPC server
2323
-----------------------
2424
There are two ways to run the XML-RPC interface:
2525

26+
through roundup itself
27+
2628
stand alone roundup-xmlrpc-server
2729

28-
through roundup itself
30+
31+
through roundup
32+
---------------
33+
The XML-RPC service is available from the roundup HTTP server under
34+
/xmlrpc.
35+
36+
To enable this set ``enable_xmlrpc`` to ``yes`` in the ``[web]``
37+
section of the ``config.ini`` file in your tracker.
38+
39+
Each user that needs access must include the "Xmlrpc Access" role. To
40+
add this new permission to the "User" role you should change your
41+
schema.py to add::
42+
43+
db.security.addPermissionToRole('User', 'Xmlrpc Access')
44+
45+
This is usually included near where other permissions like "Web Access"
46+
or "Email Access" are assigned.
2947

3048
stand alone roundup-xmlrpc-server
3149
---------------------------------
50+
Using roundup to access the xmlrpc interface is preferred. Roundup
51+
provides better control over who can use the interface.
52+
3253
The Roundup XML-RPC standalone server must be started before remote clients can access the
3354
tracker via XML-RPC. ``roundup-xmlrpc-server`` is installed in the scripts
3455
directory alongside ``roundup-server`` and roundup-admin``. When invoked, the
@@ -39,11 +60,6 @@ location of the tracker instance must be specified.
3960
The default port is ``8000``. An alternative port can be specified with the
4061
``--port`` switch.
4162

42-
through roundup
43-
---------------
44-
In addition to running a stand alone server described above, the
45-
XML-RPC service is available from the roundup HTTP server.
46-
4763
security consideration
4864
----------------------
4965
Note that the current ``roundup-xmlrpc-server`` implementation does not

roundup/cgi/client.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def initialiseSecurity(security):
6262
description="User may access the web interface")
6363
security.addPermissionToRole('Admin', p)
6464

65+
p = security.addPermission(name="Rest Access",
66+
description="User may access the rest interface")
67+
security.addPermissionToRole('Admin', p)
68+
69+
p = security.addPermission(name="Xmlrpc Access",
70+
description="User may access the xmlrpc interface")
71+
security.addPermissionToRole('Admin', p)
72+
6573
# doing Role stuff through the web - make sure Admin can
6674
# TODO: deprecate this and use a property-based control
6775
p = security.addPermission(name="Web Roles",
@@ -497,9 +505,22 @@ def handle_xmlrpc(self):
497505
self.determine_user()
498506
except LoginError as msg:
499507
output = xmlrpc_.client.dumps(
500-
xmlrpc_.client.Fault(1, "%s:%s" % (exc_type, exc_value)),
508+
xmlrpc_.client.Fault(401, "%s" % msg),
501509
allow_none=True)
510+
self.setHeader("Content-Type", "text/xml")
511+
self.setHeader("Content-Length", str(len(output)))
512+
self.write(s2b(output))
513+
return
502514

515+
if not self.db.security.hasPermission('Xmlrpc Access', self.userid):
516+
output = xmlrpc_.client.dumps(
517+
xmlrpc_.client.Fault(403, "Forbidden"),
518+
allow_none=True)
519+
self.setHeader("Content-Type", "text/xml")
520+
self.setHeader("Content-Length", str(len(output)))
521+
self.write(s2b(output))
522+
return
523+
503524
self.check_anonymous_access()
504525

505526
try:
@@ -544,6 +565,11 @@ def handle_rest(self):
544565
self.write(output)
545566
return
546567

568+
if not self.db.security.hasPermission('Rest Access', self.userid):
569+
self.response_code = 403
570+
self.write(s2b('{ "error": { "status": 403, "msg": "Forbidden." } }'))
571+
return
572+
547573
self.check_anonymous_access()
548574

549575
try:

share/roundup/templates/classic/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
# Give the regular users access to the web and email interface
9090
db.security.addPermissionToRole('User', 'Web Access')
9191
db.security.addPermissionToRole('User', 'Email Access')
92+
db.security.addPermissionToRole('User', 'Rest Access')
93+
db.security.addPermissionToRole('User', 'Xmlrpc Access')
9294

9395
# Assign the access and edit Permissions for issue, file and message
9496
# to regular users now

share/roundup/templates/devel/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@
205205
for r in 'User', 'Developer', 'Coordinator':
206206
db.security.addPermissionToRole(r, 'Web Access')
207207
db.security.addPermissionToRole(r, 'Email Access')
208-
208+
db.security.addPermissionToRole(r, 'Rest Access')
209+
db.security.addPermissionToRole(r, 'Xmlrpc Access')
210+
209211
##########################
210212
# User permissions
211213
##########################

share/roundup/templates/jinja2/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
# Give the regular users access to the web and email interface
9090
db.security.addPermissionToRole('User', 'Web Access')
9191
db.security.addPermissionToRole('User', 'Email Access')
92+
db.security.addPermissionToRole('User', 'Rest Access')
93+
db.security.addPermissionToRole('User', 'Xmlrpc Access')
9294

9395
# Assign the access and edit Permissions for issue, file and message
9496
# to regular users now

share/roundup/templates/minimal/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
# Give the regular users access to the web and email interface
3030
db.security.addPermissionToRole('User', 'Web Access')
3131
db.security.addPermissionToRole('User', 'Email Access')
32+
db.security.addPermissionToRole('User', 'Rest Access')
33+
db.security.addPermissionToRole('User', 'Xmlrpc Access')
3234

3335
# May users view other user information?
3436
# Comment these lines out if you don't want them to

share/roundup/templates/responsive/schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@
204204
for r in 'User', 'Developer', 'Coordinator':
205205
db.security.addPermissionToRole(r, 'Web Access')
206206
db.security.addPermissionToRole(r, 'Email Access')
207+
db.security.addPermissionToRole(r, 'Rest Access')
208+
db.security.addPermissionToRole(r, 'Xmlrpc Access')
207209

210+
208211
##########################
209212
# User permissions
210213
##########################

0 commit comments

Comments
 (0)