Skip to content

Conversation

ronething
Copy link
Contributor

@ronething ronething commented Oct 14, 2025

Type of change:

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches
  • Documentation
  • Refactor
  • Chore
  • CI/CD or Tests

What this PR does / why we need it:

When the TLS configuration of the Gateway/Ingress/ApisixTls resources has the same host but uses different certificates, we should intercept.

  • add reusable SSL helpers for extracting certificates, keys, and SAN hosts
  • introduce an admission conflict detector that blocks mismatched TLS material across Gateway, Ingress, and ApisixTls resources
  • cover the detector with unit tests and e2e scenarios for cross-resource and self-conflicts

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
@ronething ronething changed the title feat: block when the same host using different cert feat: add certificate conflict detection to admission webhooks Oct 15, 2025
@ronething ronething marked this pull request as ready for review October 15, 2025 05:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces certificate conflict detection to admission webhooks to prevent SSL/TLS configuration mismatches across Gateway, Ingress, and ApisixTls resources that share the same GatewayProxy. The feature ensures that when multiple resources configure TLS for the same hostname, they must use identical certificates to avoid conflicting SSL configurations in APISIX.

  • Adds reusable SSL utility functions for certificate extraction and validation
  • Implements a comprehensive conflict detector that validates SSL configurations across resource types
  • Integrates conflict detection into admission webhooks for all three resource types

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/e2e/webhook/ssl_conflict.go Comprehensive e2e tests covering conflict scenarios between resources
internal/webhook/v1/ssl/conflict_detector_test.go Unit tests for the conflict detection logic
internal/webhook/v1/ssl/conflict_detector.go Core conflict detection implementation
internal/webhook/v1/ingress_webhook.go Integration of SSL conflict detection into Ingress webhook
internal/webhook/v1/gateway_webhook.go Integration of SSL conflict detection into Gateway webhook
internal/webhook/v1/apisixtls_webhook.go Integration of SSL conflict detection into ApisixTls webhook
internal/ssl/util.go Reusable SSL utility functions for certificate handling
internal/adc/translator/ingress.go Updated to use new SSL utilities
internal/adc/translator/gateway.go Refactored to use new SSL utilities, removing duplicate code
internal/adc/translator/apisixupstream.go Updated to use new SSL utilities
internal/adc/translator/apisixtls.go Updated to use new SSL utilities

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license-eye has totally checked 349 files.

Valid Invalid Ignored Fixed
252 1 96 0
Click to see the invalid file list
  • internal/controller/indexer/ssl_host.go

Signed-off-by: Ashing Zheng <[email protected]>
// existing resources that are associated with the same GatewayProxy. Best-effort:
// failures while enumerating existing resources or reading Secrets will be logged
// and result in no conflicts instead of blocking the admission.
func (d *ConflictDetector) DetectConflicts(ctx context.Context, obj client.Object, newMappings []HostCertMapping) ([]SSLConflict, error) {
Copy link
Contributor

@AlinsRan AlinsRan Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding this check:

if len(newMappings) == 0 { return }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

seen[mapping.Host] = mapping.CertificateHash
}

if len(seen) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflicts > 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
Signed-off-by: Ashing Zheng <[email protected]>
@ronething ronething merged commit 351d20a into master Oct 16, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants