Last year at the Boston OpenStack summit, I presented on an Idea of using URL patterns to enforce RBAC. While this idea is on hold for the time being, a related approach is moving forward building on top of application credentials. In this approach, the set of acceptable URLs is added to the role, so it is an additional check. This is a lower barrier to entry approach.
One thing I requested on the specification was to use the same mechanism as I had put forth on the RBAC in Middleware spec: the URL pattern. The set of acceptable URL patterns will be specified by an operator.
The user selects the URL pattern they want to add as a “white-list” to their application credential. A user could further specify a dictionary to fill in the segments of that URL pattern, to get a delegation down to an individual resource.
I wanted to see how easy it would be to generate a list of URL patterns. It turns out that, for the projects that are using the oslo-policy-in-code approach, it is pretty easy;
cd /opt/stack/nova . .tox/py35/bin/activate (py35) [ayoung@ayoung541 nova]$ oslopolicy-sample-generator --namespace nova | egrep "POST|GET|DELETE|PUT" | sed 's!#!!' POST /servers/{server_id}/action (os-resetState) POST /servers/{server_id}/action (injectNetworkInfo) POST /servers/{server_id}/action (resetNetwork) POST /servers/{server_id}/action (changePassword) GET /os-agents POST /os-agents PUT /os-agents/{agent_build_id} DELETE /os-agents/{agent_build_id} ... |
Similar for Keystone
$ oslopolicy-sample-generator --namespace keystone | egrep "POST|GET|DELETE|PUT" | sed 's!# !!' | head -10 GET /v3/users/{user_id}/application_credentials/{application_credential_id} GET /v3/users/{user_id}/application_credentials POST /v3/users/{user_id}/application_credentials DELETE /v3/users/{user_id}/application_credentials/{application_credential_id} PUT /v3/OS-OAUTH1/authorize/{request_token_id} GET /v3/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id} GET /v3/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}/roles/{role_id} GET /v3/users/{user_id}/OS-OAUTH1/access_tokens GET /v3/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id}/roles DELETE /v3/users/{user_id}/OS-OAUTH1/access_tokens/{access_token_id} |
The output of the tool is a little sub-optimal, as the oslo policy enforcement used to be done using only JSON, and JSON does not allow comments, so I had to scrape the comments out of the YAML format. Ideally, we could tweak the tool to output the URL patterns and the policy rules that enforce them in a clean format.
What roles are used? Turns out, we can figure that out, too:
$ oslopolicy-sample-generator --namespace keystone | grep \"role: #"admin_required": "role:admin or is_admin:1" #"service_role": "role:service" |
So only admin or service are actually used. On Nova:
$ oslopolicy-sample-generator --namespace nova | grep \"role: #"context_is_admin": "role:admin" |
Only admin.
How about matching the URL pattern to the policy rule?
If I run
oslopolicy-sample-generator --namespace nova | less |
In the middle I can see an example like this (# marsk removed for syntax):
# Create, list, update, and delete guest agent builds # This is XenAPI driver specific. # It is used to force the upgrade of the XenAPI guest agent on # instance boot. GET /os-agents POST /os-agents PUT /os-agents/{agent_build_id} DELETE /os-agents/{agent_build_id} "os_compute_api:os-agents": "rule:admin_api" |
This is not 100% deterministic, though, as some services, Nova in particular, enforce policy based on the payload.
For example, these operations can be done by the resource owner:
# Restore a soft deleted server or force delete a server before # deferred cleanup POST /servers/{server_id}/action (restore) POST /servers/{server_id}/action (forceDelete) "os_compute_api:os-deferred-delete": "rule:admin_or_owner" |
Where as these operations must be done by an admin operator:
# Evacuate a server from a failed host to a new host POST /servers/{server_id}/action (evacuate) "os_compute_api:os-evacuate": "rule:admin_api" |
Both map to the same URL pattern. We tripped over this when working on RBAC in Middleware, and it is going to be an issue with the Whitelist as well.
Looking at the API docs, we can see that difference in the bodies of the operations. The Evacuate call has a body like this:
{ "evacuate": { "host": "b419863b7d814906a68fb31703c0dbd6", "adminPass": "MySecretPass", "onSharedStorage": "False" } } |
Whereas the forceDelete call has a body like this:
{ "forceDelete": null } |
From these, it is pretty straight forward to figure out what policy to apply, but as of yet, there is no programmatic way to access that.
It would take a little more scripting to try and identity the set of rules that mean a user should be able to perform those actions with a project scoped token versus the set of APIs that are reserved for cloud operations. However, just looking at the admin_or_owner rule for most is sufficient to indicate that it should be performed using a scoped token. Thus, an end user should be able to determine the set of operations that she can include in a white-list.