eksctl icon indicating copy to clipboard operation
eksctl copied to clipboard

Implementation Tries to Create an SSH Security Group Despite the SSH Configuration

Open Cushdrive opened this issue 6 years ago • 1 comments

What happened? I have created a managed nodegroup configuration that matches the following snippet from examples/07-ssh-keys.yaml:

  • name: ng-5 instanceType: m5.large desiredCapacity: 1 ssh: # use existing EC2 key but don't allow SSH access to nodegroup. publicKeyName: ec2_dev_key allow: false

As the comment implies, I should be able to specify an existing SSH Key to associate with the launch template, but not associate/create a Security Group that allows ssh access at the time of nodegroup creation.

What you expected to happen? I expect the existing EC2 public key to be associated with managed EC2 instances, but a new Security Group allowing SSH access should not be created and associated with these EC2 instances.

How to reproduce it? Use the following configuration. If you bump the log level, you can clearly see that a new Security Group is being created and associated with the launch template.

---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: eks-dev-1
  region: eu-central-1
  version: "1.18"
vpc:
  id: "vpc-1234"
  cidr: "10.252.64.0/21"
  clusterEndpoints:
    privateAccess: true
    publicAccess: false
  sharedNodeSecurityGroup: "sg-1234" # Even if specified, AWS creates its own.
  securityGroup: "sg-1234"
  subnets:
    private:
      eu-central-1a:
          id: "subnet-1234"
          cidr: "10.252.64.0/23"
      eu-central-1b:
          id: "subnet-3456"
          cidr: "10.252.66.0/23"
iam:
  serviceRoleARN: "arn:aws:iam::1234:role/eks-cluster-role"
cloudWatch:
  clusterLogging:
    enableTypes: ["scheduler","api","controllerManager", "audit", "authenticator"]
managedNodeGroups:
  - name: ng-private
    instanceType: m5.xlarge
    minSize: 1
    desiredCapacity: 2
    maxSize: 5
    availabilityZones: ["eu-central-1a", "eu-central-1b"]
    volumeSize: 20
    volumeEncrypted: true
    volumeKmsKeyID: 1234
    privateNetworking: true # if only 'Private' subnets are given, this must be enabled
    securityGroups:
      withShared: false
      withLocal: false
      attachIDs: [sg-1234, sg-5678]
    iam:
      instanceRoleARN: arn:aws:iam::1234:role/eks-node-role
    ssh:
      publicKeyName: dev-key
      allow: false
    labels: {role: worker}

Anything else we need to know? Running eksctl version 0.30.0 on MacOS. Installed via homebrew. Using AWS Tokens for access to AWS. If you look at line 45 in pkg/cfn/builder/managed_launch_template.go, it seems like there's no way to avoid this behavior, if publicKeyName is specified. It looks like changes were only made to support this scenario in unmanaged node groups via commit 135251954c02054df06dcd6f4dda472f4e1692b3.

Versions Please paste in the output of these commands:

$ eksctl version
$ kubectl version

❯ eksctl version 0.30.0

❯ kubectl version Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-26T15:44:05Z", GoVersion:"go1.15.3", Compiler:"gc", Platform:"darwin/amd64"}

Logs The relevant sections have been adjusted to remove sensitive information and are included below:

2020-11-04T12:28:55-06:00 [▶]  CreateStackInput = {
  Capabilities: ["CAPABILITY_IAM"],
  StackName: "eksctl-eks-dev-1-nodegroup-sharesource-ng-private",
  Tags: [
    {
      Key: "alpha.eksctl.io/cluster-name",
      Value: "eks-dev-1"
    },
    {
      Key: "eksctl.cluster.k8s.io/v1alpha1/cluster-name",
      Value: "eks-dev-1"
    },
    {
      Key: "alpha.eksctl.io/eksctl-version",
      Value: "0.30.0"
    },    
    {
      Key: "alpha.eksctl.io/nodegroup-name",
      Value: "ng-private"
    },
    {
      Key: "k8s.io/cluster-autoscaler/enabled",
      Value: "true"
    },
    {
      Key: "nodegroup-role",
      Value: "worker"
    },
    {
      Key: "alpha.eksctl.io/nodegroup-type",
      Value: "managed"
    }
  ],
  TemplateBody: "{\"AWSTemplateFormatVersion\":\"2010-09-09\",\"Description\":\"EKS Managed Nodes (SSH access: false) [created by eksctl]\",\"Mappings\":{\"ServicePrincipalPartitionMap\":{\"aws\":{\"EC2\":\"ec2.amazonaws.com\",\"EKS\":\"eks.amazonaws.com\",\"EKSFargatePods\":\"eks-fargate-pods.amazonaws.com\"},\"aws-cn\":{\"EC2\":\"ec2.amazonaws.com.cn\",\"EKS\":\"eks.amazonaws.com\",\"EKSFargatePods\":\"eks-fargate-pods.amazonaws.com\"},\"aws-us-gov\":{\"EC2\":\"ec2.amazonaws.com\",\"EKS\":\"eks.amazonaws.com\",\"EKSFargatePods\":\"eks-fargate-pods.amazonaws.com\"}}},\"Resources\":{\"LaunchTemplate\":{\"Type\":\"AWS::EC2::LaunchTemplate\",\"Properties\":{\"LaunchTemplateData\":{\"BlockDeviceMappings\":[{\"DeviceName\":\"/dev/xvda\",\"Ebs\":{\"Encrypted\":true,\"KmsKeyId\":\"redacted\",\"VolumeSize\":20,\"VolumeType\":\"gp2\"}}],\"InstanceType\":\"m5.xlarge\",\"KeyName\":\"dev-key\",\"MetadataOptions\":{\"HttpPutResponseHopLimit\":2,\"HttpTokens\":\"optional\"},\"SecurityGroupIds\":[{\"Fn::ImportValue\":\"eksctl-eks-dev-1-cluster::ClusterSecurityGroupId\"},\"sg-1234\",\"sg-5678\",{\"Ref\":\"SSH\"}],\"TagSpecifications\":[{\"ResourceType\":\"instance\",\"Tags\":[{\"Key\":\"Name\",\"Value\":\"eks-dev-1-ng-private-Node\"},{\"Key\":\"alpha.eksctl.io/nodegroup-name\",\"Value\":\"sharesource-ng-private\"},{\"Key\":\"nodegroup-role\",\"Value\":\"worker\"},{\"Key\":\"alpha.eksctl.io/nodegroup-type\",\"Value\":\"managed\"},{\"Key\":\"k8s.io/cluster-autoscaler/enabled\",\"Value\":\"true\"}]}]},\"LaunchTemplateName\":{\"Fn::Sub\":\"${AWS::StackName}\"}}},\"ManagedNodeGroup\":{\"Type\":\"AWS::EKS::Nodegroup\",\"Properties\":{\"AmiType\":\"AL2_x86_64\",\"ClusterName\":\"eks-dev-1\",\"Labels\":{\"alpha.eksctl.io/cluster-name\":\"eks-dev-1\",\"alpha.eksctl.io/nodegroup-name\":\"ng-private\",\"role\":\"worker\"},\"LaunchTemplate\":{\"Id\":{\"Ref\":\"LaunchTemplate\"}},\"NodeRole\":\"arn:aws:iam::615146175312:role/dev-eks-node-role\",\"NodegroupName\":\"ng-private\",\"ScalingConfig\":{\"DesiredSize\":2,\"MaxSize\":5,\"MinSize\":1},\"Subnets\":[\"subnet-3eba1f55\",\"subnet-60766d1a\"]}},\"SSH\":{\"Type\":\"AWS::EC2::SecurityGroup\",\"Properties\":{\"GroupDescription\":\"Allow SSH access\",\"GroupName\":{\"Fn::Sub\":\"${AWS::StackName}-remoteAccess\"},\"SecurityGroupIngress\":[{\"CidrIp\":\"10.252.64.0/21\",\"FromPort\":22,\"IpProtocol\":\"tcp\",\"ToPort\":22}],\"Tags\":[{\"Key\":\"Name\",\"Value\":{\"Fn::Sub\":\"${AWS::StackName}/SSH\"}}],\"VpcId\":{\"Fn::ImportValue\":\"eksctl-eks-dev-1-cluster::VPC\"}}}}}"
}

Cushdrive avatar Nov 04 '20 21:11 Cushdrive

Thanks for opening the issue @Cushdrive. I've managed to re-create the issue using the following config:

# An example of ClusterConfig showing different ways of setting nodegroup SSH keys:
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: jk-managed
  region: us-west-2

managedNodeGroups:
  - name: ng-5
    instanceType: m5.large
    desiredCapacity: 1
    ssh: # use existing EC2 key but don't allow SSH access to nodegroup.
      publicKeyName: <my-key>
      allow: false

I can see that a SecurityGroup was created to enable SSH access, despite the allow:false being set. I'm going to open a PR to fix this issue.

aclevername avatar Nov 06 '20 14:11 aclevername