contracts

package
v0.0.0-...-0117b6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 18 Imported by: 16

Documentation

Overview

Package contracts defines all channel messages structure.

Package contracts defines all channel messages structure.

Index

Constants

View Source
const (
	AgentMessage_HLLength             = 4
	AgentMessage_MessageTypeLength    = 32
	AgentMessage_SchemaVersionLength  = 4
	AgentMessage_CreatedDateLength    = 8
	AgentMessage_SequenceNumberLength = 8
	AgentMessage_FlagsLength          = 8
	AgentMessage_MessageIdLength      = 16
	AgentMessage_PayloadDigestLength  = 32
	AgentMessage_PayloadTypeLength    = 4
	AgentMessage_PayloadLengthLength  = 4
)
View Source
const (
	AgentMessage_HLOffset             = 0
	AgentMessage_MessageTypeOffset    = AgentMessage_HLOffset + AgentMessage_HLLength
	AgentMessage_SchemaVersionOffset  = AgentMessage_MessageTypeOffset + AgentMessage_MessageTypeLength
	AgentMessage_CreatedDateOffset    = AgentMessage_SchemaVersionOffset + AgentMessage_SchemaVersionLength
	AgentMessage_SequenceNumberOffset = AgentMessage_CreatedDateOffset + AgentMessage_CreatedDateLength
	AgentMessage_FlagsOffset          = AgentMessage_SequenceNumberOffset + AgentMessage_SequenceNumberLength
	AgentMessage_MessageIdOffset      = AgentMessage_FlagsOffset + AgentMessage_FlagsLength
	AgentMessage_PayloadDigestOffset  = AgentMessage_MessageIdOffset + AgentMessage_MessageIdLength
	AgentMessage_PayloadTypeOffset    = AgentMessage_PayloadDigestOffset + AgentMessage_PayloadDigestLength
	AgentMessage_PayloadLengthOffset  = AgentMessage_PayloadTypeOffset + AgentMessage_PayloadTypeLength
	AgentMessage_PayloadOffset        = AgentMessage_PayloadLengthOffset + AgentMessage_PayloadLengthLength
)
View Source
const (
	// InteractiveShellMessage message type for interactive shell.
	InteractiveShellMessage string = "interactive_shell"
	// TaskReplyMessage represents message type for task reply
	TaskReplyMessage string = "agent_task_reply"
	// TaskCompleteMessage represents message type for task complete
	TaskCompleteMessage string = "agent_task_complete"
	// TaskAcknowledgeMessage represents message type for acknowledge of tasks sent over control channel
	TaskAcknowledgeMessage string = "agent_task_acknowledge"
	// AcknowledgeMessage represents message type for acknowledge
	AcknowledgeMessage string = "acknowledge"
	// AgentSessionState represents status of session
	AgentSessionState string = "agent_session_state"
	// ChannelClosedMessage represents message type for ChannelClosed
	ChannelClosedMessage string = "channel_closed"
	// OutputStreamDataMessage represents message type for outgoing stream data
	OutputStreamDataMessage string = "output_stream_data"
	// InputStreamDataMessage represents message type for incoming stream data
	InputStreamDataMessage string = "input_stream_data"
	// PausePublicationMessage message type for pause sending data packages.
	PausePublicationMessage string = "pause_publication"
	// StartPublicationMessage message type for start sending data packages.
	StartPublicationMessage string = "start_publication"
	// AgentJobMessage represents message type for agent job
	AgentJobMessage string = "agent_job"
	// AgentJobAcknowledgeMessage represents message for agent job acknowledge
	AgentJobAcknowledgeMessage string = "agent_job_ack"
	// AgentJobReplyAck represents message for agent job reply acknowledge
	AgentJobReplyAck string = "agent_job_reply_ack"
	// AgentJobReply represents message type for agent job reply
	AgentJobReply string = "agent_job_reply"
)

Variables

View Source
var ErrHandlerNotReady = errors.New("message handler is not ready, rejecting incoming packet")

ErrHandlerNotReady message indicates that the session plugin's incoming message handler is not ready

Functions

This section is empty.

Types

type AcknowledgeContent

type AcknowledgeContent struct {
	MessageType         string `json:"AcknowledgedMessageType"`
	MessageId           string `json:"AcknowledgedMessageId"`
	SequenceNumber      int64  `json:"AcknowledgedMessageSequenceNumber"`
	IsSequentialMessage bool   `json:"IsSequentialMessage"`
}

AcknowledgeContent is used to inform the sender of an acknowledge message that the message has been received. * MessageType is a 32 byte UTF-8 string containing the message type. * MessageId is a 40 byte UTF-8 string containing the UUID identifying this message being acknowledged. * SequenceNumber is an 8 byte integer containing the message sequence number for serialized message. * IsSequentialMessage is a boolean field representing whether the acknowledged message is part of a sequence

func (*AcknowledgeContent) Deserialize

func (dataStreamAcknowledge *AcknowledgeContent) Deserialize(log logger.T, agentMessage AgentMessage) (err error)

Deserialize parses AcknowledgeContent message from payload of AgentMessage.

func (*AcknowledgeContent) Serialize

func (dataStreamAcknowledge *AcknowledgeContent) Serialize(log logger.T) (result []byte, err error)

Serialize marshals AcknowledgeContent as payloads into bytes.

type AcknowledgeTaskContent

type AcknowledgeTaskContent struct {
	SchemaVersion int    `json:"SchemaVersion"`
	MessageId     string `json:"MessageId"`
	TaskId        string `json:"TaskId"`
	Topic         string `json:"Topic"`
}

AcknowledgeTaskContent parallels the structure of acknowledgement to task message

func (*AcknowledgeTaskContent) Deserialize

func (taskAcknowledge *AcknowledgeTaskContent) Deserialize(log logger.T, agentMessage AgentMessage) (err error)

Deserialize parses taskAcknowledge message from payload of AgentMessage.

func (*AcknowledgeTaskContent) Serialize

func (taskAcknowledge *AcknowledgeTaskContent) Serialize(log logger.T) (result []byte, err error)

Serialize marshals AcknowledgeTaskContent as payload into bytes.

type ActionStatus

type ActionStatus int
const (
	Success     ActionStatus = 1
	Failed      ActionStatus = 2
	Unsupported ActionStatus = 3
)

type ActionType

type ActionType string

ActionType used in Handshake to determine action requested by the agent

const (
	// Used to perform KMSEncryption related actions.
	KMSEncryption ActionType = "KMSEncryption"
	// Can be used to perform session type specific actions.
	SessionType ActionType = "SessionType"
)

type AgentJobAck

type AgentJobAck struct {
	JobId        string `json:"jobId"`
	MessageId    string `json:"acknowledgedMessageId"`
	CreatedDate  string `json:"createdDate"`
	StatusCode   string `json:"statusCode"`
	ErrorMessage string `json:"errorMessage"`
}

AgentJobAck is the acknowledge message sent back to MGS for AgentJobs

type AgentJobPayload

type AgentJobPayload struct {
	Payload       string `json:"Content"`
	JobId         string `json:"JobId"`
	Topic         string `json:"Topic"`
	SchemaVersion int    `json:"SchemaVersion"`
}

AgentJobPayload parallels the structure of a send-command or cancel-command job

type AgentJobReplyAckContent

type AgentJobReplyAckContent struct {
	JobId                 string `json:"jobId"`
	AcknowledgedMessageId string `json:"acknowledgedMessageId"`
}

AgentJobReplyAckContent is the acknowledge message sent back to MGS for AgentJobs

func (*AgentJobReplyAckContent) Deserialize

func (replyAck *AgentJobReplyAckContent) Deserialize(log logger.T, agentMessage AgentMessage) (err error)

Deserialize parses taskAcknowledge message from payload of AgentMessage.

func (*AgentJobReplyAckContent) Serialize

func (replyAck *AgentJobReplyAckContent) Serialize(log logger.T) (result []byte, err error)

Serialize marshals AgentJobReplyAckContent as payload into bytes.

type AgentJobReplyContent

type AgentJobReplyContent struct {
	SchemaVersion int    `json:"schemaVersion"`
	JobId         string `json:"jobId"`
	Content       string `json:"content"`
	Topic         string `json:"topic"`
}

AgentJobReplyContent parallels the structure of a send-command or cancel-command job

type AgentMessage

type AgentMessage struct {
	HeaderLength   uint32
	MessageType    string
	SchemaVersion  uint32
	CreatedDate    uint64
	SequenceNumber int64
	Flags          uint64
	MessageId      uuid.UUID
	PayloadDigest  []byte
	PayloadType    uint32
	PayloadLength  uint32
	Payload        []byte
}

AgentMessage represents a message for agent to send/receive. AgentMessage Message in MGS is equivalent to MDS' InstanceMessage. All agent messages are sent in this form to the MGS service.

func (*AgentMessage) Deserialize

func (agentMessage *AgentMessage) Deserialize(log logger.T, input []byte) (err error)

Deserialize deserializes the byte array into an AgentMessage message. * Payload is a variable length byte data. * | HL| MessageType |Ver| CD | Seq | Flags | * | MessageId | Digest |PayType| PayLen| * | Payload |

func (*AgentMessage) GetAgentJobId

func (agentMessage *AgentMessage) GetAgentJobId(context context.T) (string, error)

func (*AgentMessage) ParseAgentMessage

func (agentMessage *AgentMessage) ParseAgentMessage(context context.T, messagesOrchestrationRootDir string, instanceId string) (*contracts.DocumentState, error)

func (*AgentMessage) Serialize

func (agentMessage *AgentMessage) Serialize(log logger.T) (result []byte, err error)

Serialize serializes AgentMessage message into a byte array. * Payload is a variable length byte data. * | HL| MessageType |Ver| CD | Seq | Flags | * | MessageId | Digest |PayType| PayLen| * | Payload |

func (*AgentMessage) Validate

func (agentMessage *AgentMessage) Validate() error

Validate returns error if the message is invalid

type AgentSessionStateContent

type AgentSessionStateContent struct {
	SchemaVersion int    `json:"SchemaVersion"`
	SessionState  string `json:"SessionState"`
	SessionId     string `json:"SessionId"`
}

AgentSessionState is used to inform the sender of agent's session state.

type AgentTaskCompletePayload

type AgentTaskCompletePayload struct {
	SchemaVersion    int    `json:"SchemaVersion"`
	TaskId           string `json:"TaskId"`
	Topic            string `json:"Topic"`
	FinalTaskStatus  string `json:"FinalTaskStatus"`
	IsRoutingFailure bool   `json:"IsRoutingFailure"`
	AwsAccountId     string `json:"AwsAccountId"`
	InstanceId       string `json:"InstanceId"`
	Output           string `json:"Output"`
	S3Bucket         string `json:"S3Bucket"`
	S3UrlSuffix      string `json:"S3UrlSuffix"`
	CwlGroup         string `json:"CwlGroup"`
	CwlStream        string `json:"CwlStream"`
	RetryNumber      int    `json:"RetryNumber"`
}

AgentTaskCompletePayload is sent by the agent to inform the task is complete and what the overall result was.

type AgentTaskPayload

type AgentTaskPayload struct {
	DocumentName    string                           `json:"DocumentName"`
	DocumentContent contracts.SessionDocumentContent `json:"DocumentContent"`
	SessionId       string                           `json:"SessionId"`
	Parameters      map[string]interface{}           `json:"Parameters"`
	RunAsUser       string                           `json:"RunAsUser"`
	SessionOwner    string                           `json:"SessionOwner"`
}

AgentTaskPayload parallels the structure of a send command MGS message payload.

type ChannelClosed

type ChannelClosed struct {
	MessageType   string `json:"MessageType"`
	MessageId     string `json:"MessageId"`
	DestinationId string `json:"DestinationId"`
	SessionId     string `json:"SessionId"`
	SchemaVersion int    `json:"SchemaVersion"`
	CreatedDate   string `json:"CreatedDate"`
}

ChannelClosed is used to inform the agent of a channel to be closed. * MessageType is a 32 byte UTF-8 string containing the message type. * MessageId is a 40 byte UTF-8 string containing the UUID identifying this message. * DestinationId is a string field containing the session target. * SessionId is a string field representing which session to close. * SchemaVersion is a 4 byte integer containing the message schema version number. * CreatedDate is a string field containing the message create epoch millis in UTC.

func (*ChannelClosed) Deserialize

func (channelClose *ChannelClosed) Deserialize(log logger.T, agentMessage AgentMessage) (err error)

Deserialize parses channelClosed message from payload of AgentMessage.

func (*ChannelClosed) Serialize

func (channelClose *ChannelClosed) Serialize(log logger.T) (result []byte, err error)

Serialize marshals ChannelClosed as payloads into bytes.

type EncryptionChallengeRequest

type EncryptionChallengeRequest struct {
	Challenge []byte `json:"Challenge"`
}

This is sent by the agent as a challenge to the client. The challenge field is some data that was encrypted by the agent. The client must be able to decrypt this and in turn encrypt it with its own key.

type EncryptionChallengeResponse

type EncryptionChallengeResponse struct {
	Challenge []byte `json:"Challenge"`
}

This is received by the agent from the client. The challenge field contains some data received, decrypted and then encrypted by the client. Agent must be able to decrypt this and verify it matches the original plaintext challenge.

type HandshakeCompletePayload

type HandshakeCompletePayload struct {
	HandshakeTimeToComplete time.Duration `json:"HandshakeTimeToComplete"`
	CustomerMessage         string        `json:"CustomerMessage"`
}

Handshake Complete indicates to client that handshake is complete. This signals the client to start the plugin and display a customer message where appropriate.

type HandshakeRequestPayload

type HandshakeRequestPayload struct {
	AgentVersion           string                  `json:"AgentVersion"`
	RequestedClientActions []RequestedClientAction `json:"RequestedClientActions"`
}

Handshake payload sent by the agent to the session manager plugin

type HandshakeResponsePayload

type HandshakeResponsePayload struct {
	ClientVersion          string                  `json:"ClientVersion"`
	ProcessedClientActions []ProcessedClientAction `json:"ProcessedClientActions"`
	Errors                 []string                `json:"Errors"`
}

Handshake Response sent by the plugin in response to the handshake request

type IAgentMessage

type IAgentMessage interface {
	Deserialize(log logger.T, input []byte) (err error)
	Serialize(log logger.T) (result []byte, err error)
	Validate() error
	ParseAgentMessage(context context.T, messagesOrchestrationRootDir string, instanceId string) (*contracts.DocumentState, error)
}

type IMessage

type IMessage interface {
	Deserialize(log logger.T, agentMessage AgentMessage) (err error)
	Serialize(log logger.T) (result []byte, err error)
}

type KMSEncryptionRequest

type KMSEncryptionRequest struct {
	KMSKeyID string `json:"KMSKeyId"`
}

This is sent by the agent to initialize KMS encryption

type KMSEncryptionResponse

type KMSEncryptionResponse struct {
	KMSCipherTextKey  []byte `json:"KMSCipherTextKey"`
	KMSCipherTextHash []byte `json:"KMSCipherTextHash"`
}

This is received by the agent to set up KMS encryption

type MGSPayload

type MGSPayload struct {
	Payload       string `json:"Content"`
	TaskId        string `json:"TaskId"`
	Topic         string `json:"Topic"`
	SchemaVersion int    `json:"SchemaVersion"`
}

MGSPayload parallels the structure of a start-session MGS message payload.

type PayloadMessageBase

type PayloadMessageBase struct {
	HeaderLength  uint32
	PayloadDigest []byte
	PayloadLength uint32
	Payload       []byte
}

PayloadMessageBase represent the base struct for all messages that include a payload. * HeaderLength is a 4 byte integer that represents the header length. * Payload digest is a 32 byte containing the SHA-256 hash of the payload. * Payload length is an 8 byte unsigned integer containing the byte length of data in the Payload field. * Payload is a variable length byte data.

type PayloadType

type PayloadType uint32
const (
	Output               PayloadType = 1
	Error                PayloadType = 2
	Size                 PayloadType = 3
	Parameter            PayloadType = 4
	HandshakeRequest     PayloadType = 5
	HandshakeResponse    PayloadType = 6
	HandshakeComplete    PayloadType = 7
	EncChallengeRequest  PayloadType = 8
	EncChallengeResponse PayloadType = 9
	Flag                 PayloadType = 10
	StdErr               PayloadType = 11
	ExitCode             PayloadType = 12
)

type PayloadTypeFlag

type PayloadTypeFlag uint32
const (
	DisconnectToPort   PayloadTypeFlag = 1
	TerminateSession   PayloadTypeFlag = 2
	ConnectToPortError PayloadTypeFlag = 3
)

type ProcessedClientAction

type ProcessedClientAction struct {
	ActionType   ActionType      `json:"ActionType"`
	ActionStatus ActionStatus    `json:"ActionStatus"`
	ActionResult json.RawMessage `json:"ActionResult"`
	Error        string          `json:"Error"`
}

The result of processing the action by the plugin

type RequestedClientAction

type RequestedClientAction struct {
	ActionType       ActionType  `json:"ActionType"`
	ActionParameters interface{} `json:"ActionParameters"`
}

An action requested by the agent to the plugin

type SessionPluginResultOutput

type SessionPluginResultOutput struct {
	Output      string
	S3Bucket    string
	S3UrlSuffix string
	CwlGroup    string
	CwlStream   string
}

SessionPluginResultOutput represents PluginResult output sent to MGS as part of AgentTaskComplete message

type SessionStatus

type SessionStatus string
const (
	Connected   SessionStatus = "Connected"
	Terminating SessionStatus = "Terminating"
)

type SessionTypeRequest

type SessionTypeRequest struct {
	SessionType string      `json:"SessionType"`
	Properties  interface{} `json:"Properties"`
}

type ShellConfig

type ShellConfig struct {
	Commands              string      `json:"commands" yaml:"commands"`
	RunAsElevated         bool        `json:"runAsElevated" yaml:"runAsElevated"`
	SeparateOutputStream  interface{} `json:"separateOutputStream" yaml:"separateOutputStream"`
	StdOutSeparatorPrefix string      `json:"stdOutSeparatorPrefix" yaml:"stdOutSeparatorPrefix"`
	StdErrSeparatorPrefix string      `json:"stdErrSeparatorPrefix" yaml:"stdErrSeparatorPrefix"`
}

type ShellProperties

type ShellProperties struct {
	Windows ShellConfig `json:"windows" yaml:"windows"`
	Linux   ShellConfig `json:"linux" yaml:"linux"`
	MacOS   ShellConfig `json:"macos" yaml:"macos"`
}

type SizeData

type SizeData struct {
	Cols uint32 `json:"cols"`
	Rows uint32 `json:"rows"`
}

type TaskMessageBase

type TaskMessageBase struct {
	MessageType   string
	SchemaVersion uint32
	CreatedDate   uint64
	MessageId     string
	TaskId        string
	Topic         string
}

TaskMessageBase represents basic structure for task messages. * MessageType is a 32 byte UTF-8 string containing the message type. * SchemaVersion is a 4 byte integer containing the message schema version number. * CreatedDate is an 8 byte integer containing the message create epoch millis in UTC. * MessageId is a 40 byte UTF-8 string containing a random UUID identifying this message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL