Repository navigation
馃Р feat: Enable Secure Attached Environment Pairing #15355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12816e9
feat: add secure code environment pairing
danny-avila 8e224df
fix: satisfy code environment type checks
danny-avila 6efd32f
fix: secure code environment administration
danny-avila 1ebdeef
fix: isolate code pairing control plane
danny-avila d38905f
fix: validate code pairing control responses
danny-avila d151683
fix: secure code pairing transport
danny-avila 87ca98e
fix: validate code pairing wire format
danny-avila e15b816
fix: harden pairing secret lookup
danny-avila File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
| const express = require('express'); | ||
| const { createAdminCodeEnvironmentHandlers } = require('@librechat/api'); | ||
| const { SystemCapabilities } = require('@librechat/data-schemas'); | ||
| const { requireCapability } = require('~/server/middleware/roles/capabilities'); | ||
| const { getAppConfig } = require('~/server/services/Config'); | ||
| const { requireJwtAuth } = require('~/server/middleware'); | ||
|
|
||
| const router = express.Router(); | ||
| const requireAdminAccess = requireCapability(SystemCapabilities.ACCESS_ADMIN); | ||
| const requireCodeEnvironmentManage = requireCapability(SystemCapabilities.MANAGE_CODE_ENVIRONMENTS); | ||
| const handlers = createAdminCodeEnvironmentHandlers({ getAppConfig }); | ||
|
|
||
| router.use(requireJwtAuth, requireAdminAccess, requireCodeEnvironmentManage); | ||
| router.post('/:environmentId/pairings', handlers.createPairing); | ||
| router.post('/:environmentId/revoke', handlers.revokeWorker); | ||
|
|
||
| module.exports = router; | ||
This file contains hidden or 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,74 @@ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| const middlewareCalls = []; | ||
| const mockRequireJwtAuth = jest.fn((req, _res, next) => { | ||
| middlewareCalls.push('jwt'); | ||
| req.user = { id: 'admin-1', role: 'ADMIN' }; | ||
| next(); | ||
| }); | ||
| const mockRequireCapability = jest.fn((capability) => (req, _res, next) => { | ||
| middlewareCalls.push(capability); | ||
| next(); | ||
| }); | ||
| const mockHandlers = { | ||
| createPairing: jest.fn((req, res) => | ||
| res.status(200).json({ operation: 'pair', environmentId: req.params.environmentId }), | ||
| ), | ||
| revokeWorker: jest.fn((req, res) => | ||
| res.status(200).json({ operation: 'revoke', environmentId: req.params.environmentId }), | ||
| ), | ||
| }; | ||
| const mockGetAppConfig = jest.fn(); | ||
|
|
||
| jest.mock('@librechat/data-schemas', () => ({ | ||
| SystemCapabilities: { | ||
| ACCESS_ADMIN: 'access:admin', | ||
| MANAGE_CODE_ENVIRONMENTS: 'manage:code_environments', | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('@librechat/api', () => ({ | ||
| createAdminCodeEnvironmentHandlers: jest.fn(() => mockHandlers), | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware/roles/capabilities', () => ({ | ||
| requireCapability: mockRequireCapability, | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware', () => ({ | ||
| requireJwtAuth: mockRequireJwtAuth, | ||
| })); | ||
|
|
||
| jest.mock('~/server/services/Config', () => ({ | ||
| getAppConfig: mockGetAppConfig, | ||
| })); | ||
|
|
||
| function createApp() { | ||
| delete require.cache[require.resolve('./code')]; | ||
| const router = require('./code'); | ||
| const app = express(); | ||
| app.use(express.json()); | ||
| app.use('/api/admin/code-environments', router); | ||
| return app; | ||
| } | ||
|
|
||
| describe('admin code environment routes', () => { | ||
| beforeEach(() => { | ||
| middlewareCalls.length = 0; | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['pairings', 'createPairing', 'pair'], | ||
| ['revoke', 'revokeWorker', 'revoke'], | ||
| ])('protects and delegates the %s operation', async (path, handlerName, operation) => { | ||
| const response = await request(createApp()) | ||
| .post(`/api/admin/code-environments/attached-vm/${path}`) | ||
| .expect(200); | ||
|
|
||
| expect(response.body).toEqual({ operation, environmentId: 'attached-vm' }); | ||
| expect(middlewareCalls).toEqual(['jwt', 'access:admin', 'manage:code_environments']); | ||
| expect(mockHandlers[handlerName]).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.