|
| 1 | +(* |
| 2 | + * Copyright (c) Cloud Software Group, Inc. |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published |
| 6 | + * by the Free Software Foundation; version 2.1 only. with the special |
| 7 | + * exception on linking described in file LICENSE. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. |
| 13 | + *) |
| 14 | + |
| 15 | +val is_access_allowed : |
| 16 | + __context:Context.t |
| 17 | + -> session_id:[`session] Ref.t |
| 18 | + -> permission:string |
| 19 | + -> bool |
| 20 | +(** Determines whether the session associated with the provided |
| 21 | + context has the specified permission. The permission set is cached |
| 22 | + (on the coordinator only) to benefit successive queries for the |
| 23 | + same session. *) |
| 24 | + |
| 25 | +val check : |
| 26 | + ?extra_dmsg:string |
| 27 | + -> ?extra_msg:string |
| 28 | + -> ?args:(string * Rpc.t) list |
| 29 | + -> ?keys:string list |
| 30 | + -> __context:Context.t |
| 31 | + -> fn:(unit -> 'a) |
| 32 | + -> [`session] Ref.t |
| 33 | + -> string |
| 34 | + -> 'a |
| 35 | +(** [check] executes a function associated with an action if the |
| 36 | + session associated with the provided context is authorised to |
| 37 | + perform the action. |
| 38 | +
|
| 39 | + The [?extra_dmsg] and [?extra_msg] parameters allow for extra |
| 40 | + information in debugging and error messages. |
| 41 | +
|
| 42 | + The [?keys] parameter specifies which fields of a (string -> _) |
| 43 | + map are RBAC-protected. It is primarily associated with |
| 44 | + auto-generated methods such as add_to_other_config. However, if |
| 45 | + [?keys] is non-empty, then [?args] must also be consulted as the |
| 46 | + related methods that require this protection specify their key |
| 47 | + name as a parameter. Otherwise, [?args] is mostly used to log |
| 48 | + calls within the RBAC audit log. *) |
| 49 | + |
| 50 | +val check_with_new_task : |
| 51 | + ?extra_dmsg:string |
| 52 | + -> ?extra_msg:string |
| 53 | + -> ?task_desc:string |
| 54 | + -> ?args:(string * Rpc.t) list |
| 55 | + -> fn:(unit -> 'a) |
| 56 | + -> [`session] Ref.t |
| 57 | + -> string |
| 58 | + -> 'a |
| 59 | +(** Defined in terms of [check] but using a context associated with a |
| 60 | + freshly-created task. *) |
| 61 | + |
| 62 | +val assert_permission_name : __context:Context.t -> permission:string -> unit |
| 63 | +(** Performs a dry run of the [check] function with a no-op action |
| 64 | + guarded by the provided permission (as a name). *) |
| 65 | + |
| 66 | +val assert_permission : |
| 67 | + __context:Context.t -> permission:Db_actions.role_t -> unit |
| 68 | +(** Performs a dry run of the [check] function with a no-op action |
| 69 | + guarded by the provided permission (as a database role). *) |
| 70 | + |
| 71 | +val has_permission : __context:Context.t -> permission:Db_actions.role_t -> bool |
| 72 | +(** [has_permission ctx p] determines if the session associated with |
| 73 | + the context [ctx] is authorised to perform a specific action. |
| 74 | +
|
| 75 | + [p] is of the type defined by the generated [Db_actions] module, |
| 76 | + as [Xapi_role] simulates a database for the checking of static |
| 77 | + role sets (as emitted in [Rbac_static]) and only appeals to the |
| 78 | + xapi DB for additional roles. *) |
| 79 | + |
| 80 | +val is_rbac_enabled_for_http_action : string -> bool |
| 81 | +(** [is_rbac_enabled_for_http_action route] determines whether RBAC |
| 82 | + checks should be applied to the provided HTTP [route]. |
| 83 | +
|
| 84 | + Some routes are precluded from RBAC checks because they are |
| 85 | + assumed to only be used by code paths where RBAC has already been |
| 86 | + checked or will be checked internally (e.g. /post_cli). *) |
| 87 | + |
| 88 | +val permission_of_action : |
| 89 | + ?args:(string * Rpc.t) list -> keys:string list -> string -> string |
| 90 | +(** Constructs the name of a permission associated with using an |
| 91 | + RBAC-protected key with a specified action. |
| 92 | +
|
| 93 | + For example, if [keys] specifies "folder" as a protected key name |
| 94 | + for the action SR.remove_from_other_config, the permission name |
| 95 | + associated with that is "SR.remove_from_other_config/key:folder" |
| 96 | + - which is consistent with the format that [Rbac_static] contains. *) |
| 97 | + |
| 98 | +val nofn : unit -> unit |
| 99 | +(** Named function that does nothing, e.g. (fun _ -> ()). |
| 100 | + Used as a dummy action for RBAC checking. *) |
| 101 | + |
| 102 | +val destroy_session_permissions_tbl : session_id:[`session] Ref.t -> unit |
| 103 | +(** Removes any cached permission set for the given session. This is |
| 104 | + called when xapi destroys the DB entry for a session. *) |
0 commit comments