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

add e2e tests for ext auth with grpc auth service #2841

Merged
merged 5 commits into from
Mar 10, 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
20 changes: 16 additions & 4 deletions internal/xds/translator/extauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,32 @@
}

func createExtServiceXDSCluster(rd *ir.RouteDestination, tCtx *types.ResourceVersionTable) error {
var (
endpointType EndpointType
tSocket *corev3.TransportSocket
err error
)

// Get the address type from the first setting.
// This is safe because no mixed address types in the settings.
addrTypeState := rd.Settings[0].AddressType

var endpointType EndpointType
if addrTypeState != nil && *addrTypeState == ir.FQDN {
endpointType = EndpointTypeDNS
} else {
endpointType = EndpointTypeStatic
}
if err := addXdsCluster(tCtx, &xdsClusterArgs{

if rd.Settings[0].TLS != nil {
tSocket, err = processTLSSocket(rd.Settings[0].TLS, tCtx)
if err != nil {
return err
}

Check warning on line 253 in internal/xds/translator/extauth.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/extauth.go#L250-L253

Added lines #L250 - L253 were not covered by tests
}

if err = addXdsCluster(tCtx, &xdsClusterArgs{
name: rd.Name,
settings: rd.Settings,
tSocket: nil,
tSocket: tSocket,
endpointType: endpointType,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
return err
Expand Down
21 changes: 21 additions & 0 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,27 @@
return nil
}

// processTLSSocket generates a xDS TransportSocket for a given TLS config.
// It also adds the necessary secrets to the resource version table.
func processTLSSocket(tlsConfig *ir.TLSUpstreamConfig, tCtx *types.ResourceVersionTable) (*corev3.TransportSocket, error) {
if tlsConfig == nil {
return nil, nil
}
CaSecret := buildXdsUpstreamTLSCASecret(tlsConfig)
if CaSecret != nil {
if err := tCtx.AddXdsResource(resourcev3.SecretType, CaSecret); err != nil {
return nil, err
}

Check warning on line 527 in internal/xds/translator/translator.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/translator.go#L519-L527

Added lines #L519 - L527 were not covered by tests
}
// for upstreamTLS , a fixed sni can be used. use auto_sni otherwise
// https://www.envoyproxy.io/docs/envoy/latest/faq/configuration/sni#faq-how-to-setup-sni:~:text=For%20clusters%2C%20a,for%20trust%20anchor.
tlsSocket, err := buildXdsUpstreamTLSSocketWthCert(tlsConfig)
if err != nil {
return nil, err
}
return tlsSocket, nil

Check warning on line 535 in internal/xds/translator/translator.go

View check run for this annotation

Codecov / codecov/patch

internal/xds/translator/translator.go#L531-L535

Added lines #L531 - L535 were not covered by tests
}

// findXdsSecret finds a xds secret with the same name, and returns nil if there is no match.
func findXdsSecret(tCtx *types.ResourceVersionTable, name string) *tlsv3.Secret {
if tCtx == nil || tCtx.XdsResources == nil || tCtx.XdsResources[resourcev3.SecretType] == nil {
Expand Down
71 changes: 71 additions & 0 deletions test/e2e/testdata/ext-auth-grpc-securitypolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-with-ext-auth
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
hostnames: ["www.example.com"]
rules:
- matches:
- path:
type: PathPrefix
value: /myapp # This is the path that will be protected by ext auth
backendRefs:
- name: infra-backend-v1
port: 8080
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: http-without-ext-auth
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
hostnames: ["www.example.com"]
rules:
- matches:
- path:
type: PathPrefix
value: /public # This is the path that will be public
backendRefs:
- name: infra-backend-v1
port: 8080
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: SecurityPolicy
metadata:
name: ext-auth-test
namespace: gateway-conformance-infra
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: http-with-ext-auth
extAuth:
grpc:
backendRef:
name: grpc-ext-auth
zhaohuabing marked this conversation as resolved.
Show resolved Hide resolved
namespace: gateway-conformance-infra
port: 9002
---
apiVersion: gateway.networking.k8s.io/v1alpha2
kind: BackendTLSPolicy
metadata:
name: grpc-ext-auth-btls
namespace: gateway-conformance-infra
spec:
targetRef:
group: ''
kind: Service
name: grpc-ext-auth
sectionName: "9002"
tls:
caCertRefs:
- name: grpc-ext-auth-ca
group: ''
kind: ConfigMap
hostname: grpc-ext-auth
Loading