Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable ec2 instance connect from user-data #58

Closed
vasu-git opened this issue Apr 12, 2022 · 3 comments
Closed

How to enable ec2 instance connect from user-data #58

vasu-git opened this issue Apr 12, 2022 · 3 comments

Comments

@vasu-git
Copy link

Image I'm using:
Bottlerocket OS 1.7.0 (aws-k8s-1.21)

I'm trying to use bottlerocket in my eks cluster(it uses karpenter with a custom launch template)
I also need to enable ssh access to the instance by default using ec2 instance connect.(it works seamlessly for non-bottlerocket based instances)

I was able to enable admin container by default by adding the following the the user-data for the launch template

[settings.host-containers.admin]
enabled = true

However I'm still not able to connect to the instance using mssh probably since authorized-keys-command and authorized-keys-command-user are not set in the admin-container? Reference: #39

How do I set these from the user-data of a launch template?

@jpculp
Copy link
Member

jpculp commented Apr 12, 2022

Hi @vasu-git, thanks for reaching out. By default the only authentication method that is enabled is traditional SSH using the key you set when you created the instance. If you'd like to use EC2 Instance Connect instead, you need to set the admin container's userdata with the addition of a base64-encoded block like so:

[settings.host-containers.admin]
enabled = true
user-data = YOURBASE64BLOCKHERE

The base64-encoded block should contain the following JSON:

{
  "ssh": {
    "authorized-keys-command": "/opt/aws/bin/eic_run_authorized_keys %u %f",
    "authorized-keys-command-user": "ec2-instance-connect"
  }
}

For more authentication options, see Authenticating with the Admin Container.

@vasu-git
Copy link
Author

Thanks @jpculp.
That worked :)

@jpculp
Copy link
Member

jpculp commented Apr 12, 2022

Glad it worked out!

@jpculp jpculp closed this as completed Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants