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

ci: Deny all IMDSv1 to instances #4358

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 21 additions & 38 deletions test/cloudformation/iam_cloudformation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ Resources:
- ec2:DescribeVpcs
# Image Permissions
- ec2:DescribeImages
Resource: "*"
- Effect: Allow
Action:
# Tag Permissions
- ec2:CreateTags
- ec2:DeleteTags
Expand Down Expand Up @@ -364,12 +361,7 @@ Resources:
- ec2:DeleteVpc
- ec2:DescribeVpcAttribute
- ec2:ModifyVpcAttribute
Resource: "*"
- Effect: Allow
Action: ec2:RunInstances
Resource: "*"
- Effect: Allow
Action:
- ec2:RunInstances
# Read-Only Permissions to pull ECR images needed by the NodeInstanceRole
- ecr:GetAuthorizationToken
- ecr:BatchCheckLayerAvailability
Expand All @@ -383,15 +375,9 @@ Resources:
- ecr:GetLifecyclePolicyPreview
- ecr:ListTagsForResource
- ecr:DescribeImageScanFindings
Resource: "*"
- Effect: Allow
Action:
# EKS ServiceRole permissions needed for AutoScalingGroups
- autoscaling:DescribeAutoScalingGroups
- autoscaling:UpdateAutoScalingGroup
Resource: "*"
- Effect: Allow
Action:
# EKS ServiceRole permissions needed to handle LoadBalancer
- elasticloadbalancing:AddTags
- elasticloadbalancing:ApplySecurityGroupsToLoadBalancer
Expand Down Expand Up @@ -424,15 +410,9 @@ Resources:
- elasticloadbalancing:RegisterTargets
- elasticloadbalancing:SetLoadBalancerPoliciesForBackendServer
- elasticloadbalancing:SetLoadBalancerPoliciesOfListener
Resource: "*"
- Effect: Allow
Action:
- kms:CreateGrant
- kms:GenerateDataKeyWithoutPlaintext
- kms:DescribeKey
Resource: "*"
- Effect: Allow
Action:
# SSM Permissions for AmazonSSMManagedInstanceCore policy applied to the NodeInstanceRole
- ssm:DescribeAssociation
- ssm:GetDeployablePatchSnapshotForInstance
Expand All @@ -449,53 +429,56 @@ Resources:
- ssm:UpdateAssociationStatus
- ssm:UpdateInstanceAssociationStatus
- ssm:UpdateInstanceInformation
Resource: "*"
- Effect: Allow
Action:
# SSM Permissions for AmazonSSMManagedInstanceCore policy applied to the NodeInstanceRole
- ssmmessages:CreateControlChannel
- ssmmessages:CreateDataChannel
- ssmmessages:OpenControlChannel
- ssmmessages:OpenDataChannel
Resource: "*"
- Effect: Allow
Action:
# SSM Permissions for AmazonSSMManagedInstanceCore policy applied to the NodeInstanceRole
- ec2messages:AcknowledgeMessage
- ec2messages:DeleteMessage
- ec2messages:FailMessage
- ec2messages:GetEndpoint
- ec2messages:GetMessages
- ec2messages:SendReply
Resource: "*"
- Effect: Allow
Action:
- sqs:DeleteMessage
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
- sqs:SendMessage
- sqs:ReceiveMessage
- pricing:GetProducts
- ec2:DescribeSpotPriceHistory
- eks:DescribeCluster
Resource: "*"
- Effect: Allow
Action: iam:PassRole
Resource:
- !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/KarpenterNodeRole-*"
- !GetAtt FISInterruptionRole.Arn
- Effect: Allow
Action:
- pricing:GetProducts
- ec2:DescribeSpotPriceHistory
Resource: "*"
- Effect: Allow
Action: eks:DescribeCluster
Resource: "*"
- Effect: Allow
Action:
- aps:RemoteWrite
- aps:GetSeries
- aps:GetLabels
- aps:GetMetricMetadata
Resource: !Sub "arn:${AWS::Partition}:aps:${AWS::Region}:${AWS::AccountId}:workspace/${PrometheusWorkspaceID}"
# Deny ALL IMDSv1 instance launch
- Effect: Deny
Action:
- ec2:RunInstances
Resource: "*"
Condition:
StringNotEquals:
ec2:MetadataHttpTokens: required
- Effect: Deny
Action:
- ec2:ModifyInstanceMetadataOptions
Resource: "*"
Condition:
StringEquals:
ec2:Attribute: HttpTokens
StringNotEquals:
ec2:Attribute/HttpTokens: required
GithubActionsRole:
Type: AWS::IAM::Role
Properties:
Expand Down