Custom Shell for `aws ssm start-session`
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)
+1 for this feature
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?
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
+1 on this
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.
Perhaps the agent could respect the shell setting in /etc/passwd for ssm-user?
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.
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...
So the fix is this in amazon-ssm-agent/agent/session/plugins/shell/shell_unix.go
cmd := exec.Command("bash -l")
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.
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.
👍 this pls
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.
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
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?
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
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.
Thanks for filing a ticket @brainstorm! Please do let us know what workaround is offered.
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.
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.