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

feat: add skip_mtls_uri_regex support for ApisixTls #1915

Merged
merged 14 commits into from
Dec 20, 2023
5 changes: 3 additions & 2 deletions pkg/kube/apisix/apis/config/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,9 @@ type ApisixSecret struct {

// ApisixMutualTlsClientConfig describes the mutual TLS CA and verify depth
type ApisixMutualTlsClientConfig struct {
CASecret ApisixSecret `json:"caSecret,omitempty" yaml:"caSecret,omitempty"`
Depth int `json:"depth,omitempty" yaml:"depth,omitempty"`
CASecret ApisixSecret `json:"caSecret,omitempty" yaml:"caSecret,omitempty"`
Depth int `json:"depth,omitempty" yaml:"depth,omitempty"`
SkipMtlsUriRegex []string `json:"skip_mtls_uri_regex,omitempty" yaml:"skip_mtls_uri_regex, omitempty"`
tao12345666333 marked this conversation as resolved.
Show resolved Hide resolved
}

// +genclient
Expand Down
7 changes: 6 additions & 1 deletion pkg/kube/apisix/apis/config/v2/zz_generated.deepcopy.go

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

5 changes: 3 additions & 2 deletions pkg/providers/apisix/translation/apisix_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (t *translator) TranslateSSLV2(tls *configv2.ApisixTls) (*apisixv1.Ssl, err
return nil, err
}
ssl.Client = &apisixv1.MutualTLSClientConfig{
CA: string(ca),
Depth: tls.Spec.Client.Depth,
CA: string(ca),
Depth: tls.Spec.Client.Depth,
SkipMtlsUriRegex: tls.Spec.Client.SkipMtlsUriRegex,
}
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/types/apisix/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ type Ssl struct {
// MutualTLSClientConfig apisix SSL client field
// +k8s:deepcopy-gen=true
type MutualTLSClientConfig struct {
CA string `json:"ca,omitempty" yaml:"ca,omitempty"`
Depth int `json:"depth,omitempty" yaml:"depth,omitempty"`
CA string `json:"ca,omitempty" yaml:"ca,omitempty"`
Depth int `json:"depth,omitempty" yaml:"depth,omitempty"`
SkipMtlsUriRegex []string `json:"skip_mtls_uri_regex,omitempty" yaml:"skip_mtls_uri_regex, omitempty"`
}

// StreamRoute represents the stream_route object in APISIX.
Expand Down
7 changes: 6 additions & 1 deletion pkg/types/apisix/v1/zz_generated.deepcopy.go

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

4 changes: 4 additions & 0 deletions samples/deploy/crd/v1/ApisixTls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ spec:
minLength: 1
depth:
type: integer
skip_mtls_uri_regex:
type: array
items:
type: string
hosts:
type: array
minItems: 1
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/scaffold/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ spec:
name: %s
namespace: %s
depth: 10
skip_mtls_uri_regex:
- %s
`
)

Expand Down Expand Up @@ -137,8 +139,8 @@ func (s *Scaffold) NewApisixTls(name, host, secretName string, ingressClassName
}

// NewApisixTlsWithClientCA new a ApisixTls CRD
func (s *Scaffold) NewApisixTlsWithClientCA(name, host, secretName, clientCASecret string) error {
tls := fmt.Sprintf(_api6tlsWithClientCATemplate, s.opts.ApisixResourceVersion, name, host, secretName, s.kubectlOptions.Namespace, clientCASecret, s.kubectlOptions.Namespace)
func (s *Scaffold) NewApisixTlsWithClientCA(name, host, secretName, clientCASecret, skipMtlsUriRegex string) error {
tls := fmt.Sprintf(_api6tlsWithClientCATemplate, s.opts.ApisixResourceVersion, name, host, secretName, s.kubectlOptions.Namespace, clientCASecret, s.kubectlOptions.Namespace, skipMtlsUriRegex)
if err := s.CreateResourceFromString(tls); err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/suite-ingress/suite-ingress-resource/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ var _ = ginkgo.Describe("suite-ingress-resource: ApisixTls mTLS Test", func() {

// create ApisixTls resource
tlsName := "tls-with-client-ca"
err = s.NewApisixTlsWithClientCA(tlsName, host, serverCertSecret, clientCASecret)
skipMtlsUriRegex := "/get"
err = s.NewApisixTlsWithClientCA(tlsName, host, serverCertSecret, clientCASecret, skipMtlsUriRegex)
assert.Nil(ginkgo.GinkgoT(), err, "create ApisixTls with client CA error")
// check ssl in APISIX
assert.Nil(ginkgo.GinkgoT(), s.EnsureNumApisixTlsCreated(1))
Expand Down Expand Up @@ -305,6 +306,8 @@ spec:

s.NewAPISIXHttpsClientWithCertificates(host, true, caCertPool, []tls.Certificate{cert}).
GET("/ip").WithHeader("Host", host).Expect().Status(http.StatusOK)

s.NewAPISIXHttpsClient(host).GET("/get").WithHeader("Host", host).Expect().Status(http.StatusOK)
})
}

Expand Down
Loading