Skip to content

Commit

Permalink
Add VPCResourceController policy and opt-out (eksctl-io#2610)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeaumont authored Sep 3, 2020
1 parent d9a8451 commit fe364e1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion pkg/apis/eksctl.io/v1alpha5/assets/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
"description": "permissions boundary for all identity-based entities created by eksctl. See [AWS Permission Boundary](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)",
"x-intellij-html-description": "permissions boundary for all identity-based entities created by eksctl. See <a href=\"https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html\">AWS Permission Boundary</a>"
},
"vpcResourceControllerPolicy": {
"type": "boolean",
"description": "attaches the IAM policy necessary to run the VPC controller in the control plane",
"x-intellij-html-description": "attaches the IAM policy necessary to run the VPC controller in the control plane",
"default": true
},
"withOIDC": {
"type": "boolean",
"description": "enables the IAM OIDC provider",
Expand All @@ -194,7 +200,8 @@
"fargatePodExecutionRoleARN",
"fargatePodExecutionRolePermissionsBoundary",
"withOIDC",
"serviceAccounts"
"serviceAccounts",
"vpcResourceControllerPolicy"
],
"additionalProperties": false,
"description": "holds all IAM attributes of a cluster",
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func SetClusterConfigDefaults(cfg *ClusterConfig) {
cfg.IAM.WithOIDC = Disabled()
}

if cfg.IAM.VPCResourceControllerPolicy == nil {
cfg.IAM.VPCResourceControllerPolicy = Enabled()
}

for _, sa := range cfg.IAM.ServiceAccounts {
if sa.Namespace == "" {
sa.Namespace = metav1.NamespaceDefault
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type ClusterIAM struct {
// See [IAM Service Accounts](/iamserviceaccounts/#usage-with-config-files)
// +optional
ServiceAccounts []*ClusterIAMServiceAccount `json:"serviceAccounts,omitempty"`

// VPCResourceControllerPolicy attaches the IAM policy
// necessary to run the VPC controller in the control plane
// Defaults to `true`
VPCResourceControllerPolicy *bool `json:"vpcResourceControllerPolicy,omitempty"`
}

// ClusterIAMMeta holds information we can use to create ObjectMeta for service
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/eksctl.io/v1alpha5/schema.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(clusterTemplate.Resources["ServiceRole"].Properties).ToNot(BeNil())

Expect(clusterTemplate.Resources["ServiceRole"].Properties.ManagedPolicyArns).To(Equal(
makePolicyARNRef("AmazonEKSClusterPolicy")),
makePolicyARNRef("AmazonEKSClusterPolicy", "AmazonEKSVPCResourceController")),
)

checkARPD([]string{"EKS", "EKSFargatePods"}, clusterTemplate.Resources["ServiceRole"].Properties.AssumeRolePolicyDocument)
Expand Down
14 changes: 10 additions & 4 deletions pkg/cfn/builder/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
)

const (
iamPolicyAmazonEKSClusterPolicy = "AmazonEKSClusterPolicy"
iamPolicyAmazonEKSClusterPolicy = "AmazonEKSClusterPolicy"
iamPolicyAmazonEKSVPCResourceController = "AmazonEKSVPCResourceController"

iamPolicyAmazonEKSWorkerNodePolicy = "AmazonEKSWorkerNodePolicy"
iamPolicyAmazonEKSCNIPolicy = "AmazonEKS_CNI_Policy"
Expand Down Expand Up @@ -71,16 +72,21 @@ func (c *ClusterResourceSet) addResourcesForIAM() {

c.rs.withIAM = true

managedPolicyArns := []string{
iamPolicyAmazonEKSClusterPolicy,
}
if !api.IsDisabled(c.spec.IAM.VPCResourceControllerPolicy) {
managedPolicyArns = append(managedPolicyArns, iamPolicyAmazonEKSVPCResourceController)
}

role := &gfniam.Role{
AssumeRolePolicyDocument: cft.MakeAssumeRolePolicyDocumentForServices(
MakeServiceRef("EKS"),
// Ensure that EKS can schedule pods onto Fargate, should the user
// define so-called "Fargate profiles" in order to do so:
MakeServiceRef("EKSFargatePods"),
),
ManagedPolicyArns: gfnt.NewSlice(makePolicyARNs(
iamPolicyAmazonEKSClusterPolicy,
)...),
ManagedPolicyArns: gfnt.NewSlice(makePolicyARNs(managedPolicyArns...)...),
}
if api.IsSetAndNonEmptyString(c.spec.IAM.ServiceRolePermissionsBoundary) {
role.PermissionsBoundary = gfnt.NewString(*c.spec.IAM.ServiceRolePermissionsBoundary)
Expand Down

0 comments on commit fe364e1

Please sign in to comment.