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

✨ Support setting role path and permissions boundary on managed IAM roles #5286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions cmd/clusterawsadm/api/bootstrap/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ import (
func Convert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec(in *v1beta1.AWSIAMConfigurationSpec, out *AWSIAMConfigurationSpec, s conversion.Scope) error {
return autoConvert_v1beta1_AWSIAMConfigurationSpec_To_v1alpha1_AWSIAMConfigurationSpec(in, out, s)
}

func Convert_v1beta1_AWSIAMRoleSpec_To_v1alpha1_AWSIAMRoleSpec(in *v1beta1.AWSIAMRoleSpec, out *AWSIAMRoleSpec, s conversion.Scope) error {
return autoConvert_v1beta1_AWSIAMRoleSpec_To_v1alpha1_AWSIAMRoleSpec(in, out, s)
}
77 changes: 61 additions & 16 deletions cmd/clusterawsadm/api/bootstrap/v1alpha1/zz_generated.conversion.go

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

8 changes: 8 additions & 0 deletions cmd/clusterawsadm/api/bootstrap/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ type AWSIAMRoleSpec struct {
// ExtraStatements are additional IAM statements to be included inline for the role.
ExtraStatements []iamv1.StatementEntry `json:"extraStatements,omitempty"`

// Path sets the path to the role.
// +optional
Path string `json:"path,omitempty"`

// PermissionsBoundary sets the ARN of the managed policy that is used to set the permissions boundary for the role.
// +optional
PermissionsBoundary string `json:"permissionsBoundary,omitempty"`

// TrustStatements is an IAM PolicyDocument defining what identities are allowed to assume this role.
// See "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/api/iam/v1beta1" for more documentation.
TrustStatements []iamv1.StatementEntry `json:"trustStatements,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions cmd/clusterawsadm/cloudformation/bootstrap/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,30 @@ func (t Template) RenderCloudFormation() *cloudformation.Template {

template.Resources[AWSIAMRoleControlPlane] = &cfn_iam.Role{
RoleName: t.NewManagedName("control-plane"),
Path: t.Spec.ControlPlane.Path,
AssumeRolePolicyDocument: t.controlPlaneTrustPolicy(),
ManagedPolicyArns: t.Spec.ControlPlane.ExtraPolicyAttachments,
Policies: t.controlPlanePolicies(),
PermissionsBoundary: t.Spec.ControlPlane.PermissionsBoundary,
Tags: converters.MapToCloudFormationTags(t.Spec.ControlPlane.Tags),
}

template.Resources[AWSIAMRoleControllers] = &cfn_iam.Role{
RoleName: t.NewManagedName("controllers"),
Path: t.Spec.ControlPlane.Path,
AssumeRolePolicyDocument: t.controllersTrustPolicy(),
Policies: t.controllersRolePolicy(),
PermissionsBoundary: t.Spec.ControlPlane.PermissionsBoundary,
Tags: converters.MapToCloudFormationTags(t.Spec.ClusterAPIControllers.Tags),
}

template.Resources[AWSIAMRoleNodes] = &cfn_iam.Role{
RoleName: t.NewManagedName("nodes"),
Path: t.Spec.ControlPlane.Path,
AssumeRolePolicyDocument: t.nodeTrustPolicy(),
ManagedPolicyArns: t.nodeManagedPolicies(),
Policies: t.nodePolicies(),
PermissionsBoundary: t.Spec.ControlPlane.PermissionsBoundary,
Tags: converters.MapToCloudFormationTags(t.Spec.Nodes.Tags),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,30 @@ spec:
and no name is supplied then a role is created.
minLength: 2
type: string
rolePath:
description: |-
RolePath sets the path to the role. For more information about paths, see IAM Identifiers
(https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html)
in the IAM User Guide.

This parameter is optional. If it is not included, it defaults to a slash
(/).
type: string
rolePermissionsBoundary:
description: |-
RolePermissionsBoundary sets the ARN of the managed policy that is used
to set the permissions boundary for the role.

A permissions boundary policy defines the maximum permissions that identity-based
policies can grant to an entity, but does not grant permissions. Permissions
boundaries do not define the maximum permissions that a resource-based policy
can grant to an entity. To learn more, see Permissions boundaries for IAM
entities (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)
in the IAM User Guide.

For more information about policy types, see Policy types (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policy-types)
in the IAM User Guide.
type: string
secondaryCidrBlock:
description: |-
SecondaryCidrBlock is the additional CIDR range to use for pod IPs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,30 @@ spec:
and not delete it on deletion. If the EKSEnableIAM feature
flag is true and no name is supplied then a role is created.
type: string
rolePath:
description: |-
RolePath sets the path to the role. For more information about paths, see IAM Identifiers
(https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html)
in the IAM User Guide.

This parameter is optional. If it is not included, it defaults to a slash
(/).
type: string
rolePermissionsBoundary:
description: |-
RolePermissionsBoundary sets the ARN of the managed policy that is used
to set the permissions boundary for the role.

A permissions boundary policy defines the maximum permissions that identity-based
policies can grant to an entity, but does not grant permissions. Permissions
boundaries do not define the maximum permissions that a resource-based policy
can grant to an entity. To learn more, see Permissions boundaries for IAM
entities (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)
in the IAM User Guide.

For more information about policy types, see Policy types (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policy-types)
in the IAM User Guide.
type: string
selectors:
description: Selectors specify fargate pod selectors.
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,30 @@ spec:
and not delete it on deletion. If the EKSEnableIAM feature
flag is true and no name is supplied then a role is created.
type: string
rolePath:
description: |-
RolePath sets the path to the role. For more information about paths, see IAM Identifiers
(https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html)
in the IAM User Guide.

This parameter is optional. If it is not included, it defaults to a slash
(/).
type: string
rolePermissionsBoundary:
description: |-
RolePermissionsBoundary sets the ARN of the managed policy that is used
to set the permissions boundary for the role.

A permissions boundary policy defines the maximum permissions that identity-based
policies can grant to an entity, but does not grant permissions. Permissions
boundaries do not define the maximum permissions that a resource-based policy
can grant to an entity. To learn more, see Permissions boundaries for IAM
entities (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)
in the IAM User Guide.

For more information about policy types, see Policy types (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policy-types)
in the IAM User Guide.
type: string
scaling:
description: Scaling specifies scaling for the ASG behind this pool
properties:
Expand Down
2 changes: 2 additions & 0 deletions controlplane/eks/api/v1beta1/zz_generated.conversion.go

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

24 changes: 24 additions & 0 deletions controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,30 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
// +optional
RoleAdditionalPolicies *[]string `json:"roleAdditionalPolicies,omitempty"`

// RolePath sets the path to the role. For more information about paths, see IAM Identifiers
// (https://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html)
// in the IAM User Guide.
//
// This parameter is optional. If it is not included, it defaults to a slash
// (/).
// +optional
RolePath string `json:"rolePath,omitempty"`

// RolePermissionsBoundary sets the ARN of the managed policy that is used
// to set the permissions boundary for the role.
//
// A permissions boundary policy defines the maximum permissions that identity-based
// policies can grant to an entity, but does not grant permissions. Permissions
// boundaries do not define the maximum permissions that a resource-based policy
// can grant to an entity. To learn more, see Permissions boundaries for IAM
// entities (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html)
// in the IAM User Guide.
//
// For more information about policy types, see Policy types (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#access_policy-types)
// in the IAM User Guide.
// +optional
RolePermissionsBoundary string `json:"rolePermissionsBoundary,omitempty"`

// Logging specifies which EKS Cluster logs should be enabled. Entries for
// each of the enabled logs will be sent to CloudWatch
// +optional
Expand Down
30 changes: 28 additions & 2 deletions exp/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (src *AWSManagedMachinePool) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.AvailabilityZoneSubnetType = restored.Spec.AvailabilityZoneSubnetType
}

dst.Spec.RolePath = restored.Spec.RolePath
dst.Spec.RolePermissionsBoundary = restored.Spec.RolePermissionsBoundary

return nil
}

Expand Down Expand Up @@ -149,14 +152,33 @@ func (r *AWSManagedMachinePoolList) ConvertFrom(srcRaw conversion.Hub) error {
// ConvertTo converts the v1beta1 AWSFargateProfile receiver to a v1beta2 AWSFargateProfile.
func (src *AWSFargateProfile) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1exp.AWSFargateProfile)
return Convert_v1beta1_AWSFargateProfile_To_v1beta2_AWSFargateProfile(src, dst, nil)

if err := Convert_v1beta1_AWSFargateProfile_To_v1beta2_AWSFargateProfile(src, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &infrav1exp.AWSFargateProfile{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

dst.Spec.RolePath = restored.Spec.RolePath
dst.Spec.RolePermissionsBoundary = restored.Spec.RolePermissionsBoundary

return nil
}

// ConvertFrom converts the v1beta2 AWSFargateProfile receiver to v1beta1 AWSFargateProfile.
func (r *AWSFargateProfile) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1exp.AWSFargateProfile)

return Convert_v1beta2_AWSFargateProfile_To_v1beta1_AWSFargateProfile(src, r, nil)
if err := Convert_v1beta2_AWSFargateProfile_To_v1beta1_AWSFargateProfile(src, r, nil); err != nil {
return err
}

// Preserve Hub data on down-conversion.
return utilconversion.MarshalData(src, r)
}

// ConvertTo converts the v1beta1 AWSFargateProfileList receiver to a v1beta2 AWSFargateProfileList.
Expand Down Expand Up @@ -219,3 +241,7 @@ func Convert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in *infrav
// spec.refreshPreferences.disable has been added to v1beta2.
return autoConvert_v1beta2_RefreshPreferences_To_v1beta1_RefreshPreferences(in, out, s)
}

func Convert_v1beta2_FargateProfileSpec_To_v1beta1_FargateProfileSpec(in *infrav1exp.FargateProfileSpec, out *FargateProfileSpec, s apiconversion.Scope) error {
return autoConvert_v1beta2_FargateProfileSpec_To_v1beta1_FargateProfileSpec(in, out, s)
}
Loading