-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from ngageoint/auth-sysinfo
Redact sensitive system information for non-admin users
- Loading branch information
Showing
13 changed files
with
669 additions
and
324 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
import { SystemInfo } from '../../entities/systemInfo/entities.systemInfo' | ||
import { InfrastructureError } from '../app.api.errors' | ||
import { AppRequest, AppResponse } from '../app.api.global' | ||
import { UserWithRole } from '../../permissions/permissions.role-based.base' | ||
import { InfrastructureError, PermissionDeniedError } from '../app.api.errors' | ||
import { AppRequest, AppRequestContext, AppResponse } from '../app.api.global' | ||
|
||
|
||
export type ExoPrivilegedSystemInfo = SystemInfo | ||
export type ExoRedactedSystemInfo = Omit<SystemInfo, 'environment'> | ||
export type ExoSystemInfo = ExoPrivilegedSystemInfo | ExoRedactedSystemInfo | ||
|
||
export interface ReadSystemInfoRequest extends AppRequest {} | ||
export interface ReadSystemInfoRequest extends AppRequest { | ||
context: AppRequestContext<UserWithRole>; | ||
} | ||
export interface ReadSystemInfoResponse extends AppResponse<ExoSystemInfo, InfrastructureError> {} | ||
|
||
export interface ReadSystemInfo { | ||
(req: ReadSystemInfoRequest): Promise<ReadSystemInfoResponse> | ||
} | ||
|
||
export interface SystemInfoAppLayer { | ||
readSystemInfo: ReadSystemInfo | ||
readSystemInfo: ReadSystemInfo; | ||
permissionsService: SystemInfoPermissionService; | ||
} | ||
|
||
export interface SystemInfoPermissionService { | ||
ensureReadSystemInfoPermission(context: AppRequestContext<UserWithRole>): Promise<null | PermissionDeniedError>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
service/src/migrations/030-add-read-system-info-permissions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const mongoose = require('mongoose'); | ||
const RoleModel = mongoose.model('Role'); | ||
|
||
exports.id = 'add-read-system-info-permission'; | ||
|
||
exports.up = function(done) { | ||
this.log('adding READ_SYSTEM_INFO permission to ADMIN_ROLE ...'); | ||
|
||
// Use $addToSet to ensure the permission is only added if it doesn't exist | ||
RoleModel.updateOne( | ||
{ name: 'ADMIN_ROLE' }, | ||
{ $addToSet: { permissions: 'READ_SYSTEM_INFO' } }, | ||
function(err) { | ||
done(err); | ||
} | ||
); | ||
}; | ||
|
||
exports.down = function(done) { | ||
this.log('removing READ_SYSTEM_INFO permission from ADMIN_ROLE ...'); | ||
|
||
RoleModel.updateOne( | ||
{ name: 'ADMIN_ROLE' }, | ||
{ $pull: { permissions: 'READ_SYSTEM_INFO' } }, | ||
function(err) { | ||
done(err); | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
permissionDenied, | ||
PermissionDeniedError | ||
} from '../app.api/app.api.errors'; | ||
import { AppRequestContext } from '../app.api/app.api.global'; | ||
import { SystemInfoPermissionService } from '../app.api/systemInfo/app.api.systemInfo'; | ||
import { SystemInfoPermission } from '../entities/authorization/entities.permissions'; | ||
import { | ||
UserWithRole, | ||
ensureContextUserHasPermission | ||
} from './permissions.role-based.base'; | ||
|
||
export class RoleBasedSystemInfoPermissionService implements SystemInfoPermissionService { | ||
async ensureReadSystemInfoPermission(ctx: AppRequestContext<UserWithRole>): Promise<null | PermissionDeniedError> { | ||
return ensureContextUserHasPermission( | ||
ctx, | ||
SystemInfoPermission.READ_SYSTEM_INFO | ||
); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.