-
Notifications
You must be signed in to change notification settings - Fork 217
Add API for SSH proxy #3646
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
un-def
wants to merge
5
commits into
master
Choose a base branch
from
issue_3644_sshproxy_get_upstream_api_method
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+827
−87
Open
Add API for SSH proxy #3646
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d7a870
Add API for SSH proxy
un-def 011d6a8
Merge remote-tracking branch 'origin/master' into issue_3644_sshproxy…
un-def ea55b8e
Merge remote-tracking branch 'origin/master' into issue_3644_sshproxy…
un-def 31bdec8
Use new helpers get_{run,job}_spec
un-def 764bf33
Fix typing
un-def 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
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
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,39 @@ | ||
| import os | ||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends | ||
| from sqlalchemy.ext.asyncio import AsyncSession | ||
|
|
||
| from dstack._internal.core.errors import ResourceNotExistsError | ||
| from dstack._internal.server.db import get_session | ||
| from dstack._internal.server.schemas.sshproxy import GetUpstreamRequest, GetUpstreamResponse | ||
| from dstack._internal.server.security.permissions import AlwaysForbidden, ServiceAccount | ||
| from dstack._internal.server.services.sshproxy import get_upstream_response | ||
| from dstack._internal.server.utils.routers import ( | ||
| CustomORJSONResponse, | ||
| get_base_api_additional_responses, | ||
| ) | ||
|
|
||
| if _token := os.getenv("DSTACK_SSHPROXY_API_TOKEN"): | ||
| _auth = ServiceAccount(_token) | ||
| else: | ||
| _auth = AlwaysForbidden() | ||
|
|
||
|
|
||
| router = APIRouter( | ||
| prefix="/api/sshproxy", | ||
| tags=["sshproxy"], | ||
| responses=get_base_api_additional_responses(), | ||
| dependencies=[Depends(_auth)], | ||
| ) | ||
|
|
||
|
|
||
| @router.post("/get_upstream", response_model=GetUpstreamResponse) | ||
| async def get_upstream( | ||
| body: GetUpstreamRequest, | ||
| session: Annotated[AsyncSession, Depends(get_session)], | ||
| ): | ||
| response = await get_upstream_response(session=session, upstream_id=body.id) | ||
| if response is None: | ||
| raise ResourceNotExistsError() | ||
| return CustomORJSONResponse(response) |
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,27 @@ | ||
| from typing import Annotated | ||
|
|
||
| from pydantic import Field | ||
|
|
||
| from dstack._internal.core.models.common import CoreModel | ||
|
|
||
|
|
||
| class GetUpstreamRequest(CoreModel): | ||
| # The format of id is intentionally not limited to UUID to allow further extensions | ||
| id: str | ||
|
|
||
|
|
||
| class UpstreamHost(CoreModel): | ||
| host: Annotated[str, Field(description="The hostname or IP address")] | ||
| port: Annotated[int, Field(description="The SSH port")] | ||
| user: Annotated[str, Field(description="The user to log in")] | ||
| private_key: Annotated[str, Field(description="The private key in OpenSSH file format")] | ||
|
|
||
|
|
||
| class GetUpstreamResponse(CoreModel): | ||
| hosts: Annotated[ | ||
| list[UpstreamHost], | ||
| Field(description="The chain of SSH hosts, the jump host(s) first, the target host last"), | ||
| ] | ||
| authorized_keys: Annotated[ | ||
| list[str], Field(description="The list of authorized public keys in OpenSSH file format") | ||
| ] |
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.