Skip to content

aws instance-connect is not using --profile for the connection #1846

@czunker

Description

@czunker

Describe the bug
When I run instance-connect with --profile I get this error:

cnquery run aws ec2 instance-connect ec2-user@i-08db02ceb047ea7fb --profile AdministratorAccess-1234567890 --region eu-central-1 -c 'asset{ name title ids platform }'
! CLI pre-processing encountered an issue error="unknown flag: --profile"
! using builtin provider for aws
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
→ no AWS region found, using us-east-1
FTL failed to run query error="operation error STS: GetCallerIdentity, exceeded maximum number of attempts, 3, failed to sign request: failed to retrieve credentials: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, exceeded maximum number of attempts, 3, request send failed, Get \"http://169.254.169.254/latest/meta-data/iam/security-credentials/\": dial tcp 169.254.169.254:80: i/o timeout"

Using the was CLI works:

aws ec2-instance-connect ssh --instance-id i-08db02ceb047ea7fb --region eu-central-1 --profile AdministratorAccess-1234567890                                              
The authenticity of host '3.71.8.75 (3.71.8.75)' can't be established.
ED25519 key fingerprint is SHA256:yBfOVxhFjUtRSH37CZ27x3TUWYKvNzsaK71mJF8AgBI.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '3.71.8.75' (ED25519) to the list of known hosts.
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
[ec2-user@ip-172-31-21-20 ~]$ 

Setting the env var, it works independent of the --profile parameter:

export AWS_PROFILE=AdministratorAccess-1234567890
cnquery run aws ec2 instance-connect ec2-user@i-08db02ceb047ea7fb --region eu-central-1 -c 'asset{ name title ids platform }'                                            
! CLI pre-processing encountered an issue error="unknown flag: --region"
! using builtin provider for aws
→ loaded configuration from /etc/opt/mondoo/mondoo.yml using source default
→ no AWS region found, using us-east-1
! using builtin provider for os
asset: {
  title: "Amazon Linux 2023"
  platform: "amazonlinux"
  ids: [
    0: "//platformid.api.mondoo.app/hostname/ip-172-31-21-20.eu-central-1.compute.internal"
  ]
  name: "ip-172-31-21-20.eu-central-1.compute.internal"
}

To Reproduce
Steps to reproduce the behavior:

  1. Create new EC2 instance
  2. Set up an AWS profile
  3. Try instance-connect with this profile
  4. Note the error

Expected behavior
The parameter should set the profile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv9.1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions