sigs.k8s.io/cluster-api-provider-aws@v1.5.5/cmd/clusterawsadm/cloudformation/bootstrap/cluster_api_node.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package bootstrap 18 19 import ( 20 infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1" 21 iamv1 "sigs.k8s.io/cluster-api-provider-aws/iam/api/v1beta1" 22 ) 23 24 func (t Template) secretPolicy(secureSecretsBackend infrav1.SecretBackend) iamv1.StatementEntry { 25 switch secureSecretsBackend { 26 case infrav1.SecretBackendSecretsManager: 27 return iamv1.StatementEntry{ 28 Effect: iamv1.EffectAllow, 29 Resource: iamv1.Resources{ 30 "arn:*:secretsmanager:*:*:secret:aws.cluster.x-k8s.io/*", 31 }, 32 Action: iamv1.Actions{ 33 "secretsmanager:DeleteSecret", 34 "secretsmanager:GetSecretValue", 35 }, 36 } 37 case infrav1.SecretBackendSSMParameterStore: 38 return iamv1.StatementEntry{ 39 Effect: iamv1.EffectAllow, 40 Resource: iamv1.Resources{ 41 "arn:*:ssm:*:*:parameter/cluster.x-k8s.io/*", 42 }, 43 Action: iamv1.Actions{ 44 "ssm:DeleteParameter", 45 "ssm:GetParameter", 46 }, 47 } 48 } 49 return iamv1.StatementEntry{} 50 } 51 52 func (t Template) sessionManagerPolicy() iamv1.StatementEntry { 53 return iamv1.StatementEntry{ 54 Effect: iamv1.EffectAllow, 55 Resource: iamv1.Resources{iamv1.Any}, 56 Action: iamv1.Actions{ 57 "ssm:UpdateInstanceInformation", 58 "ssmmessages:CreateControlChannel", 59 "ssmmessages:CreateDataChannel", 60 "ssmmessages:OpenControlChannel", 61 "ssmmessages:OpenDataChannel", 62 "s3:GetEncryptionConfiguration", 63 }, 64 } 65 } 66 67 func (t Template) nodeManagedPolicies() []string { 68 policies := t.Spec.Nodes.ExtraPolicyAttachments 69 70 if !t.Spec.EKS.Disable { 71 policies = append(policies, 72 t.generateAWSManagedPolicyARN("AmazonEKSWorkerNodePolicy"), 73 t.generateAWSManagedPolicyARN("AmazonEKS_CNI_Policy"), 74 ) 75 } 76 77 if t.Spec.Nodes.EC2ContainerRegistryReadOnly { 78 policies = append(policies, t.generateAWSManagedPolicyARN("AmazonEC2ContainerRegistryReadOnly")) 79 } 80 81 return policies 82 } 83 84 func (t Template) nodePolicy() *iamv1.PolicyDocument { 85 policyDocument := t.cloudProviderNodeAwsPolicy() 86 for _, secureSecretsBackend := range t.Spec.SecureSecretsBackends { 87 policyDocument.Statement = append( 88 policyDocument.Statement, 89 t.secretPolicy(secureSecretsBackend), 90 ) 91 } 92 policyDocument.Statement = append( 93 policyDocument.Statement, 94 t.sessionManagerPolicy(), 95 ) 96 97 return policyDocument 98 } 99 100 func (t Template) generateAWSManagedPolicyARN(name string) string { 101 return "arn:" + t.Spec.Partition + ":iam::aws:policy/" + name 102 }