Skip to content

Add CertficateArn field to IngressClassParam #3616

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

Merged
merged 1 commit into from
May 6, 2024
Merged
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 apis/elbv2/v1beta1/ingressclassparams_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ type Attribute struct {

// IngressClassParamsSpec defines the desired state of IngressClassParams
type IngressClassParamsSpec struct {
// CertificateARN specifies the ARN of the certificates for all Ingresses that belong to IngressClass with this IngressClassParams.
// +optional
CertficateArn []string `json:"certficateArn,omitempty"`

// NamespaceSelector restrict the namespaces of Ingresses that are allowed to specify the IngressClass with this IngressClassParams.
// * if absent or present but empty, it selects all namespaces.
// +optional
Expand Down
5 changes: 5 additions & 0 deletions apis/elbv2/v1beta1/zz_generated.deepcopy.go

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

6 changes: 6 additions & 0 deletions config/crd/bases/elbv2.k8s.aws_ingressclassparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ spec:
spec:
description: IngressClassParamsSpec defines the desired state of IngressClassParams
properties:
certficateArn:
description: CertificateARN specifies the ARN of the certificates
for all Ingresses that belong to IngressClass with this IngressClassParams.
items:
type: string
type: array
group:
description: Group defines the IngressGroup for all Ingresses that
belong to IngressClass with this IngressClassParams.
Expand Down
5 changes: 5 additions & 0 deletions docs/guide/ingress/ingress_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ Cluster administrators can use the `scheme` field to restrict the scheme for all
Cluster administrators can use the optional `inboundCIDRs` field to specify the CIDRs that are allowed to access the load balancers that belong to this IngressClass.
If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/inbound-cidrs` annotation.

### spec.certificateArn
Cluster administrators can use the optional `certificateARN` field to specify the ARN of the certificates for all Ingresses that belong to IngressClass with this IngressClassParams.

If the field is specified, LBC will ignore the `alb.ingress.kubernetes.io/certificate-arn` annotation.

#### spec.sslPolicy

Cluster administrators can use the optional `sslPolicy` field to specify the SSL policy for the load balancers that belong to this IngressClass.
Expand Down
7 changes: 7 additions & 0 deletions helm/aws-load-balancer-controller/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ spec:
spec:
description: IngressClassParamsSpec defines the desired state of IngressClassParams
properties:
certficateArn:
description:
CertificateARN specifies the ARN of the certificates for
all Ingresses that belong to IngressClass with this IngressClassParams.
items:
type: string
type: array
group:
description: Group defines the IngressGroup for all Ingresses that
belong to IngressClass with this IngressClassParams.
Expand Down
9 changes: 6 additions & 3 deletions pkg/ingress/model_build_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type listenPortConfig struct {
}

func (t *defaultModelBuildTask) computeIngressListenPortConfigByPort(ctx context.Context, ing *ClassifiedIngress) (map[int64]listenPortConfig, error) {
explicitTLSCertARNs := t.computeIngressExplicitTLSCertARNs(ctx, ing.Ing)
explicitTLSCertARNs := t.computeIngressExplicitTLSCertARNs(ctx, ing)
explicitSSLPolicy := t.computeIngressExplicitSSLPolicy(ctx, ing)
inboundCIDRv4s, inboundCIDRV6s, err := t.computeIngressExplicitInboundCIDRs(ctx, ing)
if err != nil {
Expand Down Expand Up @@ -162,9 +162,12 @@ func (t *defaultModelBuildTask) computeIngressListenPortConfigByPort(ctx context
return listenPortConfigByPort, nil
}

func (t *defaultModelBuildTask) computeIngressExplicitTLSCertARNs(_ context.Context, ing *networking.Ingress) []string {
func (t *defaultModelBuildTask) computeIngressExplicitTLSCertARNs(_ context.Context, ing *ClassifiedIngress) []string {
if ing.IngClassConfig.IngClassParams != nil && len(ing.IngClassConfig.IngClassParams.Spec.CertficateArn) != 0 {
return ing.IngClassConfig.IngClassParams.Spec.CertficateArn
}
var rawTLSCertARNs []string
_ = t.annotationParser.ParseStringSliceAnnotation(annotations.IngressSuffixCertificateARN, &rawTLSCertARNs, ing.Annotations)
_ = t.annotationParser.ParseStringSliceAnnotation(annotations.IngressSuffixCertificateARN, &rawTLSCertARNs, ing.Ing.Annotations)
return rawTLSCertARNs
}

Expand Down
268 changes: 268 additions & 0 deletions pkg/ingress/model_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,274 @@ func Test_defaultModelBuilder_Build(t *testing.T) {
"80:3": null
}
}
}`,
},
{
name: "Ingress - certificate-arn in IngressClassParams",
env: env{
svcs: []*corev1.Service{ns_1_svc_1, ns_1_svc_2, ns_1_svc_3},
},
fields: fields{
resolveViaDiscoveryCalls: []resolveViaDiscoveryCall{resolveViaDiscoveryCallForInternalLB},
listLoadBalancersCalls: []listLoadBalancersCall{listLoadBalancerCallForEmptyLB},
enableBackendSG: true,
},
args: args{
ingGroup: Group{
ID: GroupID{Namespace: "ns-1", Name: "ing-1"},
Members: []ClassifiedIngress{
{
IngClassConfig: ClassConfiguration{
IngClassParams: &v1beta1.IngressClassParams{
Spec: v1beta1.IngressClassParamsSpec{
CertficateArn: []string{"arn:aws:acm:us-east-1:9999999:certificate/ingress-class-certificate-arn"},
},
},
},
Ing: &networking.Ingress{ObjectMeta: metav1.ObjectMeta{
Namespace: "ns-1",
Name: "ing-1",
Annotations: map[string]string{
"alb.ingress.kubernetes.io/certificate-arn": "arn:aws:acm:us-east-1:9999999:certificate/annotated-certificate-arn",
},
},
Spec: networking.IngressSpec{
Rules: []networking.IngressRule{
{
Host: "app-1.example.com",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: "/svc-1",
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: ns_1_svc_1.Name,
Port: networking.ServiceBackendPort{
Name: "http",
},
},
},
},
{
Path: "/svc-2",
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: ns_1_svc_2.Name,
Port: networking.ServiceBackendPort{
Name: "http",
},
},
},
},
},
},
},
},
{
Host: "app-2.example.com",
IngressRuleValue: networking.IngressRuleValue{
HTTP: &networking.HTTPIngressRuleValue{
Paths: []networking.HTTPIngressPath{
{
Path: "/svc-3",
Backend: networking.IngressBackend{
Service: &networking.IngressServiceBackend{
Name: ns_1_svc_3.Name,
Port: networking.ServiceBackendPort{
Name: "https",
},
},
},
},
},
},
},
},
},
},
},
},
},
},
},
wantStackPatch: `
{
"resources": {
"AWS::EC2::SecurityGroup": {
"ManagedLBSecurityGroup": {
"spec": {
"ingress": [
{
"fromPort": 443,
"ipProtocol": "tcp",
"ipRanges": [
{
"cidrIP": "0.0.0.0/0"
}
],
"toPort": 443
}
]
}
}
},
"AWS::ElasticLoadBalancingV2::Listener": {
"443": {
"spec": {
"certificates": [
{
"certificateARN": "arn:aws:acm:us-east-1:9999999:certificate/ingress-class-certificate-arn"
}
],
"defaultActions": [
{
"fixedResponseConfig": {
"contentType": "text/plain",
"statusCode": "404"
},
"type": "fixed-response"
}
],
"loadBalancerARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::LoadBalancer/LoadBalancer/status/loadBalancerARN"
},
"port": 443,
"protocol": "HTTPS",
"sslPolicy": "ELBSecurityPolicy-2016-08",
"mutualAuthentication": {
"mode" : "off"
}
}
},
"80": null
},
"AWS::ElasticLoadBalancingV2::ListenerRule": {
"443:1": {
"spec": {
"actions": [
{
"forwardConfig": {
"targetGroups": [
{
"targetGroupARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-1:http/status/targetGroupARN"
}
}
]
},
"type": "forward"
}
],
"conditions": [
{
"field": "host-header",
"hostHeaderConfig": {
"values": [
"app-1.example.com"
]
}
},
{
"field": "path-pattern",
"pathPatternConfig": {
"values": [
"/svc-1"
]
}
}
],
"listenerARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::Listener/443/status/listenerARN"
},
"priority": 1
}
},
"443:2": {
"spec": {
"actions": [
{
"forwardConfig": {
"targetGroups": [
{
"targetGroupARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-2:http/status/targetGroupARN"
}
}
]
},
"type": "forward"
}
],
"conditions": [
{
"field": "host-header",
"hostHeaderConfig": {
"values": [
"app-1.example.com"
]
}
},
{
"field": "path-pattern",
"pathPatternConfig": {
"values": [
"/svc-2"
]
}
}
],
"listenerARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::Listener/443/status/listenerARN"
},
"priority": 2
}
},
"443:3": {
"spec": {
"actions": [
{
"forwardConfig": {
"targetGroups": [
{
"targetGroupARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::TargetGroup/ns-1/ing-1-svc-3:https/status/targetGroupARN"
}
}
]
},
"type": "forward"
}
],
"conditions": [
{
"field": "host-header",
"hostHeaderConfig": {
"values": [
"app-2.example.com"
]
}
},
{
"field": "path-pattern",
"pathPatternConfig": {
"values": [
"/svc-3"
]
}
}
],
"listenerARN": {
"$ref": "#/resources/AWS::ElasticLoadBalancingV2::Listener/443/status/listenerARN"
},
"priority": 3
}
},
"80:1": null,
"80:2": null,
"80:3": null
}
}
}`,
},
{
Expand Down