Skip to content

Commit 8e9df3e

Browse files
committed
feat: support setting EKS AuthenticationMode
1 parent 4507c0b commit 8e9df3e

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
164164
// +optional
165165
Addons *[]Addon `json:"addons,omitempty"`
166166

167-
// IdentityProviderconfig is used to specify the oidc provider config
167+
// OIDCIdentityProviderConfig is used to specify the oidc provider config
168168
// to be attached with this eks cluster
169169
// +optional
170170
OIDCIdentityProviderConfig *OIDCIdentityProviderConfig `json:"oidcIdentityProviderConfig,omitempty"`
171171

172+
// AccessConfig specifies the access configuration information for the cluster
173+
// +optional
174+
AccessConfig *AccessConfig `json:"accessConfig,omitempty"`
175+
172176
// VpcCni is used to set configuration options for the VPC CNI plugin
173177
// +optional
174178
VpcCni VpcCni `json:"vpcCni,omitempty"`
@@ -219,6 +223,15 @@ type EndpointAccess struct {
219223
Private *bool `json:"private,omitempty"`
220224
}
221225

226+
// AccessConfig represents the access configuration information for the cluster
227+
type AccessConfig struct {
228+
// AuthenticationMode specifies the desired authentication mode for the cluster
229+
// Defaults to CONFIG_MAP
230+
// +kubebuilder:default=CONFIG_MAP
231+
// +kubebuilder:validation:Enum=CONFIG_MAP;API;API_AND_CONFIG_MAP
232+
AuthenticationMode EKSAuthenticationMode `json:"authenticationMode,omitempty"`
233+
}
234+
222235
// EncryptionConfig specifies the encryption configuration for the EKS clsuter.
223236
type EncryptionConfig struct {
224237
// Provider specifies the ARN or alias of the CMK (in AWS KMS)

controlplane/eks/api/v1beta2/types.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ var (
7979
EKSTokenMethodAWSCli = EKSTokenMethod("aws-cli")
8080
)
8181

82+
// EKSAuthenticationMode defines the authentication mode for the cluster
83+
type EKSAuthenticationMode string
84+
85+
var (
86+
// EKSAuthenticationModeConfigMap indicates that only `aws-auth` ConfigMap will be used for authentication
87+
EKSAuthenticationModeConfigMap = EKSAuthenticationMode("CONFIG_MAP")
88+
89+
// EKSAuthenticationModeApi indicates that only AWS Access Entries will be used for authentication
90+
EKSAuthenticationModeApi = EKSAuthenticationMode("API")
91+
92+
// EKSAuthenticationModeApiAndConfigMap indicates that both `aws-auth` ConfigMap and AWS Access Entries will
93+
// be used for authentication
94+
EKSAuthenticationModeApiAndConfigMap = EKSAuthenticationMode("API_AND_CONFIG_MAP")
95+
)
96+
8297
var (
8398
// DefaultEKSControlPlaneRole is the name of the default IAM role to use for the EKS control plane
8499
// if no other role is supplied in the spec and if iam role creation is not enabled. The default

pkg/cloud/services/eks/cluster.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ func (s *Service) reconcileCluster(ctx context.Context) error {
121121
return errors.Wrap(err, "failed reconciling cluster config")
122122
}
123123

124+
if err := s.reconcileAccessConfig(cluster.AccessConfig); err != nil {
125+
return errors.Wrap(err, "failed reconciling access config")
126+
}
127+
124128
if err := s.reconcileLogging(cluster.Logging); err != nil {
125129
return errors.Wrap(err, "failed reconciling logging")
126130
}
@@ -375,6 +379,13 @@ func (s *Service) createCluster(eksClusterName string) (*eks.Cluster, error) {
375379
return nil, errors.Wrap(err, "couldn't create vpc config for cluster")
376380
}
377381

382+
var accessConfig *eks.CreateAccessConfigRequest
383+
if s.scope.ControlPlane.Spec.AccessConfig != nil && s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode != "" {
384+
accessConfig = &eks.CreateAccessConfigRequest{
385+
AuthenticationMode: aws.String(string(s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode)),
386+
}
387+
}
388+
378389
var netConfig *eks.KubernetesNetworkConfigRequest
379390
if s.scope.VPC().IsIPv6Enabled() {
380391
netConfig = &eks.KubernetesNetworkConfigRequest{
@@ -416,13 +427,18 @@ func (s *Service) createCluster(eksClusterName string) (*eks.Cluster, error) {
416427
Name: aws.String(eksClusterName),
417428
Version: eksVersion,
418429
Logging: logging,
430+
AccessConfig: accessConfig,
419431
EncryptionConfig: encryptionConfigs,
420432
ResourcesVpcConfig: vpcConfig,
421433
RoleArn: role.Arn,
422434
Tags: tags,
423435
KubernetesNetworkConfig: netConfig,
424436
}
425437

438+
if err := input.Validate(); err != nil {
439+
return nil, errors.Wrap(err, "created invalid CreateClusterInput")
440+
}
441+
426442
var out *eks.CreateClusterOutput
427443
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
428444
if out, err = s.EKSClient.CreateCluster(input); err != nil {
@@ -501,6 +517,44 @@ func (s *Service) reconcileClusterConfig(cluster *eks.Cluster) error {
501517
return nil
502518
}
503519

520+
func (s *Service) reconcileAccessConfig(accessConfig *eks.AccessConfigResponse) error {
521+
input := eks.UpdateClusterConfigInput{Name: aws.String(s.scope.KubernetesClusterName())}
522+
523+
if s.scope.ControlPlane.Spec.AccessConfig == nil || s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode == "" {
524+
return nil
525+
}
526+
527+
expectedAuthenticationMode := string(s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode)
528+
if expectedAuthenticationMode != aws.StringValue(accessConfig.AuthenticationMode) {
529+
input.AccessConfig = &eks.UpdateAccessConfigRequest{
530+
AuthenticationMode: aws.String(expectedAuthenticationMode),
531+
}
532+
}
533+
534+
if input.AccessConfig != nil {
535+
if err := input.Validate(); err != nil {
536+
return errors.Wrap(err, "created invalid UpdateClusterConfigInput")
537+
}
538+
539+
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
540+
if _, err := s.EKSClient.UpdateClusterConfig(&input); err != nil {
541+
if aerr, ok := err.(awserr.Error); ok {
542+
return false, aerr
543+
}
544+
return false, err
545+
}
546+
conditions.MarkTrue(s.scope.ControlPlane, ekscontrolplanev1.EKSControlPlaneUpdatingCondition)
547+
record.Eventf(s.scope.ControlPlane, "InitiatedUpdateEKSControlPlane", "Initiated auth config update for EKS control plane %s", s.scope.KubernetesClusterName())
548+
return true, nil
549+
}); err != nil {
550+
record.Warnf(s.scope.ControlPlane, "FailedUpdateEKSControlPlane", "Failed to update EKS control plane auth config: %v", err)
551+
return errors.Wrapf(err, "failed to update EKS cluster")
552+
}
553+
}
554+
555+
return nil
556+
}
557+
504558
func (s *Service) reconcileLogging(logging *eks.Logging) error {
505559
input := eks.UpdateClusterConfigInput{Name: aws.String(s.scope.KubernetesClusterName())}
506560

0 commit comments

Comments
 (0)