mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 09:45:36 +08:00
feat(security): add read-only scopes for remaining resources
This commit is contained in:
1 parent
be8721204b
commit
866c7f4b98
12 files changed
+175
-15
No files matched your search
+19
-1
@@ -24,7 +24,25 @@ export interface AppToken {
|
||||
expiration: number;
|
||||
}
|
||||
|
||||
export type AppScope = 'envs' | 'envs:read' | 'crons' | 'configs' | 'configs:read' | 'scripts' | 'scripts:read' | 'logs' | 'system' | 'dashboard';
|
||||
export type AppScope =
|
||||
| 'crons'
|
||||
| 'crons:read'
|
||||
| 'subscriptions'
|
||||
| 'subscriptions:read'
|
||||
| 'envs'
|
||||
| 'envs:read'
|
||||
| 'configs'
|
||||
| 'configs:read'
|
||||
| 'scripts'
|
||||
| 'scripts:read'
|
||||
| 'logs'
|
||||
| 'logs:read'
|
||||
| 'dependencies'
|
||||
| 'dependencies:read'
|
||||
| 'dashboard'
|
||||
| 'dashboard:read'
|
||||
| 'system'
|
||||
| 'apps';
|
||||
|
||||
export interface AppInstance extends Model<App, App>, App {}
|
||||
export const AppModel = sequelize.define<AppInstance>('App', {
|
||||
|
||||
+21
-9
@@ -113,13 +113,25 @@ export default ({ app }: { app: Application }) => {
|
||||
const key = keyMatch && keyMatch[1];
|
||||
|
||||
const isReadRequest =
|
||||
['GET', 'HEAD'].includes(req.method) ||
|
||||
(key === 'scripts' &&
|
||||
(['GET', 'HEAD'].includes(req.method) &&
|
||||
!(
|
||||
key === 'crons' && /^\/open\/crons\/import\/?$/.test(pathLower)
|
||||
)) ||
|
||||
(['scripts', 'logs'].includes(key || '') &&
|
||||
req.method === 'POST' &&
|
||||
/^\/open\/scripts\/download\/?$/.test(pathLower));
|
||||
/^\/open\/(?:scripts|logs)\/download\/?$/.test(pathLower));
|
||||
const hasNamespaceScope =
|
||||
doc.scopes.includes(key as AppScope) ||
|
||||
(['envs', 'configs', 'scripts'].includes(key || '') &&
|
||||
([
|
||||
'crons',
|
||||
'subscriptions',
|
||||
'envs',
|
||||
'configs',
|
||||
'scripts',
|
||||
'logs',
|
||||
'dependencies',
|
||||
'dashboard',
|
||||
].includes(key || '') &&
|
||||
doc.scopes.includes(`${key}:read` as AppScope) &&
|
||||
isReadRequest);
|
||||
if (!hasNamespaceScope) {
|
||||
@@ -131,11 +143,11 @@ export default ({ app }: { app: Application }) => {
|
||||
|
||||
// The built-in system app still needs its local CLI maintenance API.
|
||||
const appRouteAllowed =
|
||||
(key !== 'system' ||
|
||||
doc.name === 'system' ||
|
||||
((req.method === 'GET' || req.method === 'HEAD') &&
|
||||
(pathLower === '/open/system' || pathLower === '/open/system/')) ||
|
||||
(req.method === 'PUT' && pathLower === '/open/system/notify'));
|
||||
key !== 'system' ||
|
||||
doc.name === 'system' ||
|
||||
((req.method === 'GET' || req.method === 'HEAD') &&
|
||||
(pathLower === '/open/system' || pathLower === '/open/system/')) ||
|
||||
(req.method === 'PUT' && pathLower === '/open/system/notify');
|
||||
if (!appRouteAllowed) {
|
||||
const err = new UnauthorizedError('credentials_bad_scheme', {
|
||||
message: t('暂无权限'),
|
||||
|
||||
Reference in new issue
Block a user