-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: new ca-filter causing expontentially more api-calls #3608
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
+11
−11
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package ingress | |
|
||
import ( | ||
"context" | ||
"slices" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
@@ -16,6 +15,7 @@ import ( | |
"github.com/pkg/errors" | ||
"k8s.io/apimachinery/pkg/util/cache" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/utils/strings/slices" | ||
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services" | ||
) | ||
|
||
|
@@ -153,18 +153,18 @@ func (d *acmCertDiscovery) loadDomainsForCertificate(ctx context.Context, certAR | |
certDetail := resp.Certificate | ||
|
||
// check if cert is issued from an allowed CA | ||
// otherwise empty-out the list of domains | ||
domains := sets.String{} | ||
if len(d.allowedCAARNs) == 0 || slices.Contains(d.allowedCAARNs, awssdk.StringValue(certDetail.CertificateAuthorityArn)) { | ||
domains := sets.NewString(aws.StringValueSlice(certDetail.SubjectAlternativeNames)...) | ||
switch aws.StringValue(certDetail.Type) { | ||
case acm.CertificateTypeImported: | ||
d.certDomainsCache.Set(certARN, domains, d.importedCertDomainsCacheTTL) | ||
case acm.CertificateTypeAmazonIssued, acm.CertificateTypePrivate: | ||
d.certDomainsCache.Set(certARN, domains, d.privateCertDomainsCacheTTL) | ||
} | ||
return domains, nil | ||
domains = sets.NewString(aws.StringValueSlice(certDetail.SubjectAlternativeNames)...) | ||
} | ||
return sets.String{}, nil | ||
|
||
switch aws.StringValue(certDetail.Type) { | ||
case acm.CertificateTypeImported: | ||
d.certDomainsCache.Set(certARN, domains, d.importedCertDomainsCacheTTL) | ||
case acm.CertificateTypeAmazonIssued, acm.CertificateTypePrivate: | ||
d.certDomainsCache.Set(certARN, domains, d.privateCertDomainsCacheTTL) | ||
} | ||
return domains, nil | ||
} | ||
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. Real resp. resulting diff for this feature (#3565) can be viewed here: Or on this screenshot: |
||
|
||
func (d *acmCertDiscovery) domainMatchesHost(domainName string, tlsHost string) bool { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just for my understanding, the originally PR didn't introduce any regression right?
And you faced this issue due to you used the new "allowedCAARNs" feature?
If so, this fix looks good to me. However, i'd like to change this code to be like
technically there is no functional difference since
allowedCAARNs
is a controller-level flag which is immutable given the controller's lifetime. However, from coding perspective, the cache shall be for the "domains" before the "CA filter logic" and this make the code more robust(e.g. works evenallowedCAARNs
can be dynamically updated somehow).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.
Our PR introduce this behavior only if both conditions are met:
--allowed-certificate-authority-arns=...
parameterI/we can test your proposal tomorrow in our staging environment. But I assume that your proposed code change does not work properly as we then also cache the domain(s) of a certificate which is not issued from an allowed CA.
And the function first tries to load the domains from the cache before it reaches this filtering code block:
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.
@mkilchhofer
You are right, the cache shall be the domains after the filter.
ideally we should refactor the code such that the cache stores certificate details from AWS. (but for now it only caches domains and your filter logic is on cert CA), thus filter logic has to be run before the cache.
I'll approve this, and maybe refactor this in the future if we ever need to make the ca list mutable.