aws / aws/session-manager-plugin

Panic just after Session was successfully started

Open
#75 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
320
Forks
97
PR merge metrics
No merged PRs in 30d

Description

## The Problem

I'm trying to use `session-manager-plugin` to log into my ECS Fargate containers and I face the following issue:

```sh
Starting session with SessionId: ecs-execute-command-*****************
root@ip-***-***-***-***:/src# panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x102584cec]

goroutine 1 [running]:
github.com/aws/session-manager-plugin/src/sessionmanagerplugin/session.glob..func2(0x140001a0340, {0x102980dd0, 0x140001d6760})
/Users/kinjal/go/pkg/mod/github.com/aws/session-manager-plugin@v0.0.0-20230315220744-7b544e9f381d/src/sessionmanagerplugin/session/session.go:98 +0x5c
github.com/aws/session-manager-plugin/src/sessionmanagerplugin/session.(*Session).Execute(0x140001a0340, {0x102980dd0, 0x140001d6760})
/Users/kinjal/go/pkg/mod/github.com/aws/session-manager-plugin@v0.0.0-20230315220744-7b544e9f381d/src/sessionmanagerplugin/session/session.go:233 +0x21c
github.com/wingsure-inc/sshing/sshing.EcsExec()
/Users/kinjal/Desktop/DRIVE/WORK/sshing/sshing/aws.go:179 +0xa40
main.main()
/Users/kinjal/Desktop/DRIVE/WORK/sshing/main.go:9 +0x1c
exit status 2
```

> Sensitive information have been masked with ***

From the log line above, I can see that the session was successfully started. The line `root@ip-***-***-***-***:/src#` clearly depicts the same. I also confirmed through the Session Manager in AWS Console (https://ap-south-1.console.aws.amazon.com/systems-manager/session-manager/sessions?region=ap-south-1) that the sessions were started successfully. However as soon as the session is created, it `panics` somehow!

## More information

I've setup the session in the following fashion:

```go
var ssmSession session.Session
ssmSession.SessionId = *output.Session.SessionId
ssmSession.StreamUrl = *output.Session.StreamUrl
ssmSession.TokenValue = *output.Session.TokenValue
ssmSession.Endpoint = endpoint.URL
ssmSession.TargetId = fmt.Sprintf("ecs:%v_%v_%v", clusterName, taskId, containerRuntimeId)
ssmSession.ClientId = uuid.NewV4().String()
ssmSession.DataChannel = &datachannel.DataChannel{}
// ssmSession.SessionType = "NonInteractiveCommands"

log := log.Logger(true, ssmSession.ClientId)
err = ssmSession.Execute(log)
HandleErr(err)
```

The above code is inspired by this:
https://github.com/aws/session-manager-plugin/blob/7b544e9f381d809fd7117747d4b78b244addcf1e/src/sessionmanagerplugin/session/session.go#L182-L209

## AWS CLI

However, when I try to log into the container through `aws-cli` using this command, it works:
```sh
aws ecs execute-command --region --cluster --task --container --command "/bin/bash" --interactive
```

Digging into the `aws-cli` code, I find that it invokes `session-manager-plugin` as a `subprocess` rather than implementing it programmatically:
https://github.com/aws/aws-cli/blob/5218ac17b8141e1a15afed9e644904a6a1081b7d/awscli/customizations/ecs/executecommand.py#L103-L111

## My Goal
I wish to log into my ECS Fargate containers programmatically! My goal is to reverse-engineer `aws-cli` and `session-manager-plugin` so that they work together

Any help would be appreciated. Thanks in advanced!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.