amazon-ssm-agent icon indicating copy to clipboard operation
amazon-ssm-agent copied to clipboard

Custom Shell for `aws ssm start-session`

Open kellertobias opened this issue 8 years ago • 50 comments

I want to replace our ssh/ldap login with the ssm for all our AWS servers.

However the /bin/sh shell is not my favourite, so I want to use bash as default shell. I already configured that for the user ssm-user, however it still starts /bin/sh on startup.

(also tried to link /bin/sh to /bin/bash, but somehow it still finds /bin/bsh)

kellertobias avatar Oct 27 '18 14:10 kellertobias

+1 for this feature

csabapatyi avatar Nov 21 '18 22:11 csabapatyi

Would love for session manager to respect passwd settings (not sure how/why it's not now, is it because it's a non login shell?), like setting the default shell, etc. Is it possible to do this now somehow?

johnnyplaydrums avatar Dec 04 '18 13:12 johnnyplaydrums

The line of code in the agent is here: https://github.com/aws/amazon-ssm-agent/blob/b9654b268afcb7e70a9cc6c6d9b7d2a676f5b468/agent/session/plugins/shell/shell_unix.go#L53

teambob avatar Dec 28 '18 23:12 teambob

+1 on this

JibbyAni avatar Jan 18 '19 23:01 JibbyAni

As @johnplaydrums said, I think its sort of dangerous (for lack of a better word) to not respect general Linux behavior.

Some sort of configuration file on the instance or a setting in the AWS console would be acceptable too.

HewittJC avatar Jan 21 '19 18:01 HewittJC

Perhaps the agent could respect the shell setting in /etc/passwd for ssm-user?

teambob avatar Jan 22 '19 08:01 teambob

I can get to the shell I want by just calling /bin/bash directly upon login, but that just seems like an extra step. +1 on respecting /etc/passwd.

mewelling avatar Feb 20 '19 15:02 mewelling

Yeah, I have to type in "bash -l -o vi" to get my preferred login shell. It would be so simple for AWS to implement. Talk about being in the dark ages...

Robert-Joe avatar Feb 26 '19 21:02 Robert-Joe

So the fix is this in amazon-ssm-agent/agent/session/plugins/shell/shell_unix.go

cmd := exec.Command("bash -l")

Robert-Joe avatar Feb 26 '19 21:02 Robert-Joe

I'm not sure if this should be a separate feature request, but I'd like to be able to specify the initial command - e.g. aws ssm start-session <command>.

My use case: I'm writing a tool to start an SSM session on an ECS Container Instance and I want to immediately docker exec to start a shell, rails console, python console... inside one of the containers along the lines of https://engineering.loyaltylion.com/running-an-interactive-console-on-amazon-ecs-c692f321b14d.

Right now my script is sadly forced to print thedocker exec command and advise the user to copy/paste it at the ssm session shell prompt.

eyablonowitz avatar Mar 04 '19 13:03 eyablonowitz

Bump; I wanted to provide a patch but also talk this out a bit. It's simple in theory but that's only if it's made a configurable independent option by itself. If we go the passwd route or PAM, this becomes a much more involved thing. If there was a roadmap for this it would be helpful.

cwarner-mdsol avatar Mar 11 '19 18:03 cwarner-mdsol

👍 this pls

dantech2000 avatar Apr 16 '19 20:04 dantech2000

Has anybody figured out a workaround for this (other than instructing users to manually run a command)?

sh (which is really bash in "sh" mode) doesn't seem to be picking up any of the usual start up scripts like /etc/profile or ~/.profile that could be used to automatically run a command. If the code called exec.Command("sh -l") instead, then at least those could be used.

Apparently if you set an environment variable named ENV with the path to a shell script, then sh will execute that script when it runs, alas it is a chicken and egg problem because there doesn't seem to be a way to set ENV.

What's even worse, the non-primary groups for ssm-user don't seem to get recognized automatically either, so even though I add the ssm-user to the docker group, it can't run docker commands by default.

talawahtech avatar May 12 '19 21:05 talawahtech

I think custom shell invocations are possible now mostly due to commit d2d2746059ff4dde453c65c028102e25f28d0ee2. Apparently you need to reference an SSM document when calling StartSession. I have not attempted this yet.

fiducioso-dan avatar May 28 '19 14:05 fiducioso-dan

@fiducioso-dan

I think custom shell invocations are possible now mostly due to commit d2d2746. Apparently you need to reference an SSM document when calling StartSession. I have not attempted this yet.

tried to create a document according to the commit like the following:

{
    "schemaVersion": "1.0",
    "description": "Document to hold regional settings for Session Manager",
    "sessionType": "Standard_Stream",
    "inputs": {
      "s3BucketName": "",
      "s3KeyPrefix": "",
      "s3EncryptionEnabled": true,
      "cloudWatchLogGroupName": "",
      "cloudWatchEncryptionEnabled": true
    },
    "sessionCommands": [{
      "commands": "bash -lc 'echo fooooooooo'"
    }]
  }

Unfortunately, the API is rejecting sessionCommands:

 Error creating SSM document: InvalidDocumentContent: SessionCommands is not supported in Standard_Stream session type
	status code: 400

The only halfway official docs about session documents I found: https://docs.aws.amazon.com/systems-manager/latest/userguide/getting-started-configure-preferences-cli.html

Sort of looks like the agent itself would support it, but there's no way to create such document. Ideas?

skorfmann avatar May 31 '19 13:05 skorfmann

Bump.. my company is evaluating using this to replace our vpn/key access for several hundred machines but this is a dealbreaker. We need logins to load the shell/command of our choice as would be possible in /etc/passwd

slikk66 avatar Jun 14 '19 16:06 slikk66

I'm in the same situation, I then filed an AWS support ticket and here's where it is for now (since 2-3 days ago):

They (SSM AWS internal team) say that the SSM support /bin/sh and the behavior you are noticing is normal and by design, however there is a plan for SSM to support bash preference in the future. They are currently looking for a workaround to the issue and I will update you as soon as I get feedback. I will keep this case open until I update you on the workaround. In the mean time please reach out if you have any further questions, I will be glad to assist.

I really hope that they don't come up with a aws ssm --use-bash or similar non-intuitive flag. I do expect and hope that the final solution respects /etc/passwd, transparently, as @slikk66 mentions.

Fingers crossed.

brainstorm avatar Jun 15 '19 05:06 brainstorm

Thanks for filing a ticket @brainstorm! Please do let us know what workaround is offered.

tdmalone avatar Jun 15 '19 07:06 tdmalone

There's actually an issue from 2017 about this same topic but was left behind, apparently.

And also the possibility to use SSH instead, as pointed out in issue https://github.com/aws/amazon-ssm-agent/issues/188

... let's see what the SSM team comes up with.

brainstorm avatar Jun 21 '19 03:06 brainstorm

SSM team came back via AWS Support:

The main reason session manager is not using "bash" as default shell is because of logging. When using "bash" shell, session log files that are generated have formatting issues and gibberish characters. Due the logging issue on bash, session manager launches "sh" as a default shell at the moment.

They have also noted that they are currently working on implementing "bash" but they have to research and look for workarounds to improve logging which I believe might take some time.

brainstorm avatar Jun 26 '19 06:06 brainstorm