xref: /openbmc/docs/designs/redfish-authorization.md (revision f4febd002df578bad816239b70950f84ea4567e8)
18fd98f13SNan Zhou# Dynamic Redfish Authorization
28fd98f13SNan Zhou
38fd98f13SNan ZhouAuthor: Nan Zhou (nanzhoumails@gmail.com)
48fd98f13SNan Zhou
58fd98f13SNan ZhouCreated: 08/08/2022
68fd98f13SNan Zhou
78fd98f13SNan Zhou## Problem Description
88fd98f13SNan Zhou
98fd98f13SNan ZhouThe Redfish authorization subsystem controls which authenticated users have
108fd98f13SNan Zhouaccess to resources and the type of access that users have.
118fd98f13SNan Zhou
128fd98f13SNan ZhouDMTF has already defined the authorization model and schemas. This design is to
138fd98f13SNan Zhouenhance the current implementation in BMCWeb Redfish interface so that OpenBMC
148fd98f13SNan Zhousystems exposes interfaces to change authorization behavior at runtime without
158fd98f13SNan ZhouRedfish service restart.
168fd98f13SNan Zhou
178fd98f13SNan Zhou## Background and References
188fd98f13SNan Zhou
198fd98f13SNan Zhou### Redfish Authorization Model
208fd98f13SNan Zhou
218fd98f13SNan ZhouThe Redfish authorization model consists of the privilege model and the
228fd98f13SNan Zhouoperation-to-privilege mapping.
238fd98f13SNan Zhou
248fd98f13SNan ZhouIn the privilege model, there are fixed set of standard Redfish roles and each
258fd98f13SNan Zhouof them is assigned a fixed array of standard privileges (e.g., `Login`,
268fd98f13SNan Zhou`ConfigureManager`, etc). A service may define custom OEM roles (read-only). A
278fd98f13SNan Zhouservice may even allow custom client-defined roles to be created, modified, and
288fd98f13SNan Zhoudeleted via REST operations on `RoleCollection`.
298fd98f13SNan Zhou
308fd98f13SNan ZhouThe operation-to-privilege mapping is defined for every resource type and
318fd98f13SNan Zhouapplies to every resource the service implements for the applicable resource
328fd98f13SNan Zhoutype. It is used to determine whether the identity privileges of an
338fd98f13SNan Zhouauthenticated Redfish role are sufficient to complete the operation in the
348fd98f13SNan Zhourequest. The Redfish Forum provides a Privilege Registry definition in its
358fd98f13SNan Zhouofficial registry collection as a base operation-to-privilege mapping. It also
368fd98f13SNan Zhouallows mapping overrides (Property override, Subordinate override, and Resource
378fd98f13SNan ZhouURI override) to customize mapping.
388fd98f13SNan Zhou
398fd98f13SNan ZhouFor example, a peer who is an `Operator` that has both `Login`,
408fd98f13SNan Zhou`ConfigureComponents`, and `ConfigureSelf` privileges, is authorized to send a
418fd98f13SNan Zhou`GET` request to the `ChassisCollection`, since the `GET` operation on this
428fd98f13SNan Zhouresource only requires the `Login` privilege. On the other hand, the same peer
438fd98f13SNan Zhougets denied access if they send a POST request to `CertificateService`, as the
448fd98f13SNan ZhouPOST operation on certificates requires `ConfigureManager` privilege that the
458fd98f13SNan Zhoupeer is missing.
468fd98f13SNan Zhou
478fd98f13SNan Zhou**Note**, in the Redfish spec, OEM roles can be added via POST to the
48*f4febd00SPatrick Williams`RoleCollection` in the `AccountService`; `PrivilegesUsed`, `OEMPrivilegesUsed`,
49*f4febd00SPatrick Williamsand properties of `Mappings` are all read-only.
508fd98f13SNan Zhou
518fd98f13SNan ZhouReferences:
52*f4febd00SPatrick Williams
538fd98f13SNan Zhou1. https://redfish.dmtf.org/schemas/DSP0266_1.15.1.html#privilege-model
548fd98f13SNan Zhou2. https://redfish.dmtf.org/schemas/DSP0266_1.15.1.html#redfish-service-operation-to-privilege-mapping
558fd98f13SNan Zhou3. https://redfish.dmtf.org/schemas/DSP0266_1.15.1.html#roles
568fd98f13SNan Zhou4. https://redfish.dmtf.org/registries/v1/Redfish_1.3.0_PrivilegeRegistry.json
578fd98f13SNan Zhou
588fd98f13SNan Zhou### Phosphor-user-manager
598fd98f13SNan Zhou
608fd98f13SNan ZhouPhosphor-user-manager is an OpenBMC daemon that does user management.
618fd98f13SNan Zhou
628fd98f13SNan ZhouIt exposes DBus APIs to dynamically add users, manage users' attributes (e.g.,
638fd98f13SNan Zhougroup, privileges, status, and account policies). It has a hardcoded list of
648fd98f13SNan Zhouuser groups (SSH, IPMI, Redfish, Web) and a hardcoded list of privileges
658fd98f13SNan Zhou("priv-admin", "priv-operator", "priv-user", "priv-noaccess"). These privileges
668fd98f13SNan Zhouare implemented as Linux secondary groups.
678fd98f13SNan Zhou
68*f4febd00SPatrick WilliamsIt also integrates LDAP (supports either ActiveDirectory or OpenLDAP) for remote
69*f4febd00SPatrick Williamsuser management, where BMC acts as a LDAP client and uses nslcd to automatically
70*f4febd00SPatrick Williamsconvert Linux system calls to LDAP queries.
718fd98f13SNan Zhou
728fd98f13SNan ZhouReferences:
73*f4febd00SPatrick Williams
748fd98f13SNan Zhou1. https://github.com/openbmc/docs/blob/master/architecture/user-management.md
758fd98f13SNan Zhou2. https://github.com/openbmc/phosphor-user-manager
768fd98f13SNan Zhou3. https://github.com/openbmc/phosphor-dbus-interfaces/tree/master/yaml/xyz/openbmc_project/User
778fd98f13SNan Zhou4. https://linux.die.net/man/8/nslcd
788fd98f13SNan Zhou5. https://linux.die.net/man/8/nscd
798fd98f13SNan Zhou
808fd98f13SNan Zhou### BMCWeb
818fd98f13SNan Zhou
828fd98f13SNan ZhouBMCWeb is an OpenBMC Daemon which implements the Redfish service (it implements
838fd98f13SNan Zhouother management interfaces as well besides Redfish).
848fd98f13SNan Zhou
858fd98f13SNan ZhouBMCWeb supports various "authentication" options, but under the hood, to verify
868fd98f13SNan Zhouthe user is who they claim they are, there are two main authentication methods:
87*f4febd00SPatrick Williams
888fd98f13SNan Zhou1. PAM based: use Linux-PAM to do username/password style of authentication
898fd98f13SNan Zhou2. TLS based: use the Public Key infrastructure to verify signature of peer's
90*f4febd00SPatrick Williams   certificates; then use identities (in X509 certificates, these are Common
91*f4febd00SPatrick Williams   Name or Subject Alternative Name) as user names.
928fd98f13SNan Zhou
938fd98f13SNan ZhouAfter getting the peer's user name, BMCWeb sends DBus queries to
94*f4febd00SPatrick Williamsphosphor-user-manager to query the user's privileges and uses a hardcoded map to
95*f4febd00SPatrick Williamsconvert the privileges to Redfish roles. The hardcoded map is listed below:
968fd98f13SNan Zhou
978fd98f13SNan Zhou| Phosphor-user-manager privileges (implemented as groups) | BMCWeb Redfish Roles |
98*f4febd00SPatrick Williams| -------------------------------------------------------- | -------------------- |
998fd98f13SNan Zhou| priv-admin                                               | Administrator        |
1008fd98f13SNan Zhou| priv-operator                                            | Operator             |
1018fd98f13SNan Zhou| priv-user                                                | ReadOnly             |
1028fd98f13SNan Zhou| priv-noaccess                                            | NoAccess             |
1038fd98f13SNan Zhou
1048fd98f13SNan ZhouTo map Redfish role to their assigned Redfish privileges, BMCWeb implements the
1058fd98f13SNan Zhoufollowing hardcoded map:
1068fd98f13SNan Zhou
1078fd98f13SNan Zhou| BMCWeb Redfish Roles | Assigned Redfish Privileges                                                            |
108*f4febd00SPatrick Williams| -------------------- | -------------------------------------------------------------------------------------- |
1098fd98f13SNan Zhou| Administrator        | "Login", "ConfigureManager", "ConfigureUsers", "ConfigureSelf", "ConfigureComponents"} |
1108fd98f13SNan Zhou| Operator             | "Login", "ConfigureSelf", "ConfigureComponents"                                        |
1118fd98f13SNan Zhou| ReadOnly             | "Login", "ConfigureSelf"                                                               |
1128fd98f13SNan Zhou| NoAccess             | NA                                                                                     |
1138fd98f13SNan Zhou
1148fd98f13SNan ZhouAt compile time, BMCWeb assigns each operation of each entity a set of required
1158fd98f13SNan ZhouRedfish Privileges. An authorization action is performed when a BMCWeb route
116*f4febd00SPatrick Williamscallback is performed: check if the assigned Redfish Privileges is a superset of
117*f4febd00SPatrick Williamsthe required Redfish Privileges.
1188fd98f13SNan Zhou
119*f4febd00SPatrick WilliamsIn the following section, we refer a BMCWeb route as the handler of an operation
120*f4febd00SPatrick Williamsof an given resource URI, which is what the BMCWEB_ROUTE macro has defined.
1218fd98f13SNan Zhou
1228fd98f13SNan ZhouReferences:
123*f4febd00SPatrick Williams
1248fd98f13SNan Zhou1. https://github.com/openbmc/bmcweb/blob/d9f6c621036162e9071ce3c3a333b4544c6db870/include/authentication.hpp
1258fd98f13SNan Zhou2. https://github.com/openbmc/bmcweb/blob/d9f6c621036162e9071ce3c3a333b4544c6db870/http/http_connection.hpp
1268fd98f13SNan Zhou3. https://github.com/openbmc/bmcweb/blob/d9f6c621036162e9071ce3c3a333b4544c6db870/redfish-core/lib/roles.hpp
1278fd98f13SNan Zhou
1288fd98f13SNan Zhou### Gaps
129*f4febd00SPatrick Williams
1308fd98f13SNan ZhouAs mentioned above, majority of the current Redfish authorization settings are
1318fd98f13SNan Zhouconfigured at compile time including:
1328fd98f13SNan Zhou
1338fd98f13SNan Zhou1. the set of Phosphor-user-manager privileges
1348fd98f13SNan Zhou2. the mapping from Phosphor-user-manager privileges to Redfish roles
1358fd98f13SNan Zhou3. the set of Redfish roles
1368fd98f13SNan Zhou4. the mapping from Redfish roles to Redfish Privileges
1378fd98f13SNan Zhou5. the operation-to-privilege mapping
1388fd98f13SNan Zhou
1391adafbb3SNan ZhouHowever, modern systems have use cases where Redfish roles, Redfish privileges,
140*f4febd00SPatrick Williamsand operation-to-privilege mapping need to change when the system keeps running.
141*f4febd00SPatrick WilliamsE.g., a new micro-service is introduced and needs to talk to existing BMCs in
142*f4febd00SPatrick Williamsthe fleet, we need to propagate a configuration so that this new peer gets a
143*f4febd00SPatrick Williamsproper Redfish role and is authorized to access certain resources without
144*f4febd00SPatrick Williamsrolling out a new BMC firmware.
1458fd98f13SNan Zhou
1468fd98f13SNan ZhouAnother gap is that current Redfish roles and operation-to-privilege mapping
1478fd98f13SNan Zhoulead to a very coarse-grained access control, and doesn't implement the
1488fd98f13SNan Zhouprinciple of least privilege. Though these configurations are defined by DMTF,
1498fd98f13SNan Zhouit is explicitly called out in the standard that implementation implement their
1508fd98f13SNan Zhouown OEM roles and privileges if "the standard privilege is overly broad".
1518fd98f13SNan Zhou
1528fd98f13SNan ZhouFor systems which have requirement where a given user only has access to the
1538fd98f13SNan Zhouresources it needs. For example, a micro-service responsible for remote power
1548fd98f13SNan Zhoucontrol can only send GET to Chassis and ComputerSystems, and POST to
155*f4febd00SPatrick Williamscorresponding ResetActions. With the existing implementation, such micro-service
156*f4febd00SPatrick Williamshas at least ConfigureComponents Redfish privilege, which leads to being able to
157*f4febd00SPatrick Williamspatch an EthernetInterface resource.
1588fd98f13SNan Zhou
1598fd98f13SNan Zhou## Requirements
160*f4febd00SPatrick Williams
1611adafbb3SNan ZhouBMC implements a dynamic Redfish authorization system:
1628fd98f13SNan Zhou
1638fd98f13SNan Zhou1. Clients shall be able to add new OEM Redfish privileges without recompile
1648fd98f13SNan Zhou2. Clients shall be able to add new OEM Redfish roles and assign it with any
1658fd98f13SNan Zhou   existing Redfish privileges without recompile
1668fd98f13SNan Zhou3. Clients shall be able to modify existing operation-to-privilege mappings
1678fd98f13SNan Zhou   without recompile
1688fd98f13SNan Zhou4. Above changes on systems shall be atomic; that is, once changed, all new
1698fd98f13SNan Zhou   queries will use the latest configurations
1708fd98f13SNan Zhou5. BMC shall perform sanity check on above modification; that is
171*f4febd00SPatrick Williams   - It rejects ill formatted modification
172*f4febd00SPatrick Williams   - It rejects modification of non-OEM privileges
173*f4febd00SPatrick Williams   - It rejects deletion of OEM Redfish roles if any user (either local or
1748fd98f13SNan Zhou     remote) maps such roles
175*f4febd00SPatrick Williams   - It rejects deletion of OEM Redfish privileges if any OEM Redfish role is
1768fd98f13SNan Zhou     assigned such privileges
1778fd98f13SNan Zhou6. BMC shall persist all the above modifications and recover from crash
1788fd98f13SNan Zhou7. Existing systems with the static authorization shall work as if this feature
1798fd98f13SNan Zhou   is not introduced, including non-Redfish routes (e.g., KVM websocket)
1808fd98f13SNan Zhou8. Default OEM roles and Redfish privileges must be selectable on a per system
181*f4febd00SPatrick Williams   basis at compile time; default Redfish PrivilegeRegistry must be settable on
182*f4febd00SPatrick Williams   a per system basis at compile time
1838fd98f13SNan Zhou9. The total storage used by this feature shall be limited; this is
184*f4febd00SPatrick Williams   - The total rwfs disk usage increase is less than 100 KB on systems with the
185*f4febd00SPatrick Williams     dynamic authorization feature enabled
186*f4febd00SPatrick Williams   - The runtime memory usage increase is less than 1 MB on systems with the
187*f4febd00SPatrick Williams     dynamic authorization feature enabled
188*f4febd00SPatrick Williams   - The binary size increase of modified daemons is less than 100 KB on all
1898fd98f13SNan Zhou     systems
1908fd98f13SNan Zhou10. BMC implements a complete privilege registry; that is
191*f4febd00SPatrick Williams    - It shall implement all overrides in the Redfish base Privilege registries
1928fd98f13SNan Zhou      at compile time; it shall support configuring overrides at runtime but
1938fd98f13SNan Zhou      implementation may begin with static configuring and reject runtime
1948fd98f13SNan Zhou      modification
195*f4febd00SPatrick Williams    - BMC exposes PrivilegeRegistry which represents the current configuration
1968fd98f13SNan Zhou      and reflects runtime changes
197*f4febd00SPatrick Williams    - Changes to resource entities shall be propagated to the current privilege
1988fd98f13SNan Zhou      registries automatically
1998fd98f13SNan Zhou11. New Redfish resource can be implemented without modifying custom
2008fd98f13SNan Zhou    PrivilegeRegistry
2018fd98f13SNan Zhou12. All the above shall be testable; CI must be capable of finding issues
2028fd98f13SNan Zhou
2038fd98f13SNan Zhou## Proposed Design
2048fd98f13SNan Zhou
2058fd98f13SNan Zhou### Mapping: Users, Redfish Roles, and Redfish Privileges
2068fd98f13SNan Zhou
2078fd98f13SNan ZhouAs mentioned in the background section, existing Redfish roles are stored as
2088fd98f13SNan ZhouLinux secondary groups with prefix "priv" (includes "priv-admin",
2098fd98f13SNan Zhou"priv-operator", and "priv-user"). And a Linux user is in one of these groups
2108fd98f13SNan Zhourepresenting that a user is a specific Redfish role. BMCWeb then uses a
2118fd98f13SNan Zhouhardcoded table to map Redfish role to Redfish privileges.
2128fd98f13SNan Zhou
2138fd98f13SNan ZhouHowever, modeling roles only as static Linux secondary groups doesn't worked
2148fd98f13SNan Zhouwell with OEM Redfish Roles where a Redfish role maps to a dynamic set of OEM
2158fd98f13SNan Zhouprivileges: secondary group can't represent associations.
2168fd98f13SNan Zhou
2178fd98f13SNan ZhouTo solve this, we propose the following solution:
2188fd98f13SNan Zhou
219*f4febd00SPatrick Williams**Store Redfish Roles As Linux Users and Secondary Groups** We propose to store
220*f4febd00SPatrick WilliamsRedfish Roles as both Linux users and secondary groups. Storing as secondary
221*f4febd00SPatrick Williamsgroups is to associate users with Redfish roles. On the other hand, storing as
222*f4febd00SPatrick Williamsusers is to associate Redfish roles with Redfish privileges. See below section
223*f4febd00SPatrick Williamsfor these mappings.
2248fd98f13SNan Zhou
2258fd98f13SNan ZhouUsers for Redfish roles won't be any predefined groups (web, redfish, ipmi). We
2268fd98f13SNan Zhoucan add extra attributes to distinguish them with real local and LDAP users.
2278fd98f13SNan ZhouUsers for Redfish roles won't have SSH permission as well.
2288fd98f13SNan Zhou
2298fd98f13SNan ZhouRedfish roles will have a fixed prefix "openbmc-rfr-". "rfr" refers to Redfish
2308fd98f13SNan Zhourole. OEM redfish roles will get prefix "openbmc-orfr-". "orfr" refers to OEM
2318fd98f13SNan ZhouRedfish role. For example, the base Redfish role "Administrator" will result in
2328fd98f13SNan Zhoua Linux secondary group "openbmc-rfr-administrator" and a local user
2338fd98f13SNan Zhou"openbmc-rfr-administrator". We can also make the vendor name ("openbmc")
2348fd98f13SNan Zhouconfigurable at compile time. Using acronym is to save characters since Linux
2358fd98f13SNan Zhouusername has 31 characters limit.
2368fd98f13SNan Zhou
237*f4febd00SPatrick Williams**Store Redfish Privileges as Secondary Groups** Redfish privileges will be
238*f4febd00SPatrick Williamsstored as Linux secondary groups with a fixed prefix "openbmc-rfp". rfr" refers
239*f4febd00SPatrick Williamsto Redfish privilege. OEM privileges will have fixed prefix "openbmc-orfp".
240*f4febd00SPatrick Williams"orfr" refers to OEM Redfish privilege.
2418fd98f13SNan Zhou
242*f4febd00SPatrick Williams**Username to Redfish Role Mapping** Mapping a username to Redfish role becomes
243*f4febd00SPatrick Williamssearching the group starting with "openbmc-rfr" that the user is in.
2448fd98f13SNan Zhou
245*f4febd00SPatrick Williams**Redfish Role to Redfish Privileges Mapping** Mapping a Redfish Role to Redfish
246*f4febd00SPatrick Williamsprivileges becomes searching all the groups starting with "openbmc-rfp" or
247*f4febd00SPatrick Williams"openbmc-orfp" of the user.
2488fd98f13SNan Zhou
2498fd98f13SNan ZhouA user maps be in multiple linux secondary groups meaning they are assigned
2508fd98f13SNan Zhoucertain privileges; for example, user "PowerService" is in "openbmc-orfr-power"
2518fd98f13SNan Zhougroup meaning its Redfish role is "openbmc-orfr-power"; local user
2528fd98f13SNan Zhou"openbmc-orfr-power" is in secondary groups "openbmc-rfp-configureself" and
2538fd98f13SNan Zhou"openbmc-orfp-power" groups meaning "openbmc-orfr-power" is assigned to Redfish
2548fd98f13SNan Zhouprivileges "ConfigureSelf" and "OemPrivPower".
2558fd98f13SNan Zhou
2568fd98f13SNan ZhouThe following diagram shows how assigned privileges of a power control service
2578fd98f13SNan Zhouwith identity (username in PAM, or CN/SAN in TLS) "power-service" is resolved.
2588fd98f13SNan Zhou
2598fd98f13SNan Zhou```
2608fd98f13SNan Zhou +-----------------+
2618fd98f13SNan Zhou |  power service  |
2628fd98f13SNan Zhou |                 |
2638fd98f13SNan Zhou +--------|--------+
2648fd98f13SNan Zhou          |
2658fd98f13SNan Zhou          |
2668fd98f13SNan Zhou +-----------------+
2678fd98f13SNan Zhou |  authentication |
2688fd98f13SNan Zhou |   (PAM or TLS)  |
2698fd98f13SNan Zhou |      BMCWeb     |
2708fd98f13SNan Zhou +--------|--------+
2718fd98f13SNan Zhou          |
2728fd98f13SNan Zhou          |username:power-service
2738fd98f13SNan Zhou          |
2748fd98f13SNan Zhou +-----------------+                        +-----------------+            +----------------------------+
2758fd98f13SNan Zhou |      BMCWeb     |DBus: privileges        |  phosphor-      |            |     Linux                  |
2768fd98f13SNan Zhou |                 ------------------------>|   user-manager  |            |user: power-service         |
2778fd98f13SNan Zhou |                 |<-----------------------|                 |            |group:                      |
2788fd98f13SNan Zhou |                 | privileges:            |                 <----------->|  openbmc-orfr-power        |
2798fd98f13SNan Zhou |                 |  Login, ConfigureSelf  |                 |            |                            |
2808fd98f13SNan Zhou |                 |  OemPrivPower          |                 |            |user: openbmc-orfr-power    |
2818fd98f13SNan Zhou +-----------------+                        +-----------------+            |group:                      |
2828fd98f13SNan Zhou                                                                           |  openbmc-rfp-configureself |
2838fd98f13SNan Zhou                                                                           |  openbmc-orfp-power        |
2848fd98f13SNan Zhou                                                                           |  openbmc-rfp-login         |
2858fd98f13SNan Zhou                                                                           +----------------------------+
2868fd98f13SNan Zhou```
2878fd98f13SNan Zhou
288*f4febd00SPatrick WilliamsThe above diagram works for LDAP users as well. A remote role or group can map
289*f4febd00SPatrick Williamsto base Redfish roles or OEM Redfish roles via RemoteRoleMapping: an LDAP group
290*f4febd00SPatrick Williamsmaps to a single Redfish role stored as local users.
2918fd98f13SNan Zhou
2928fd98f13SNan ZhouWe propose to extend the existing phosphor-user-manager:
2938fd98f13SNan Zhou
2948fd98f13SNan Zhou1. It returns AllPrivileges dynamically by looking up the current groups
2958fd98f13SNan Zhou2. Phosphor-user-manager provides DBus APIs to query privileges of a given user
2968fd98f13SNan Zhou
297*f4febd00SPatrick WilliamsThe legacy groups (e.g., `priv-user`) still works as before. For example, a user
298*f4febd00SPatrick Williamsin both `priv-user` and `openbmc-orfp-power` will have the following Redfish
299*f4febd00SPatrick Williamsprivileges: `Login`, `ConfigureSelf`, `OemPrivPower`.
3008fd98f13SNan Zhou
3018fd98f13SNan Zhou### Creation/Deletion: Users, Redfish Roles, and Redfish Privileges
3028fd98f13SNan Zhou
3038fd98f13SNan ZhouBase privileges and roles won't be allowed to change at runtime.
3048fd98f13SNan Zhou
3058fd98f13SNan Zhou#### OEM Redfish Privileges
3068fd98f13SNan Zhou
307*f4febd00SPatrick WilliamsPATCH OEMPrivilegesUsed in PrivilegeRegistry creating/deleting OEM privileges to
308*f4febd00SPatrick Williamscreate or delete OEM Privileges at runtime.
3098fd98f13SNan Zhou
3108fd98f13SNan ZhouWe propose to extend the existing phosphor-user-manager:
3118fd98f13SNan Zhou
3128fd98f13SNan Zhou1. Phosphor-user-manager provides DBus APIs to create/delete OEM Redfish
3138fd98f13SNan Zhou   privileges; under the hood, it stores privileges as Linux groups, as today
3148fd98f13SNan Zhou   how base Redfish roles are stored
3158fd98f13SNan Zhou2. Phosphor-user-manager keeps a maximum number of Redfish privileges; we
3168fd98f13SNan Zhou   propose 32 as the first iteration considering fast bit manipulation
3178fd98f13SNan Zhou3. Phosphor-user-manager performs validation:
318*f4febd00SPatrick Williams   - Names of OEM Redfish privileges are unique and valid; e.g., start with
3198fd98f13SNan Zhou     "openbmc-orfp-"
320*f4febd00SPatrick Williams   - Reject deletion of a privilege that's currently in use (assigned to any
3218fd98f13SNan Zhou     Redfish roles that have a user associated with)
3228fd98f13SNan Zhou
3238fd98f13SNan ZhouSystems can also optionally add OEM Privileges at compile time via Yocto's
3248fd98f13SNan ZhouGROUPADD_PARAM in the useradd class.
3258fd98f13SNan Zhou
3268fd98f13SNan Zhou#### OEM Redfish Roles
3278fd98f13SNan Zhou
3288fd98f13SNan ZhouPOST on the RoleCollection in the AccountService to create an OEM role, with
3298fd98f13SNan Zhouassigned Privileges in the AssignedPrivileges and OemPrivileges properties in
3308fd98f13SNan Zhouthe Role resource.
3318fd98f13SNan Zhou
3328fd98f13SNan ZhouDELETE on the specific Role in the RoleCollection to delete an OEM role.
3338fd98f13SNan ZhouPredefined roles are not allowed to be deleted.
3348fd98f13SNan Zhou
3358fd98f13SNan ZhouWe propose to extend the existing phosphor-user-manager:
336*f4febd00SPatrick Williams
3378fd98f13SNan Zhou1. Phosphor-user-manager provides DBus APIs to create Redfish role
3388fd98f13SNan Zhou2. Phosphor-user-manager keeps a maximum number of Redfish roles; we propose 32
3398fd98f13SNan Zhou   as the first iteration considering fast bit manipulation
3408fd98f13SNan Zhou3. Phosphor-user-manager performs validation:
341*f4febd00SPatrick Williams   - Names of OEM Redfish roles are unique and valid; e.g., start with
3428fd98f13SNan Zhou     "openbmc-orfr-"
343*f4febd00SPatrick Williams   - Reject deletion of a RedfishRole that's currently in use (associated with
3448fd98f13SNan Zhou     users)
3458fd98f13SNan Zhou
3468fd98f13SNan Zhou#### Users
3478fd98f13SNan Zhou
3488fd98f13SNan ZhouPOST on the ManagerAccountCollection to create a user, with a RoleId to the
3498fd98f13SNan Zhouassigned Redfish role.
3508fd98f13SNan Zhou
3518fd98f13SNan ZhouDELETE on the specific user in the ManagerAccountCollection to delete a user.
3528fd98f13SNan Zhou
3538fd98f13SNan ZhouNote: modification on ManagerAccountCollection need authorization as well. For
3548fd98f13SNan Zhouexample, a user with only "ConfigureSelf" permission is not allowed to delete
3558fd98f13SNan Zhouother users.
3568fd98f13SNan Zhou
3578fd98f13SNan Zhou#### Typical Workflow
3588fd98f13SNan Zhou
3598fd98f13SNan ZhouIn summary, a typical workflow to create a new local user with an new OEM
360*f4febd00SPatrick WilliamsRedfish role which is assigned a new set of OEM Redfish Privileges is mapped out
361*f4febd00SPatrick Williamsbelow.
3628fd98f13SNan Zhou
3638fd98f13SNan Zhou```
3648fd98f13SNan Zhou         Root User                    BMCWeb                  Phosphor-User-Manager             Linux
3658fd98f13SNan Zhou              |   PATCH PrivilegeRegistry |                              |                        |
3668fd98f13SNan Zhou              |-------------------------->|   DBus: createGroup          |                        |
3678fd98f13SNan Zhou              |   Add OemAddPowerService  |----------------------------->|     groupadd           |
3688fd98f13SNan Zhou  Create      |                           |                              |----------------------->|
3698fd98f13SNan Zhou  OemPrivilege|                           |            Okay              |<-----------------------|
3708fd98f13SNan Zhou              |           Okay            |<-----------------------------|        Okay            |
3718fd98f13SNan Zhou              |<--------------------------|                              |                        |
3728fd98f13SNan Zhou              |                           |                              |                        |
3738fd98f13SNan Zhou              |                           |                              |                        |
3748fd98f13SNan Zhou              | POST RoleCollection       |                              |                        |
3758fd98f13SNan Zhou              |-------------------------->|  DBus: createUser            |                        |
3768fd98f13SNan Zhou              |                           |----------------------------->|  useradd + groupadd    |
3778fd98f13SNan Zhou  Create      |                           |                              |----------------------->|
3788fd98f13SNan Zhou  OemRole     |                           |            Okay              |<-----------------------|
3798fd98f13SNan Zhou              |          Okay             |<-----------------------------|         Okay           |
3808fd98f13SNan Zhou              |<--------------------------|                              |                        |
3818fd98f13SNan Zhou              |                           |                              |                        |
3828fd98f13SNan Zhou              |                           |                              |                        |
3838fd98f13SNan Zhou              |POST                       |                              |                        |
3848fd98f13SNan Zhou              | ManagerAccountCollection  |                              |                        |
3858fd98f13SNan Zhou              |-------------------------->| DBus: createUser             |                        |
3868fd98f13SNan Zhou              |                           |----------------------------->|       useradd          |
3878fd98f13SNan Zhou  Create      |                           |                              |----------------------->|
3888fd98f13SNan Zhou  User        |                           |                              |<-----------------------|
3898fd98f13SNan Zhou              |                           |<-----------------------------|        Okay            |
3908fd98f13SNan Zhou              |<--------------------------|            Okay              |                        |
3918fd98f13SNan Zhou              |           Okay            |                              |                        |
3928fd98f13SNan Zhou  Time        |                           |                              |                        |
3938fd98f13SNan Zhou              v                           v                              v                        v
3948fd98f13SNan Zhou```
3958fd98f13SNan Zhou
3968fd98f13SNan Zhou### Non-Redfish Routes or OEM Resources
397*f4febd00SPatrick Williams
3988fd98f13SNan ZhouWe still keep the current `privileges` C++ API to add explicit Redfish
3998fd98f13SNan Zhouprivileges for non-redfish routes via `BMCWEB_ROUTE`.
4008fd98f13SNan Zhou
4018fd98f13SNan Zhou### Redfish Routes
402*f4febd00SPatrick Williams
4038fd98f13SNan ZhouWe propose to create a new macro `REDFISH_ROUTE` so existing `REDFISH_ROUTE`
4048fd98f13SNan Zhoustay unchanged for non-redfish routes.
4058fd98f13SNan Zhou
4068fd98f13SNan ZhouFor each `REDFISH_ROUTE`, instead of taking a privileges array (or reference to
4078fd98f13SNan Zhoua privileges array), this design proposes to create the following extra C++
4088fd98f13SNan ZhouAPIs:
4098fd98f13SNan Zhou
4108fd98f13SNan Zhou1. `entity`: it takes a string representing the Resource name (the same
4118fd98f13SNan Zhou   definition as it in the PrivilegeRegistry); for example,
4128fd98f13SNan Zhou   "/redfish/v1/Managers/${ManagerId}/EthernetInterfaces/" will provide a string
4138fd98f13SNan Zhou   "EthernetInterfaceCollection" as the entity
4148fd98f13SNan Zhou2. `subordinateTo`: it takes an array of string representing what resource this
415*f4febd00SPatrick Williams   router is subordinate to (the same definition as it in the
416*f4febd00SPatrick Williams   PrivilegeRegistry); for example, a route with URL
4178fd98f13SNan Zhou   "/redfish/v1/Managers/${ManagerId}/EthernetInterfaces/" will provide an array
418*f4febd00SPatrick Williams   of {"Manager", "EthernetInterfaceCollection"} as the value of
419*f4febd00SPatrick Williams   `subordinateTo`.
4208fd98f13SNan Zhou
4218fd98f13SNan ZhouAny Redfish route must provide these attributes. Non Redfish route shall not
4228fd98f13SNan Zhouprovide them, instead, they specify `privileges` directly. The values of these
4238fd98f13SNan Zhouattributes can be generated from the schema at compile time. To guarantee this
4248fd98f13SNan Zhouin C++ code, we can make them required parameters in constructors.
4258fd98f13SNan Zhou
4268fd98f13SNan ZhouSee below for how we propose to get required Redfish privileges for a given
427*f4febd00SPatrick Williamsmethod on a given resource by using the proposed `entity` & `subordinateTo`, the
428*f4febd00SPatrick Williamsexisting `methods`, and the URL from the request.
4298fd98f13SNan Zhou
4308fd98f13SNan ZhouSee the alternatives section for how we can get rid of setting these attributes
4318fd98f13SNan Zhouat manually.
4328fd98f13SNan Zhou
4338fd98f13SNan Zhou### Operation-to-Privilege Mapping Data Structure in Memory
434*f4febd00SPatrick Williams
4358fd98f13SNan ZhouBMCWeb keeps a JSON like data structure in memory to represent the whole
4368fd98f13SNan ZhouOperation-to-Privilege Mapping. For a given route with known entity name, HTTP
4378fd98f13SNan Zhoumethod, and resource URL, the required set of privileges can be retrieved
4388fd98f13SNan Zhouefficiently.
4398fd98f13SNan Zhou
440*f4febd00SPatrick WilliamsThe operation to check if a user is authorized to perform a Redfish operation is
441*f4febd00SPatrick Williamsstill the existing bit-wise `isSupersetOf` between the required privileges of a
442*f4febd00SPatrick Williamsgiven operation on a given resource and the assigned privileges of a role.
4438fd98f13SNan Zhou
4448fd98f13SNan Zhou### Generate Operation-to-Privilege Mapping Data Structure at Compile Time
445*f4febd00SPatrick Williams
4468fd98f13SNan ZhouBMCWeb has requirements that it doesn't prefer to load a large file at service
4478fd98f13SNan Zhoustart time since it slows down the service, and whatever services rely on it.
4488fd98f13SNan Zhou
4498fd98f13SNan ZhouThus, we propose to generate the data structure at compile time, it takes a
450*f4febd00SPatrick WilliamsPrivilegeRegistry JSON, and generate necessary headers and sources files to hold
451*f4febd00SPatrick Williamsa variable that represent the whole Operation-to-Privilege Mapping. The input
452*f4febd00SPatrick WilliamsJSON can change across systems.
4538fd98f13SNan Zhou
4548fd98f13SNan ZhouThis can be implemented as a customized Meson generator.
4558fd98f13SNan Zhou
4568fd98f13SNan ZhouWe will delete the current static privileges header, but the generated header
457*f4febd00SPatrick Williamswill increase the binary size. We shall limit the increase to <= 100KB. The size
458*f4febd00SPatrick Williamsof `Redfish_1.3.0_PrivilegeRegistry.json` is about 275 KB; the minified version
459*f4febd00SPatrick Williamsof it (no whitespace) is about 62 KB. When parsing this JSON and converting it
460*f4febd00SPatrick Williamsto C++ codes, we shall not increase the binary size a lot otherwise we can just
461*f4febd00SPatrick Williamsstore the whole registry as a Nlohmann JSON object.
4628fd98f13SNan Zhou
4638fd98f13SNan Zhou### Operation-to-Privilege Mapping Overrides
4648fd98f13SNan Zhou
465*f4febd00SPatrick WilliamsIn routing codes, we can parse the Operation-to-Privilege Mapping Data Structure
466*f4febd00SPatrick Williamsand look for SubordinateOverrides and ResourceURIOverrides, combine them with
467*f4febd00SPatrick Williamsthe attributes from route and request, and perform authorization.
4688fd98f13SNan Zhou
4698fd98f13SNan ZhouMost part of the Authorization codes run before resource handlers. However,
470*f4febd00SPatrick WilliamsPropertyOverrides for read operation can only be executed when response is ready
471*f4febd00SPatrick Williamssince we need to inspect the response attributes. PropertyOverrides for write
472*f4febd00SPatrick Williamsoperator shall still run before the handler codes: the authorization code
4738fd98f13SNan Zhouinspect the request payload and corresponding properties, and look them up in
4748fd98f13SNan Zhouthe Operation-to-Privilege Mapping in-memory Data Structure.
4758fd98f13SNan Zhou
4768fd98f13SNan ZhouA example execution flow for a read operation is mapped out below.
4778fd98f13SNan Zhou
4788fd98f13SNan Zhou```
4798fd98f13SNan Zhou    +---------------+
4808fd98f13SNan Zhou    |   BMCWeb      | Get
4818fd98f13SNan Zhou    |    routing    | /redfish/v1/Managers/${ManagerId}/EthernetInterfaces/
4828fd98f13SNan Zhou    +-------|-------+
4838fd98f13SNan Zhou            | Known information:
4848fd98f13SNan Zhou            |  Request.URL
4858fd98f13SNan Zhou            |  Request.method
4868fd98f13SNan Zhou            |  Route.entity
4878fd98f13SNan Zhou            |  Route.subordinateTo
4888fd98f13SNan Zhou            |
4898fd98f13SNan Zhou+-----------------------+       +--------------------------------------------------------------+
4908fd98f13SNan Zhou| Any                   |       |Operation-to-Privilege Mapping in-memory Data Structure       |
4918fd98f13SNan Zhou| ResourceURIOverrides? <------>|                                                              |
4928fd98f13SNan Zhou|                       |       |{                                                             |
4938fd98f13SNan Zhou+-----------|-----------+       |   "Entity": "EthernetInterface",                             |
4948fd98f13SNan Zhou            |Updated            |   "OperationMap": {                                          |
4958fd98f13SNan Zhou            |RequiredPrivileges |      "Get": [{                                               |
4968fd98f13SNan Zhou+-----------------------+       |         "Privilege": ["ConfigureComponents"]                 |
4978fd98f13SNan Zhou| Any                   |       |      }]                                                      |
4988fd98f13SNan Zhou| SubordinateOverrides? |<----->|   },                                                         |
4998fd98f13SNan Zhou|                       |       |   "SubordinateOverrides": [{                                 |
5008fd98f13SNan Zhou+-----------------------+       |      "Targets": ["Manager", "EthernetInterfaceCollection"],  |
5018fd98f13SNan Zhou            |Updated            |      "OperationMap": {                                       |
5028fd98f13SNan Zhou            |RequiredPrivileges |         "Get": [{                                            |
5038fd98f13SNan Zhou            v                   |            "Privilege": ["ConfigureManager"]                 |
5048fd98f13SNan Zhou+-----------------------+       |         }]                                                   |
5058fd98f13SNan Zhou| Authorization         |       |      }                                                       |
5068fd98f13SNan Zhou+-----------|-----------+       |   }]                                                         |
5078fd98f13SNan Zhou            |Okay               |}                                                             |
5088fd98f13SNan Zhou            |Got Response       |                                                              |
5098fd98f13SNan Zhou            |                   +--------------------------------------------------------------+
5108fd98f13SNan Zhou+-----------------------+                       ^
5118fd98f13SNan Zhou| Any                   |                       |
5128fd98f13SNan Zhou| PropertyOverrides?    |<----------------------+
5138fd98f13SNan Zhou+-----------|-----------+
5148fd98f13SNan Zhou            |
5158fd98f13SNan Zhou            |
5168fd98f13SNan Zhou            v
5178fd98f13SNan Zhou        Final Response
5188fd98f13SNan Zhou```
5198fd98f13SNan Zhou
5208fd98f13SNan ZhouThe implementation may start with implementing just the overrides specified in
5218fd98f13SNan ZhouDMTF's base PrivilegeRegistry at compile time and reject any PATCH on overrides
5228fd98f13SNan Zhouproperties.
5238fd98f13SNan Zhou
5248fd98f13SNan Zhou### PrivilegeRegistry Resource
5258fd98f13SNan Zhou
5268fd98f13SNan ZhouBMCWeb will implement PrivilegeRegistry in a new route. The route will reflect
5278fd98f13SNan Zhouthe current PrivilegeRegistry in used including dynamic changes.
5288fd98f13SNan Zhou
5298fd98f13SNan ZhouWith the proposed Dynamic Operation-to-Privilege Mapping Data Structure, and
5308fd98f13SNan ZhouDBus APIs that phosphor-user-manager provides, the implementation is trivial:
5318fd98f13SNan Zhouconvert the JSON data structure into a JSON response.
5328fd98f13SNan Zhou
5338fd98f13SNan Zhou### PATCH on PrivilegeRegistry
5348fd98f13SNan Zhou
5358fd98f13SNan ZhouThough the Redfish spec declares PrivilegeRegistry to be read-only, this design
5368fd98f13SNan Zhoustill proposes implementing PATCH on PrivilegeRegistry: users can PATCH any
5378fd98f13SNan Zhouattributes directly, e.g., patch the POST privilege array of OperationMap of
5388fd98f13SNan ZhouEntity EthernetInterface so that users with "OemEthernetManager" can also send
5398fd98f13SNan ZhouGET to EthernetInterface.
5408fd98f13SNan Zhou
5418fd98f13SNan Zhou```
5428fd98f13SNan Zhou{
5438fd98f13SNan Zhou    Entity": "EthernetInterface",
5448fd98f13SNan Zhou    "OperationMap": {
5458fd98f13SNan Zhou        "GET": [
5468fd98f13SNan Zhou            {
5478fd98f13SNan Zhou                "Privilege": [
5488fd98f13SNan Zhou                    "Login"
5498fd98f13SNan Zhou                ]
5508fd98f13SNan Zhou            },
5518fd98f13SNan Zhou            {
5528fd98f13SNan Zhou                "Privilege": [
5538fd98f13SNan Zhou                    "OemEthernetManager"
5548fd98f13SNan Zhou                ]
5558fd98f13SNan Zhou            }
5568fd98f13SNan Zhou        ]
5578fd98f13SNan Zhou    }
5588fd98f13SNan Zhou}
5598fd98f13SNan Zhou```
5608fd98f13SNan Zhou
5618fd98f13SNan ZhouThe implementation might reject modification on certain attributes when
5628fd98f13SNan Zhoucorresponding implementation is not ready. E.g., it rejects modifying
5638fd98f13SNan ZhouSubordinateOverrides when the service doesn't have SubordinateOverrides
5648fd98f13SNan Zhouimplemented.
5658fd98f13SNan Zhou
5668fd98f13SNan ZhouChanges against the base PrivilegeRegistry will be rejected, e.g., deleting
5678fd98f13SNan ZhouConfigureSelf from a OperationMap. This design is for OEMPrivileges and
5688fd98f13SNan ZhouOEMRoles.
5698fd98f13SNan Zhou
5708fd98f13SNan Zhou### Persistent Data
5718fd98f13SNan Zhou
5728fd98f13SNan ZhouOEM Redfish roles, Redfish privileges, and users are persisted by Linux. With a
573*f4febd00SPatrick Williamsmaximum number of roles and privileges being set, the total persistent data will
574*f4febd00SPatrick Williamsbe very small (around several KB).
5758fd98f13SNan Zhou
5768fd98f13SNan ZhouTo minimize size of persistent data, we propose that BMCWeb only stores the
5778fd98f13SNan Zhouserial of PATCH requests on the PrivilegeRegistry. This data can be stored in
5788fd98f13SNan Zhouthe existing `bmcweb_persistent_data.json`. When restart from crash or reset,
5798fd98f13SNan ZhouBMCWeb will be able to execute the serial of PATCH requests to recover the
5808fd98f13SNan ZhouPrivilegeRegistry. A change on existing `bmcweb_persistent_data.json` is that
5818fd98f13SNan Zhounow BMCWeb will write changes to disk (commit) before it returns okay to
5828fd98f13SNan Zhouclients' PATCH on PrivilegeRegistry. Given that operations on PrivilegeRegistry
5838fd98f13SNan Zhouis much less often than other management and monitoring resources, writing a
5848fd98f13SNan Zhousmall piece of data to disk is acceptable.
5858fd98f13SNan Zhou
5868fd98f13SNan ZhouWe can set a maximum number of PATCH requests that BMCWeb allows to limit the
5878fd98f13SNan Zhoudisk usage. Most upstream systems also have several MB of read-write partition
5888fd98f13SNan Zhouconfigured. For example, `romulus` as of the design was written, 4194304 bytes
5898fd98f13SNan Zhoufor rwfs. We propose to start with allowing 1000 requests.
5908fd98f13SNan Zhou
5918fd98f13SNan ZhouSystems without enabling dynamic authorization feature won't have any new
5928fd98f13SNan Zhoupersistent data added.
5938fd98f13SNan Zhou
5948fd98f13SNan Zhou## Alternatives Considered
5958fd98f13SNan Zhou
5968fd98f13SNan Zhou### Infer Entity and SubordinateTo from URL
597*f4febd00SPatrick Williams
5988fd98f13SNan ZhouWe can infer the entity from the URL by building a Trie like data structure.
599*f4febd00SPatrick WilliamsHowever, it's not a big deal to hardcode an entity for a route, since entity and
600*f4febd00SPatrick WilliamsSubordinateTo never change at runtime.
6018fd98f13SNan Zhou
6028fd98f13SNan Zhou## Impacts
603*f4febd00SPatrick Williams
6048fd98f13SNan Zhou1. New DBus interfaces on phosphor-user-manager
6058fd98f13SNan Zhou2. New persistent data managed by BMCWeb will be added on BMCs
6068fd98f13SNan Zhou3. Binary size will increase on BMCWeb
6078fd98f13SNan Zhou4. Existing systems with the static authorization shall work as if this feature
6088fd98f13SNan Zhou   is not introduced
6098fd98f13SNan Zhou
6108fd98f13SNan Zhou## Organizational
611*f4febd00SPatrick Williams
612*f4febd00SPatrick WilliamsNo new repository is required. Phosphor-user-manager and BMCWeb will be modified
613*f4febd00SPatrick Williamsto implement the design.
6148fd98f13SNan Zhou
6158fd98f13SNan Zhou## Testing
616*f4febd00SPatrick Williams
617*f4febd00SPatrick WilliamsExisting tests shall still pass as if this feature is not introduced. New Robot
618*f4febd00SPatrick WilliamsFramework test can be added to test runtime modification of PrivilegeRegistry.
6198fd98f13SNan Zhou
6208fd98f13SNan ZhouTest cases should include:
6218fd98f13SNan Zhou
6228fd98f13SNan Zhou1. verify base Redfish roles, privileges, and base operation-to-privilege
6238fd98f13SNan Zhou   respect the Redfish spec when no runtime modification is made
6248fd98f13SNan Zhou2. verify Redfish OemPrivilege can be added via PATCH to PrivilegeRegistry and
6258fd98f13SNan Zhou   reflected in the PrivilegeRegistry resource
626*f4febd00SPatrick Williams3. verify Redfish OemRole can be added via POST to ManagerAccountCollection with
627*f4febd00SPatrick Williams   assigned OemPrivilege and reflected in the ManagerAccountCollection
628*f4febd00SPatrick Williams4. verify operation-to-privilege can be modified via PATCH on PrivilegeRegistry;
629*f4febd00SPatrick Williams   mapping of an action on a resource can be added with the above OemPrivilege,
630*f4febd00SPatrick Williams   and finally the user of that OemRole now can access the resource
6318fd98f13SNan Zhou5. verify the 3 dynamic overriding is working as expected; e.g., a new override
6328fd98f13SNan Zhou   can be added to PrivilegeRegistry and should be reflected in new requests
633