-
Couldn't load subscription status.
- Fork 635
✨ feat: Support Access Entries #5583
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,7 @@ func (*awsManagedControlPlaneWebhook) ValidateCreate(_ context.Context, obj runt | |
| allErrs = append(allErrs, r.validateNetwork()...) | ||
| allErrs = append(allErrs, r.validatePrivateDNSHostnameTypeOnLaunch()...) | ||
| allErrs = append(allErrs, r.validateAccessConfigCreate()...) | ||
| allErrs = append(allErrs, r.validateAccessEntries()...) | ||
|
|
||
| if len(allErrs) == 0 { | ||
| return nil, nil | ||
|
|
@@ -150,6 +151,7 @@ func (*awsManagedControlPlaneWebhook) ValidateUpdate(ctx context.Context, oldObj | |
| allErrs = append(allErrs, r.validateKubeProxy()...) | ||
| allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...) | ||
| allErrs = append(allErrs, r.validatePrivateDNSHostnameTypeOnLaunch()...) | ||
| allErrs = append(allErrs, r.validateAccessEntries()...) | ||
|
|
||
| if r.Spec.Region != oldAWSManagedControlplane.Spec.Region { | ||
| allErrs = append(allErrs, | ||
|
|
@@ -367,6 +369,61 @@ func (r *AWSManagedControlPlane) validateAccessConfigCreate() field.ErrorList { | |
| return allErrs | ||
| } | ||
|
|
||
| func (r *AWSManagedControlPlane) validateAccessEntries() field.ErrorList { | ||
| var allErrs field.ErrorList | ||
|
|
||
| if len(r.Spec.AccessEntries) > 0 { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid this indentation by returning early |
||
| // AccessEntries require AuthenticationMode to be api or api_and_config_map | ||
| if r.Spec.AccessConfig == nil || | ||
| (r.Spec.AccessConfig.AuthenticationMode != EKSAuthenticationModeAPI && | ||
| r.Spec.AccessConfig.AuthenticationMode != EKSAuthenticationModeAPIAndConfigMap) { | ||
| allErrs = append(allErrs, | ||
| field.Invalid(field.NewPath("spec", "accessEntries"), | ||
| r.Spec.AccessEntries, | ||
| "accessEntries can only be used when authenticationMode is set to api or api_and_config_map", | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| for i, entry := range r.Spec.AccessEntries { | ||
| // Validate that EC2 types don't have kubernetes groups or access policies | ||
| if entry.Type == AccessEntryTypeEC2Linux || entry.Type == AccessEntryTypeEC2Windows { | ||
| if len(entry.KubernetesGroups) > 0 { | ||
| allErrs = append(allErrs, | ||
| field.Invalid(field.NewPath("spec", "accessEntries").Index(i).Child("kubernetesGroups"), | ||
| entry.KubernetesGroups, | ||
| "kubernetesGroups cannot be specified when type is ec2_linux or ec2_windows", | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| if len(entry.AccessPolicies) > 0 { | ||
| allErrs = append(allErrs, | ||
| field.Invalid(field.NewPath("spec", "accessEntries").Index(i).Child("accessPolicies"), | ||
| entry.AccessPolicies, | ||
| "accessPolicies cannot be specified when type is ec2_linux or ec2_windows", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // Validate namespace scopes | ||
| for j, policy := range entry.AccessPolicies { | ||
| if policy.AccessScope.Type == AccessScopeTypeNamespace && len(policy.AccessScope.Namespaces) == 0 { | ||
| allErrs = append(allErrs, | ||
| field.Invalid(field.NewPath("spec", "accessEntries").Index(i).Child("accessPolicies").Index(j).Child("accessScope", "namespaces"), | ||
| policy.AccessScope.Namespaces, | ||
| "at least one value must be provided when accessScope type is namespace", | ||
| ), | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return allErrs | ||
| } | ||
|
|
||
| func (r *AWSManagedControlPlane) validateIAMAuthConfig() field.ErrorList { | ||
| return validateIAMAuthConfig(r.Spec.IAMAuthenticatorConfig, field.NewPath("spec.iamAuthenticatorConfig")) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to move this into the
AccessConfigstruct asEntries?It feels to me that the entries should be a child of the config.