Skip to content

Commit

Permalink
more tests, changelog and site docs
Browse files Browse the repository at this point in the history
Signed-off-by: claytonig <claytonivorgonsalves@gmail.com>
  • Loading branch information
claytonig committed Feb 20, 2023
1 parent 91c3564 commit d5b8150
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 232 deletions.
2 changes: 1 addition & 1 deletion apis/projectcontour/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (v *VirtualHost) AuthorizationContext() map[string]string {
}

// DisableGlobalAuthorization returns true if this virtual host disables
// global authorization. If a global authorization config present, the default
// global authorization. If a global authorization config is present, the default
// policy is to not disable.
func (v *VirtualHost) DisableGlobalAuthorization() bool {
return v.Authorization != nil && v.Authorization.GlobalExternalAuthorizationDisabled
Expand Down
8 changes: 6 additions & 2 deletions apis/projectcontour/v1/httpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ type ExtensionServiceReference struct {
// external authorization GRPC protocol (https://www.envoyproxy.io/docs/envoy/latest/api-v3/service/auth/v3/external_auth.proto).
type AuthorizationServer struct {
// ExtensionServiceRef specifies the extension resource that will authorize client requests.
// One of globalExtAuthDisabled or extensionRef must be set.
//
// +required
ExtensionServiceRef ExtensionServiceReference `json:"extensionRef,,omitempty"`
// +optional
ExtensionServiceRef ExtensionServiceReference `json:"extensionRef,omitempty"`

// AuthPolicy sets a default authorization policy for client requests.
// This policy will be used unless overridden by individual routes.
Expand Down Expand Up @@ -225,6 +226,9 @@ type AuthorizationServer struct {
WithRequestBody *AuthorizationServerBufferSettings `json:"withRequestBody,omitempty"`

// GlobalExternalAuthorizationDisabled optionally disables the global external authorization on the virtual host.
// One of globalExtAuthDisabled or extensionRef must be set.
//
// +optional
GlobalExternalAuthorizationDisabled bool `json:"globalExtAuthDisabled,omitempty"`
}

Expand Down
4 changes: 2 additions & 2 deletions apis/projectcontour/v1alpha1/contourconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type ContourConfigurationSpec struct {
EnableExternalNameService *bool `json:"enableExternalNameService,omitempty"`

// GlobalExternalAuthorization allows envoys external authorization filter
// to be enabled for all HTTP requests.
// to be enabled for all virtual hosts.
// +optional
GlobalExternalAuthorization *GlobalExternalAuthorizationConfig `json:"globalExtAuth,omitempty"`

Expand Down Expand Up @@ -628,7 +628,7 @@ type NetworkParameters struct {
EnvoyAdminPort *int `json:"adminPort,omitempty"`
}

// GlobalExternalAuthorizationConfig defines properties of global HTTP external authorization.
// GlobalExternalAuthorizationConfig defines properties of global external authorization.
type GlobalExternalAuthorizationConfig struct {
// ExtensionService identifies the extension service responsible for the authorization.
// formatted as <namespace>/<name>.
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/4994-clayton-gonsalves-minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Global External Authorization for HTTPProxy.
1 change: 1 addition & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ func (ctx *serveContext) convertToContourConfigurationSpec() contour_api_v1alpha

if ctx.Config.GlobalExternalAuthorization.WithRequestBody != nil {
globalExtAuth.WithRequestBody = &contour_api_v1alpha1.GlobalAuthorizationServerBufferSettings{
MaxRequestBytes: ctx.Config.GlobalExternalAuthorization.WithRequestBody.MaxRequestBytes,
AllowPartialMessage: ref.To(ctx.Config.GlobalExternalAuthorization.WithRequestBody.AllowPartialMessage),
PackAsBytes: ref.To(ctx.Config.GlobalExternalAuthorization.WithRequestBody.PackAsBytes),
}
Expand Down
42 changes: 40 additions & 2 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,9 @@ func TestConvertServeContext(t *testing.T) {
DisablePermitInsecure: ref.To(false),
FallbackCertificate: nil,
},
EnableExternalNameService: ref.To(false),
RateLimitService: nil,
EnableExternalNameService: ref.To(false),
RateLimitService: nil,
GlobalExternalAuthorization: nil,
Policy: &contour_api_v1alpha1.PolicyConfig{
RequestHeadersPolicy: &contour_api_v1alpha1.HeadersPolicy{},
ResponseHeadersPolicy: &contour_api_v1alpha1.HeadersPolicy{},
Expand Down Expand Up @@ -699,6 +700,43 @@ func TestConvertServeContext(t *testing.T) {
return cfg
},
},
"global external authorization": {
getServeContext: func(ctx *serveContext) *serveContext {
ctx.Config.GlobalExternalAuthorization = config.GlobalExternalAuthorization{
ExtensionService: "extauthns/extauthtext",
FailOpen: true,
AuthPolicy: &config.GlobalAuthorizationPolicy{
Context: map[string]string{
"foo": "bar",
},
},
WithRequestBody: &config.GlobalAuthorizationServerBufferSettings{
MaxRequestBytes: 512,
PackAsBytes: true,
AllowPartialMessage: true,
},
}
return ctx
},
getContourConfiguration: func(cfg contour_api_v1alpha1.ContourConfigurationSpec) contour_api_v1alpha1.ContourConfigurationSpec {
cfg.GlobalExternalAuthorization = &contour_api_v1alpha1.GlobalExternalAuthorizationConfig{
ExtensionService: "extauthns/extauthtext",
FailOpen: ref.To(true),
AuthPolicy: &contour_api_v1alpha1.GlobalAuthorizationPolicy{
Context: map[string]string{
"foo": "bar",
},
Disabled: ref.To(false),
},
WithRequestBody: &contour_api_v1alpha1.GlobalAuthorizationServerBufferSettings{
MaxRequestBytes: 512,
PackAsBytes: ref.To(true),
AllowPartialMessage: ref.To(true),
},
}
return cfg
},
},
}

for name, tc := range cases {
Expand Down
165 changes: 0 additions & 165 deletions config.yaml

This file was deleted.

10 changes: 6 additions & 4 deletions examples/contour/01-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external authorization
filter to be enabled for all HTTP requests.
filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -3498,7 +3498,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external
authorization filter to be enabled for all HTTP requests.
authorization filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -5864,7 +5864,8 @@ spec:
type: object
extensionRef:
description: ExtensionServiceRef specifies the extension resource
that will authorize client requests.
that will authorize client requests. One of globalExtAuthDisabled
or extensionRef must be set.
properties:
apiVersion:
description: API version of the referent. If this field
Expand Down Expand Up @@ -5893,7 +5894,8 @@ spec:
globalExtAuthDisabled:
description: GlobalExternalAuthorizationDisabled optionally
disables the global external authorization on the virtual
host.
host. One of globalExtAuthDisabled or extensionRef must
be set.
type: boolean
responseTimeout:
description: ResponseTimeout configures maximum time to wait
Expand Down
10 changes: 6 additions & 4 deletions examples/render/contour-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external authorization
filter to be enabled for all HTTP requests.
filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -3711,7 +3711,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external
authorization filter to be enabled for all HTTP requests.
authorization filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -6077,7 +6077,8 @@ spec:
type: object
extensionRef:
description: ExtensionServiceRef specifies the extension resource
that will authorize client requests.
that will authorize client requests. One of globalExtAuthDisabled
or extensionRef must be set.
properties:
apiVersion:
description: API version of the referent. If this field
Expand Down Expand Up @@ -6106,7 +6107,8 @@ spec:
globalExtAuthDisabled:
description: GlobalExternalAuthorizationDisabled optionally
disables the global external authorization on the virtual
host.
host. One of globalExtAuthDisabled or extensionRef must
be set.
type: boolean
responseTimeout:
description: ResponseTimeout configures maximum time to wait
Expand Down
10 changes: 6 additions & 4 deletions examples/render/contour-gateway-provisioner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external authorization
filter to be enabled for all HTTP requests.
filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -3512,7 +3512,7 @@ spec:
type: object
globalExtAuth:
description: GlobalExternalAuthorization allows envoys external
authorization filter to be enabled for all HTTP requests.
authorization filter to be enabled for all virtual hosts.
properties:
extensionService:
description: ExtensionService identifies the extension service
Expand Down Expand Up @@ -5878,7 +5878,8 @@ spec:
type: object
extensionRef:
description: ExtensionServiceRef specifies the extension resource
that will authorize client requests.
that will authorize client requests. One of globalExtAuthDisabled
or extensionRef must be set.
properties:
apiVersion:
description: API version of the referent. If this field
Expand Down Expand Up @@ -5907,7 +5908,8 @@ spec:
globalExtAuthDisabled:
description: GlobalExternalAuthorizationDisabled optionally
disables the global external authorization on the virtual
host.
host. One of globalExtAuthDisabled or extensionRef must
be set.
type: boolean
responseTimeout:
description: ResponseTimeout configures maximum time to wait
Expand Down
Loading

0 comments on commit d5b8150

Please sign in to comment.