Skip to content
Merged
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,42 @@ The default local port is `8081`, configurable with `PORT`. Swagger UI is availa
to the database. API routes use the `/api/` prefix. The example `TEST_PORT=3001` gives the
integration suite a separate listener port. The full Docker setup uses port `3000`.

### Root demo accounts

Running `npm run populate:dev` resets the local development database and creates these active accounts:

| Organization | Ordinary user | Administrator |
| --- | --- | --- |
| `top_root_1` | `top_root_1_user@demo.test` | `top_root_1_admin@demo.test` |
| `root_1_4` | `root_1_4_user@demo.test` | `root_1_4_admin@demo.test` |

All four accounts use the existing `LOCAL_KEY` API secret configured for local population. The population command prints this key. Administrators belong to both their organization's `users` and `admins` lists; ordinary users belong only to `users`.

The demo hierarchy includes `top_root_1` → `root_1_4` → `window_1`. Both account types can read descendant organizations and users. With the local server running, replace `YOUR_LOCAL_KEY` with the printed secret to try an expanded organization read:

```sh
curl 'http://localhost:8081/api/registry/org/window_1?expand=users' \
-H 'CVE-API-ORG: top_root_1' \
-H 'CVE-API-USER: top_root_1_user@demo.test' \
-H 'CVE-API-KEY: YOUR_LOCAL_KEY'
```

Use the organization and username from either row above to try these requests:

| Request | Expected result |
| --- | --- |
| `GET /api/registry/org` | The flat list and its pagination totals include the requesting Root and all its direct and indirect descendants. |
| `GET /api/registry/org-hierarchy` | The requesting Root's subtree, with its ancestor path for context. |
| `GET /api/registry/org/window_1` | The descendant organization's details. |
| `GET /api/registry/org/window_1?expand=users` | The descendant organization with expanded user metadata. |
| `GET /api/registry/org/window_1/users` | Users belonging to `window_1`. |
| `GET /api/registry/org/window_1/user/ashleyruiz@window_1.com` | The specified descendant user. |
| `GET /api/registry/org/top_root_2` | `403`: outside both Roots' oversight. |

The `top_root_1` accounts can also read `root_1_4` and its users. The `root_1_4` accounts receive `403` when reading ancestor organization `top_root_1` or sibling Root `root_1_3`. Organization lists exclude those records as well. Secretariat continues to receive the complete organization list.

Both demo administrators can grant or revoke `ADMIN` for users in `window_1`. Send `POST /api/registry/org/window_1/user/{username}/grant-role` or `POST /api/registry/org/window_1/user/{username}/revoke-role` with the JSON body `{"role":"ADMIN"}`. This permission covers the administrator's own Root and all its direct and indirect descendants. Attempting to revoke one's own `ADMIN` role returns `403`.

### API Documentation

Use the Swagger documentation for the instance you are calling:
Expand Down
54 changes: 27 additions & 27 deletions api-docs/openapi.json

Large diffs are not rendered by default.

14 changes: 12 additions & 2 deletions datadump/pre-population/root-orgs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"name": "Top Level Root 1",
"short_name": "top_root_1",
"is_top_level_root": true,
"oversees": ["root_1_1", "root_1_2", "root_1_3", "root_1_4"]
"oversees": ["root_1_1", "root_1_2", "root_1_3", "root_1_4"],
"users": [
"20000000-0000-4000-8000-000000000062",
"20000000-0000-4000-8000-000000000063"
],
"admins": ["20000000-0000-4000-8000-000000000063"]
},
{
"authority": { "active_roles": ["ROOT"] },
Expand Down Expand Up @@ -53,7 +58,12 @@
"name": "Root 1.4",
"short_name": "root_1_4",
"is_top_level_root": false,
"oversees": []
"oversees": [],
"users": [
"20000000-0000-4000-8000-000000000064",
"20000000-0000-4000-8000-000000000065"
],
"admins": ["20000000-0000-4000-8000-000000000065"]
},
{
"authority": { "active_roles": ["ROOT"] },
Expand Down
44 changes: 44 additions & 0 deletions datadump/pre-population/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,5 +791,49 @@
"status": "active",
"created": "2021-05-11T15:07:20.674347Z",
"last_updated": "2021-05-11T15:07:20.674347Z"
},
{
"UUID": "20000000-0000-4000-8000-000000000062",
"username": "top_root_1_user@demo.test",
"name": {
"first": "Top Root 1",
"last": "User"
},
"status": "active",
"created": "2021-05-11T15:07:20.674347Z",
"last_updated": "2021-05-11T15:07:20.674347Z"
},
{
"UUID": "20000000-0000-4000-8000-000000000063",
"username": "top_root_1_admin@demo.test",
"name": {
"first": "Top Root 1",
"last": "Administrator"
},
"status": "active",
"created": "2021-05-11T15:07:20.674347Z",
"last_updated": "2021-05-11T15:07:20.674347Z"
},
{
"UUID": "20000000-0000-4000-8000-000000000064",
"username": "root_1_4_user@demo.test",
"name": {
"first": "Root 1.4",
"last": "User"
},
"status": "active",
"created": "2021-05-11T15:07:20.674347Z",
"last_updated": "2021-05-11T15:07:20.674347Z"
},
{
"UUID": "20000000-0000-4000-8000-000000000065",
"username": "root_1_4_admin@demo.test",
"name": {
"first": "Root 1.4",
"last": "Administrator"
},
"status": "active",
"created": "2021-05-11T15:07:20.674347Z",
"last_updated": "2021-05-11T15:07:20.674347Z"
}
]
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cve-services",
"author": "Automation Working Group",
"version": "2.9.4",
"version": "2.10.0",
"license": "(CC0)",
"devDependencies": {
"@faker-js/faker": "^10.5.0",
Expand Down
2 changes: 1 addition & 1 deletion schemas/registry-user/update-registry-user-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": "string"
},
"org_short_name": {
"description": "Moves the user to another organization and removes ADMIN in both the source and destination. Promotion requires a separate authorized request after the move.",
"description": "Moves the user to another organization and removes ADMIN in both the source and destination. Allowed for Secretariat or a Root ADMIN when both organizations are its own organization or descendants. Root move permission alone requires username, status, and all existing name fields to remain unchanged. Promotion requires a separate authorized request after the move.",
"type": "string",
"minLength": 2,
"maxLength": 32
Expand Down
27 changes: 11 additions & 16 deletions src/controller/org.controller/org.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,10 +715,11 @@ async function resetSecret (req, res, next) {
const requesterUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, objectFormat)
const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, objectFormat)

if (!isRequesterSecretariat) {
const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, { session }, objectFormat)
if (!requesterSameOrg) {
logger.info({ uuid: req.ctx.uuid, message: 'The api secret can only be reset by the Secretariat, an Org admin or if the requester is the user.' })
const requesterSameOrg = !isRequesterSecretariat && await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, { session }, objectFormat)
if (!isRequesterSecretariat && !requesterSameOrg) {
const overseesOrg = req.useRegistry && await authContext.isRequesterRootAdminOfOrgs(req, userRepo, orgRepo, [targetOrg], { session })
if (!overseesOrg) {
logger.info({ uuid: req.ctx.uuid, message: 'API secret reset denied for the target organization.' })
await session.abortTransaction()
return res.status(403).json(error.notSameOrgOrSecretariat())
}
Expand All @@ -732,18 +733,12 @@ async function resetSecret (req, res, next) {
return res.status(404).json(error.userDne(targetUsername))
}

if (!isRequesterSecretariat) {
// If they are in the same organization, they must be the target user themselves OR an admin of the target org.
// 1. WE are not the same user
if (requesterUserUUID !== targetUserUUID) {
// Check to see if we are the admin of the target organization
const isAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, { session }, objectFormat)

if (!isAdminOfTargetOrg) {
logger.info({ uuid: req.ctx.uuid, message: 'The api secret can only be reset by the Secretariat, an Org admin or if the requester is the user.' })
await session.abortTransaction()
return res.status(403).json(error.notSameUserOrSecretariat())
}
if (requesterSameOrg && requesterUserUUID !== targetUserUUID) {
const isAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, { session }, objectFormat)
if (!isAdminOfTargetOrg) {
logger.info({ uuid: req.ctx.uuid, message: 'The api secret can only be reset by the Secretariat, an Org admin or if the requester is the user.' })
await session.abortTransaction()
return res.status(403).json(error.notSameUserOrSecretariat())
}
}

Expand Down
Loading
Loading