Skip to content

Commit

Permalink
feat(xo-server/rest-api): limit patches listing and RPU (#6864)
Browse files Browse the repository at this point in the history
Same restriction as in the UI.
  • Loading branch information
julien-f authored May 31, 2023
1 parent 18bd2c6 commit 83c5c97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/xo-server/src/xo-mixins/authorization.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const AUTHORIZATIONS = {
EXPORT: {
XVA: STARTER, // @todo handleExport in xen-orchestra/packages/xo-server/src/api/vm.mjs
},
LIST_MISSING_PATCHES: STARTER,
ROLLING_POOL_UPDATE: ENTERPRISE,
}

export default class Authorization {
Expand Down
16 changes: 13 additions & 3 deletions packages/xo-server/src/xo-mixins/rest-api.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { asyncEach } from '@vates/async-each'
import { every } from '@vates/predicates'
import { ifDef } from '@xen-orchestra/defined'
import { invalidCredentials, noSuchObject } from 'xo-common/api-errors.js'
import { featureUnauthorized, invalidCredentials, noSuchObject } from 'xo-common/api-errors.js'
import { pipeline } from 'node:stream/promises'
import { json, Router } from 'express'
import path from 'node:path'
Expand Down Expand Up @@ -89,7 +89,9 @@ function wrap(middleware, handleNoSuchObject = false) {
try {
await middleware.apply(this, arguments)
} catch (error) {
if (handleNoSuchObject && noSuchObject.is(error)) {
if (featureUnauthorized.is(error)) {
res.sendStatus(403)
} else if (handleNoSuchObject && noSuchObject.is(error)) {
res.sendStatus(404)
} else {
next(error)
Expand Down Expand Up @@ -156,6 +158,8 @@ export default class RestApi {
__proto__: null,

async missing_patches(req, res) {
await app.checkFeatureAuthorization('LIST_MISSING_PATCHES')

const host = req.xapiObject
res.json(await host.$xapi.listMissingPatches(host))
},
Expand All @@ -165,6 +169,8 @@ export default class RestApi {
__proto__: null,

async missing_patches(req, res) {
await app.checkFeatureAuthorization('LIST_MISSING_PATCHES')

const xapi = req.xapiObject.$xapi
const missingPatches = new Map()
await asyncEach(Object.values(xapi.objects.indexes.type.host ?? {}), async host => {
Expand All @@ -184,7 +190,11 @@ export default class RestApi {
collections.pools.actions = {
__proto__: null,

rolling_update: ({ xoObject }) => app.rollingPoolUpdate(xoObject).then(noop),
rolling_update: async ({ xoObject }) => {
await app.checkFeatureAuthorization('ROLLING_POOL_UPDATE')

await app.rollingPoolUpdate(xoObject)
},
}
collections.vms.actions = {
__proto__: null,
Expand Down

0 comments on commit 83c5c97

Please sign in to comment.