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

[v17] Discover EKS: handle 'CONFIG_MAP' authentication mode gracefully #48293

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions lib/integrations/awsoidc/eks_enroll_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"fmt"
"log/slog"
"net/url"
"slices"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -375,6 +376,16 @@ func enrollEKSCluster(ctx context.Context, log *slog.Logger, clock clockwork.Clo
return "", trace.AccessDenied(`can't enroll %q because it is not accessible from Teleport Cloud, please enable endpoint public access in your EKS cluster and try again.`, clusterName)
}

// When clusters are using CONFIG_MAP, API is not acessible and thus Teleport can't install the Teleport's Helm chart.
// You can read more about the Authentication Modes here: https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/
allowedAuthModes := []eksTypes.AuthenticationMode{
eksTypes.AuthenticationModeApi,
eksTypes.AuthenticationModeApiAndConfigMap,
}
if !slices.Contains(allowedAuthModes, eksCluster.AccessConfig.AuthenticationMode) {
return "", trace.BadParameter("can't enroll %q because its access config's authentication mode is %q, only %v are supported", clusterName, eksCluster.AccessConfig.AuthenticationMode, allowedAuthModes)
}

principalArn, err := getAccessEntryPrincipalArn(ctx, clt.GetCallerIdentity)
if err != nil {
return "", trace.Wrap(err)
Expand Down
35 changes: 35 additions & 0 deletions lib/integrations/awsoidc/eks_enroll_clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func TestEnrollEKSClusters(t *testing.T) {
Tags: map[string]string{"label1": "value1"},
CertificateAuthority: &eksTypes.Certificate{Data: aws.String(testCAData)},
Status: eksTypes.ClusterStatusActive,
AccessConfig: &eksTypes.AccessConfigResponse{
AuthenticationMode: eksTypes.AuthenticationModeApiAndConfigMap,
},
},
{
Name: aws.String("EKS2"),
Expand All @@ -108,6 +111,9 @@ func TestEnrollEKSClusters(t *testing.T) {
Tags: map[string]string{"label2": "value2"},
CertificateAuthority: &eksTypes.Certificate{Data: aws.String(testCAData)},
Status: eksTypes.ClusterStatusActive,
AccessConfig: &eksTypes.AccessConfigResponse{
AuthenticationMode: eksTypes.AuthenticationModeApiAndConfigMap,
},
},
}

Expand Down Expand Up @@ -237,6 +243,29 @@ func TestEnrollEKSClusters(t *testing.T) {
`can't enroll EKS cluster "EKS1" - expected "ACTIVE" state, got "PENDING".`)
},
},
{
name: "cluster with CONFIG_MAP authentication mode is not enrolled",
enrollClient: baseClient,
eksClusters: []eksTypes.Cluster{
{
Name: aws.String("EKS1"),
Arn: aws.String(clustersBaseArn + "1"),
Tags: map[string]string{"label1": "value1"},
CertificateAuthority: &eksTypes.Certificate{Data: aws.String(testCAData)},
Status: eksTypes.ClusterStatusActive,
AccessConfig: &eksTypes.AccessConfigResponse{
AuthenticationMode: eksTypes.AuthenticationModeConfigMap,
},
},
},
request: baseRequest,
requestClusterNames: []string{"EKS1"},
responseCheck: func(t *testing.T, response *EnrollEKSClusterResponse) {
require.Len(t, response.Results, 1)
require.ErrorContains(t, response.Results[0].Error,
`can't enroll "EKS1" because its access config's authentication mode is "CONFIG_MAP", only [API API_AND_CONFIG_MAP] are supported`)
},
},
{
name: "private cluster in cloud is not enrolled",
enrollClient: baseClient,
Expand All @@ -250,6 +279,9 @@ func TestEnrollEKSClusters(t *testing.T) {
Tags: map[string]string{"label3": "value3"},
CertificateAuthority: &eksTypes.Certificate{Data: aws.String(testCAData)},
Status: eksTypes.ClusterStatusActive,
AccessConfig: &eksTypes.AccessConfigResponse{
AuthenticationMode: eksTypes.AuthenticationModeApiAndConfigMap,
},
},
},
request: EnrollEKSClustersRequest{
Expand Down Expand Up @@ -279,6 +311,9 @@ func TestEnrollEKSClusters(t *testing.T) {
Tags: map[string]string{"label3": "value3"},
CertificateAuthority: &eksTypes.Certificate{Data: aws.String(testCAData)},
Status: eksTypes.ClusterStatusActive,
AccessConfig: &eksTypes.AccessConfigResponse{
AuthenticationMode: eksTypes.AuthenticationModeApiAndConfigMap,
},
},
},
request: EnrollEKSClustersRequest{
Expand Down
Loading