mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-21 05:42:14 +00:00
Add ssh keys to nodes on demand (#411)
Our existing model has a per-scaleset SSH key. This update moves towards using user provided SSH keys when they need to connect to a given node.
This commit is contained in:
@ -18,9 +18,10 @@ from onefuzztypes.enums import (
|
||||
)
|
||||
from onefuzztypes.models import AutoScaleConfig, Error
|
||||
from onefuzztypes.models import Node as BASE_NODE
|
||||
from onefuzztypes.models import NodeAssignment, NodeCommand
|
||||
from onefuzztypes.models import NodeAssignment, NodeCommand, NodeCommandAddSshKey
|
||||
from onefuzztypes.models import NodeTasks as BASE_NODE_TASK
|
||||
from onefuzztypes.models import Pool as BASE_POOL
|
||||
from onefuzztypes.models import Result
|
||||
from onefuzztypes.models import Scaleset as BASE_SCALESET
|
||||
from onefuzztypes.models import (
|
||||
ScalesetNodeState,
|
||||
@ -257,11 +258,10 @@ class Node(BASE_NODE, ORMMixin):
|
||||
return self.version != __version__
|
||||
|
||||
def send_message(self, message: NodeCommand) -> None:
|
||||
stop_message = NodeMessage(
|
||||
NodeMessage(
|
||||
agent_id=self.machine_id,
|
||||
message=message,
|
||||
)
|
||||
stop_message.save()
|
||||
).save()
|
||||
|
||||
def to_reimage(self, done: bool = False) -> None:
|
||||
if done:
|
||||
@ -273,6 +273,21 @@ class Node(BASE_NODE, ORMMixin):
|
||||
self.reimage_requested = True
|
||||
self.save()
|
||||
|
||||
def add_ssh_public_key(self, public_key: str) -> Result[None]:
|
||||
if self.scaleset_id is None:
|
||||
return Error(
|
||||
code=ErrorCode.INVALID_REQUEST,
|
||||
errors=["only able to add ssh keys to scaleset nodes"],
|
||||
)
|
||||
|
||||
if not public_key.endswith("\n"):
|
||||
public_key += "\n"
|
||||
|
||||
self.send_message(
|
||||
NodeCommand(add_ssh_key=NodeCommandAddSshKey(public_key=public_key))
|
||||
)
|
||||
return None
|
||||
|
||||
def stop(self) -> None:
|
||||
self.to_reimage()
|
||||
self.send_message(NodeCommand(stop=StopNodeCommand()))
|
||||
|
Reference in New Issue
Block a user