Skip to content

Commit ace99cf

Browse files
authored
Allow specification of IAM permission boundary for Auto Mode's Node Role (#8307)
1 parent df9c8da commit ace99cf

5 files changed

Lines changed: 38 additions & 6 deletions

File tree

pkg/apis/eksctl.io/v1alpha5/assets/schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,17 @@
304304
"$ref": "#/definitions/ARN",
305305
"description": "node role to use for nodes launched by Auto Mode.",
306306
"x-intellij-html-description": "node role to use for nodes launched by Auto Mode."
307+
},
308+
"permissionsBoundaryARN": {
309+
"$ref": "#/definitions/ARN",
310+
"description": "permissions boundary to use when creating the Auto Mode node role.",
311+
"x-intellij-html-description": "permissions boundary to use when creating the Auto Mode node role."
307312
}
308313
},
309314
"preferredOrder": [
310315
"enabled",
311316
"nodeRoleARN",
317+
"permissionsBoundaryARN",
312318
"nodePools"
313319
],
314320
"additionalProperties": false

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type AutoModeConfig struct {
2020
Enabled *bool `json:"enabled,omitempty"`
2121
// NodeRoleARN is the node role to use for nodes launched by Auto Mode.
2222
NodeRoleARN ARN `json:"nodeRoleARN,omitempty"`
23+
// PermissionsBoundaryARN is the permissions boundary to use when creating the Auto Mode node role.
24+
PermissionsBoundaryARN ARN `json:"permissionsBoundaryARN,omitempty"`
2325
// NodePools is a list of node pools to create.
2426
NodePools *[]string `json:"nodePools,omitempty"`
2527
}
@@ -43,6 +45,12 @@ func ValidateAutoModeConfig(clusterConfig *ClusterConfig) error {
4345
if len(*autoModeConfig.NodePools) == 0 && !autoModeConfig.NodeRoleARN.IsZero() {
4446
return errors.New("cannot specify autoModeConfig.nodeRoleARN when autoModeConfig.nodePools is empty")
4547
}
48+
if len(*autoModeConfig.NodePools) == 0 && !autoModeConfig.PermissionsBoundaryARN.IsZero() {
49+
return errors.New("cannot specify autoModeConfig.permissionBoundaryARN when autoModeConfig.nodePools is empty")
50+
}
51+
if !autoModeConfig.NodeRoleARN.IsZero() && !autoModeConfig.PermissionsBoundaryARN.IsZero() {
52+
return errors.New("cannot specify autoModeConfig.permissionBoundaryARN when autoModeConfig.nodeRoleARN is set")
53+
}
4654
seenNodePools := map[string]struct{}{}
4755
for _, np := range *autoModeConfig.NodePools {
4856
if _, ok := seenNodePools[np]; ok {
@@ -54,8 +62,8 @@ func ValidateAutoModeConfig(clusterConfig *ClusterConfig) error {
5462
seenNodePools[np] = struct{}{}
5563
}
5664
}
57-
} else if !autoModeConfig.NodeRoleARN.IsZero() || autoModeConfig.HasNodePools() {
58-
return errors.New("cannot set autoModeConfig.nodeRoleARN or autoModeConfig.nodePools when Auto Mode is disabled")
65+
} else if !autoModeConfig.PermissionsBoundaryARN.IsZero() || !autoModeConfig.NodeRoleARN.IsZero() || autoModeConfig.HasNodePools() {
66+
return errors.New("cannot set autoModeConfig.nodeRoleARN, autoModeConfig.permissionBoundaryARN, or autoModeConfig.nodePools when Auto Mode is disabled")
5967
}
6068
return nil
6169
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,20 @@ var _ = DescribeTable("Auto Mode Validation", func(c *api.ClusterConfig, expecte
4242
NodeRoleARN: api.MustParseARN("arn:aws:iam::1234:role/CustomNodeRole"),
4343
NodePools: &[]string{api.AutoModeNodePoolGeneralPurpose},
4444
},
45-
}, "cannot set autoModeConfig.nodeRoleARN or autoModeConfig.nodePools when Auto Mode is disabled"),
45+
}, "cannot set autoModeConfig.nodeRoleARN, autoModeConfig.permissionBoundaryARN, or autoModeConfig.nodePools when Auto Mode is disabled"),
46+
Entry("permissionsBoundary and nodePools specified when Auto Mode is disabled", &api.ClusterConfig{
47+
AutoModeConfig: &api.AutoModeConfig{
48+
Enabled: api.Disabled(),
49+
PermissionsBoundaryARN: api.MustParseARN("arn:aws:iam::1234:policy/PermissionsBoundary"),
50+
NodePools: &[]string{api.AutoModeNodePoolGeneralPurpose},
51+
},
52+
}, "cannot set autoModeConfig.nodeRoleARN, autoModeConfig.permissionBoundaryARN, or autoModeConfig.nodePools when Auto Mode is disabled"),
53+
Entry("permissionsBoundary, nodeRoleARN, and nodePools specified", &api.ClusterConfig{
54+
AutoModeConfig: &api.AutoModeConfig{
55+
Enabled: api.Enabled(),
56+
NodeRoleARN: api.MustParseARN("arn:aws:iam::1234:role/CustomNodeRole"),
57+
PermissionsBoundaryARN: api.MustParseARN("arn:aws:iam::1234:policy/PermissionsBoundary"),
58+
NodePools: &[]string{api.AutoModeNodePoolGeneralPurpose},
59+
},
60+
}, "cannot specify autoModeConfig.permissionBoundaryARN when autoModeConfig.nodeRoleARN is set"),
4661
)

pkg/cfn/builder/auto_mode.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ type AutoModeRefs struct {
3131
NodeRole *gfnt.Value
3232
}
3333

34-
func AddAutoModeResources(clusterTemplate *gfn.Template) (AutoModeRefs, error) {
34+
func AddAutoModeResources(clusterTemplate *gfn.Template, permissionsBoundary string) (AutoModeRefs, error) {
3535
template, err := goformation.ParseYAML(autoModeNodeRoleTemplate)
3636
if err != nil {
3737
return AutoModeRefs{}, err
3838
}
39-
for resourceName, resource := range template.Resources {
39+
for resourceName, resource := range template.GetAllIAMRoleResources() {
40+
if permissionsBoundary != "" {
41+
resource.PermissionsBoundary = gfnt.NewString(permissionsBoundary)
42+
}
4043
clusterTemplate.Resources[resourceName] = resource
4144
}
4245
for key, output := range template.Outputs {

pkg/cfn/builder/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (c *ClusterResourceSet) addResourcesForControlPlane(subnetDetails *SubnetDe
338338
cluster.ComputeConfig = computeConfig
339339
if cc.NodeRoleARN.IsZero() {
340340
if cc.HasNodePools() {
341-
autoModeRefs, err := AddAutoModeResources(c.rs.template)
341+
autoModeRefs, err := AddAutoModeResources(c.rs.template, cc.PermissionsBoundaryARN.String())
342342
if err != nil {
343343
return fmt.Errorf("error building cluster compute roles: %w", err)
344344
}

0 commit comments

Comments
 (0)