Skip to content

Commit d224304

Browse files
adammwjoshfrench
authored andcommitted
feat: support setting EKS AuthenticationMode
1 parent 47820e4 commit d224304

File tree

6 files changed

+109
-86
lines changed

6 files changed

+109
-86
lines changed

config/crd/bases/controlplane.cluster.x-k8s.io_awsmanagedcontrolplanes.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,21 @@ spec:
22082208
description: AWSManagedControlPlaneSpec defines the desired state of an
22092209
Amazon EKS Cluster.
22102210
properties:
2211+
accessConfig:
2212+
description: AccessConfig specifies the access configuration information
2213+
for the cluster
2214+
properties:
2215+
authenticationMode:
2216+
default: CONFIG_MAP
2217+
description: |-
2218+
AuthenticationMode specifies the desired authentication mode for the cluster
2219+
Defaults to CONFIG_MAP
2220+
enum:
2221+
- CONFIG_MAP
2222+
- API
2223+
- API_AND_CONFIG_MAP
2224+
type: string
2225+
type: object
22112226
additionalTags:
22122227
additionalProperties:
22132228
type: string
@@ -3010,7 +3025,7 @@ spec:
30103025
type: object
30113026
oidcIdentityProviderConfig:
30123027
description: |-
3013-
IdentityProviderconfig is used to specify the oidc provider config
3028+
OIDCIdentityProviderConfig is used to specify the oidc provider config
30143029
to be attached with this eks cluster
30153030
properties:
30163031
clientId:

controlplane/eks/api/v1beta1/zz_generated.conversion.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go

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

190-
// IdentityProviderconfig is used to specify the oidc provider config
190+
// OIDCIdentityProviderConfig is used to specify the oidc provider config
191191
// to be attached with this eks cluster
192192
// +optional
193193
OIDCIdentityProviderConfig *OIDCIdentityProviderConfig `json:"oidcIdentityProviderConfig,omitempty"`
194194

195+
// AccessConfig specifies the access configuration information for the cluster
196+
// +optional
197+
AccessConfig *AccessConfig `json:"accessConfig,omitempty"`
198+
195199
// VpcCni is used to set configuration options for the VPC CNI plugin
196200
// +optional
197201
VpcCni VpcCni `json:"vpcCni,omitempty"`
@@ -248,6 +252,15 @@ type EndpointAccess struct {
248252
Private *bool `json:"private,omitempty"`
249253
}
250254

255+
// AccessConfig represents the access configuration information for the cluster
256+
type AccessConfig struct {
257+
// AuthenticationMode specifies the desired authentication mode for the cluster
258+
// Defaults to CONFIG_MAP
259+
// +kubebuilder:default=CONFIG_MAP
260+
// +kubebuilder:validation:Enum=CONFIG_MAP;API;API_AND_CONFIG_MAP
261+
AuthenticationMode EKSAuthenticationMode `json:"authenticationMode,omitempty"`
262+
}
263+
251264
// EncryptionConfig specifies the encryption configuration for the EKS clsuter.
252265
type EncryptionConfig struct {
253266
// 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

controlplane/eks/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 9 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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(ctx, cluster.Logging); err != nil {
125129
return errors.Wrap(err, "failed reconciling logging")
126130
}
@@ -422,6 +426,13 @@ func (s *Service) createCluster(ctx context.Context, eksClusterName string) (*ek
422426
return nil, errors.Wrap(err, "couldn't create vpc config for cluster")
423427
}
424428

429+
var accessConfig *ekstypes.CreateAccessConfigRequest
430+
if s.scope.ControlPlane.Spec.AccessConfig != nil && s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode != "" {
431+
accessConfig = &ekstypes.CreateAccessConfigRequest{
432+
AuthenticationMode: string(s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode),
433+
}
434+
}
435+
425436
var netConfig *ekstypes.KubernetesNetworkConfigRequest
426437
if s.scope.VPC().IsIPv6Enabled() {
427438
netConfig = &ekstypes.KubernetesNetworkConfigRequest{
@@ -465,6 +476,7 @@ func (s *Service) createCluster(ctx context.Context, eksClusterName string) (*ek
465476
Name: aws.String(eksClusterName),
466477
Version: eksVersion,
467478
Logging: logging,
479+
AccessConfig: accessConfig,
468480
EncryptionConfig: encryptionConfigs,
469481
ResourcesVpcConfig: vpcConfig,
470482
RoleArn: role.Arn,
@@ -473,6 +485,10 @@ func (s *Service) createCluster(ctx context.Context, eksClusterName string) (*ek
473485
BootstrapSelfManagedAddons: bootstrapAddon,
474486
}
475487

488+
if err := input.Validate(); err != nil {
489+
return nil, errors.Wrap(err, "created invalid CreateClusterInput")
490+
}
491+
476492
var out *eks.CreateClusterOutput
477493
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
478494
if out, err = s.EKSClient.CreateCluster(ctx, input); err != nil {
@@ -542,6 +558,44 @@ func (s *Service) reconcileClusterConfig(ctx context.Context, cluster *ekstypes.
542558
return nil
543559
}
544560

561+
func (s *Service) reconcileAccessConfig(accessConfig *ekstypes.AccessConfigResponse) error {
562+
input := &eks.UpdateClusterConfigInput{Name: aws.String(s.scope.KubernetesClusterName())}
563+
564+
if s.scope.ControlPlane.Spec.AccessConfig == nil || s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode == "" {
565+
return nil
566+
}
567+
568+
expectedAuthenticationMode := string(s.scope.ControlPlane.Spec.AccessConfig.AuthenticationMode)
569+
if expectedAuthenticationMode != accessConfig.AuthenticationMode {
570+
input.AccessConfig = &eks.UpdateAccessConfigRequest{
571+
AuthenticationMode: aws.String(expectedAuthenticationMode),
572+
}
573+
}
574+
575+
if input.AccessConfig != nil {
576+
if err := input.Validate(); err != nil {
577+
return errors.Wrap(err, "created invalid UpdateClusterConfigInput")
578+
}
579+
580+
if err := wait.WaitForWithRetryable(wait.NewBackoff(), func() (bool, error) {
581+
if _, err := s.EKSClient.UpdateClusterConfig(input); err != nil {
582+
if aerr, ok := err.(awserr.Error); ok {
583+
return false, aerr
584+
}
585+
return false, err
586+
}
587+
conditions.MarkTrue(s.scope.ControlPlane, ekscontrolplanev1.EKSControlPlaneUpdatingCondition)
588+
record.Eventf(s.scope.ControlPlane, "InitiatedUpdateEKSControlPlane", "Initiated auth config update for EKS control plane %s", s.scope.KubernetesClusterName())
589+
return true, nil
590+
}); err != nil {
591+
record.Warnf(s.scope.ControlPlane, "FailedUpdateEKSControlPlane", "Failed to update EKS control plane auth config: %v", err)
592+
return errors.Wrapf(err, "failed to update EKS cluster")
593+
}
594+
}
595+
596+
return nil
597+
}
598+
545599
func (s *Service) reconcileLogging(ctx context.Context, logging *ekstypes.Logging) error {
546600
input := &eks.UpdateClusterConfigInput{Name: aws.String(s.scope.KubernetesClusterName())}
547601

0 commit comments

Comments
 (0)