Skip to content

Commit

Permalink
internal/dag: default the authorization response timeout (projectcont…
Browse files Browse the repository at this point in the history
…our#3026)

If the authorization spec on the virtual host doesn't set the response
timeout, default it from the corresponding `ExtensionService`.

This fixes projectcontour#3025.

Signed-off-by: James Peach <jpeach@vmware.com>
  • Loading branch information
jpeach authored Oct 13, 2020
1 parent 5312588 commit 47c4eb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 7 additions & 2 deletions internal/dag/httpproxy_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,16 @@ func (p *HTTPProxyProcessor) computeHTTPProxy(proxy *contour_api_v1.HTTPProxy) {

timeout, err := timeout.Parse(auth.ResponseTimeout)
if err != nil {
validCond.AddErrorf("AuthError", "AuthReponseTimeoutInvalid",
validCond.AddErrorf("AuthError", "AuthResponseTimeoutInvalid",
"Spec.Virtualhost.Authorization.ResponseTimeout is invalid: %s", err)
return
}
svhost.AuthorizationResponseTimeout = timeout

if timeout.UseDefault() {
svhost.AuthorizationResponseTimeout = ext.TimeoutPolicy.ResponseTimeout
} else {
svhost.AuthorizationResponseTimeout = timeout
}
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions internal/featuretests/v2/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"k8s.io/client-go/tools/cache"
)

const defaultResponseTimeout = time.Minute * 60

func grpcCluster(name string) *envoy_config_filter_http_ext_authz_v2.ExtAuthz_GrpcService {
return &envoy_config_filter_http_ext_authz_v2.ExtAuthz_GrpcService{
GrpcService: &envoy_api_v2_core.GrpcService{
Expand All @@ -44,6 +46,7 @@ func grpcCluster(name string) *envoy_config_filter_http_ext_authz_v2.ExtAuthz_Gr
ClusterName: name,
},
},
Timeout: protobuf.Duration(defaultResponseTimeout),
},
}
}
Expand Down Expand Up @@ -76,6 +79,7 @@ func authzResponseTimeout(t *testing.T, rh cache.ResourceEventHandler, c *Contou
TypeUrl: listenerType,
Resources: resources(t,
defaultHTTPListener(),

&envoy_api_v2.Listener{
Name: "ingress_https",
Address: envoy_v2.SocketAddress("0.0.0.0", 8443),
Expand Down Expand Up @@ -104,6 +108,7 @@ func authzResponseTimeout(t *testing.T, rh cache.ResourceEventHandler, c *Contou
},
SocketOptions: envoy_v2.TCPKeepaliveSocketOptions(),
},

staticListener()),
}).Status(p).Like(contour_api_v1.HTTPProxyStatus{
CurrentStatus: string(status.ProxyStatusValid),
Expand Down Expand Up @@ -131,13 +136,10 @@ func authzInvalidResponseTimeout(t *testing.T, rh cache.ResourceEventHandler, c

rh.OnAdd(p)

cluster := grpcCluster("extension/auth/extension")
cluster.GrpcService.Timeout = protobuf.Duration(10 * time.Minute)

c.Request(listenerType).Equals(&envoy_api_v2.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, staticListener()),
}).Status(p).HasError("AuthError", "AuthReponseTimeoutInvalid", `Spec.Virtualhost.Authorization.ResponseTimeout is invalid: unable to parse timeout string "invalid-timeout": time: invalid duration "invalid-timeout"`)
}).Status(p).HasError("AuthError", "AuthResponseTimeoutInvalid", `Spec.Virtualhost.Authorization.ResponseTimeout is invalid: unable to parse timeout string "invalid-timeout": time: invalid duration "invalid-timeout"`)
}

func authzFailOpen(t *testing.T, rh cache.ResourceEventHandler, c *Contour) {
Expand Down Expand Up @@ -549,6 +551,9 @@ func TestAuthorization(t *testing.T) {
Services: []v1alpha1.ExtensionServiceTarget{
{Name: "oidc-server", Port: 8081},
},
TimeoutPolicy: &contour_api_v1.TimeoutPolicy{
Response: defaultResponseTimeout.String(),
},
},
})

Expand Down

0 comments on commit 47c4eb2

Please sign in to comment.