sigs.k8s.io/cluster-api-provider-aws@v1.5.5/pkg/cloud/services/iamauth/iamauth.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 iamauth 18 19 import ( 20 crclient "sigs.k8s.io/controller-runtime/pkg/client" 21 22 ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1" 23 ) 24 25 const ( 26 // EC2NodeUserName is the username required for EC2 nodes. 27 EC2NodeUserName = "system:node:{{EC2PrivateDNSName}}" 28 ) 29 30 var ( 31 // NodeGroups is the groups that are required for a node. 32 NodeGroups = []string{"system:bootstrappers", "system:nodes"} 33 ) 34 35 // AuthenticatorBackend is the interface that represents an aws-iam-authenticator backend. 36 type AuthenticatorBackend interface { 37 // MapRole is used to map a role ARN to a user and set of groups 38 MapRole(mapping ekscontrolplanev1.RoleMapping) error 39 // MapUser is used to map a user ARN to a user and set of groups 40 MapUser(mapping ekscontrolplanev1.UserMapping) error 41 } 42 43 // BackendType is a type that represents the different aws-iam-authenticator backends. 44 type BackendType string 45 46 var ( 47 // BackendTypeConfigMap is the Kubernetes config map backend. 48 BackendTypeConfigMap = BackendType("config-map") 49 // BackendTypeCRD is the CRD based backend. 50 BackendTypeCRD = BackendType("crd") 51 ) 52 53 // NewBackend will create a new authenticate backend for a given type. Only use BackendTypeConfigMap 54 // with EKS. 55 func NewBackend(backendType BackendType, client crclient.Client) (AuthenticatorBackend, error) { 56 if client == nil { 57 return nil, ErrClientRequired 58 } 59 60 switch backendType { 61 case BackendTypeConfigMap: 62 return &configMapBackend{client: client}, nil 63 case BackendTypeCRD: 64 return &crdBackend{client: client}, nil 65 default: 66 return nil, ErrInvalidBackendType 67 } 68 }