Skip to content

Commit 66d1a5e

Browse files
authored
Enforce authenticationMode:CONFIG_MAP on Outposts (#7699)
Make authenticationMode:CONFIG_MAP default on Outposts
1 parent 2addd3a commit 66d1a5e

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

pkg/apis/eksctl.io/v1alpha5/defaults.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func SetClusterConfigDefaults(cfg *ClusterConfig) {
5656

5757
if cfg.AccessConfig == nil {
5858
cfg.AccessConfig = &AccessConfig{
59-
AuthenticationMode: ekstypes.AuthenticationModeApiAndConfigMap,
59+
AuthenticationMode: getDefaultAuthenticationMode(cfg.IsControlPlaneOnOutposts()),
6060
}
6161
} else if cfg.AccessConfig.AuthenticationMode == "" {
62-
cfg.AccessConfig.AuthenticationMode = ekstypes.AuthenticationModeApiAndConfigMap
62+
cfg.AccessConfig.AuthenticationMode = getDefaultAuthenticationMode(cfg.IsControlPlaneOnOutposts())
6363
}
6464

6565
if cfg.PrivateCluster == nil {
@@ -244,6 +244,13 @@ func getDefaultVolumeType(nodeGroupOnOutposts bool) string {
244244
return DefaultNodeVolumeType
245245
}
246246

247+
func getDefaultAuthenticationMode(nodeGroupOnOutposts bool) ekstypes.AuthenticationMode {
248+
if nodeGroupOnOutposts {
249+
return ekstypes.AuthenticationModeConfigMap
250+
}
251+
return ekstypes.AuthenticationModeApiAndConfigMap
252+
}
253+
247254
func setContainerRuntimeDefault(ng *NodeGroup, clusterVersion string) {
248255
if ng.ContainerRuntime != nil {
249256
return

pkg/apis/eksctl.io/v1alpha5/defaults_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"github.com/aws/aws-sdk-go-v2/aws"
55
. "github.com/onsi/ginkgo/v2"
66
. "github.com/onsi/gomega"
7+
8+
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
79
)
810

911
var _ = Describe("ClusterConfig validation", func() {
@@ -338,6 +340,29 @@ var _ = Describe("ClusterConfig validation", func() {
338340

339341
})
340342

343+
Context("Authentication Mode", func() {
344+
var (
345+
cfg *ClusterConfig
346+
)
347+
348+
BeforeEach(func() {
349+
cfg = NewClusterConfig()
350+
})
351+
352+
It("should be set to API_AND_CONFIG_MAP by default", func() {
353+
SetClusterConfigDefaults(cfg)
354+
Expect(cfg.AccessConfig.AuthenticationMode).To(Equal(ekstypes.AuthenticationModeApiAndConfigMap))
355+
})
356+
357+
It("should be set to CONFIG_MAP when control plane is on outposts", func() {
358+
cfg.Outpost = &Outpost{
359+
ControlPlaneOutpostARN: "arn:aws:outposts:us-west-2:1234:outpost/op-1234",
360+
}
361+
SetClusterConfigDefaults(cfg)
362+
Expect(cfg.AccessConfig.AuthenticationMode).To(Equal(ekstypes.AuthenticationModeConfigMap))
363+
})
364+
})
365+
341366
Describe("ClusterConfig", func() {
342367
var cfg *ClusterConfig
343368

pkg/apis/eksctl.io/v1alpha5/outposts_validation_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
. "github.com/onsi/ginkgo/v2"
77
. "github.com/onsi/gomega"
88

9+
"github.com/aws/aws-sdk-go-v2/aws"
10+
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
11+
912
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
1013
)
1114

@@ -22,10 +25,29 @@ var _ = Describe("Outposts validation", func() {
2225
clusterConfig.Outpost = &api.Outpost{
2326
ControlPlaneOutpostARN: "arn:aws:outposts:us-west-2:1234:outpost/op-1234",
2427
}
28+
api.SetClusterConfigDefaults(clusterConfig)
2529
oe.updateDefaultConfig(clusterConfig)
2630
err := api.ValidateClusterConfig(clusterConfig)
2731
Expect(err).To(MatchError(ContainSubstring(oe.expectedErr)))
2832
},
33+
Entry("Authentication Mode - API", outpostsEntry{
34+
updateDefaultConfig: func(c *api.ClusterConfig) {
35+
c.AccessConfig.AuthenticationMode = ekstypes.AuthenticationModeApi
36+
},
37+
expectedErr: fmt.Sprintf("accessConfig.AuthenticationMode must be set to %s on Outposts", ekstypes.AuthenticationModeConfigMap),
38+
}),
39+
Entry("Authentication mode - API_AND_CONFIG_MAP", outpostsEntry{
40+
updateDefaultConfig: func(c *api.ClusterConfig) {
41+
c.AccessConfig.AuthenticationMode = ekstypes.AuthenticationModeApiAndConfigMap
42+
},
43+
expectedErr: fmt.Sprintf("accessConfig.AuthenticationMode must be set to %s on Outposts", ekstypes.AuthenticationModeConfigMap),
44+
}),
45+
Entry("BootstrapClusterCreatorAdminPermissions - false", outpostsEntry{
46+
updateDefaultConfig: func(c *api.ClusterConfig) {
47+
c.AccessConfig.BootstrapClusterCreatorAdminPermissions = aws.Bool(false)
48+
},
49+
expectedErr: "accessConfig.BootstrapClusterCreatorAdminPermissions can't be set to false on Outposts",
50+
}),
2951
Entry("Addons", outpostsEntry{
3052
updateDefaultConfig: func(c *api.ClusterConfig) {
3153
c.Addons = []*api.Addon{

pkg/apis/eksctl.io/v1alpha5/validation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ func ValidateClusterConfig(cfg *ClusterConfig) error {
162162
return err
163163
}
164164

165+
if cfg.AccessConfig.AuthenticationMode != ekstypes.AuthenticationModeConfigMap {
166+
return fmt.Errorf("accessConfig.AuthenticationMode must be set to %s on Outposts", ekstypes.AuthenticationModeConfigMap)
167+
}
168+
if IsDisabled(cfg.AccessConfig.BootstrapClusterCreatorAdminPermissions) {
169+
return fmt.Errorf("accessConfig.BootstrapClusterCreatorAdminPermissions can't be set to false on Outposts")
170+
}
165171
if cfg.IPv6Enabled() {
166172
return errors.New("IPv6 is not supported on Outposts")
167173
}

0 commit comments

Comments
 (0)