forked from projectcontour/contour
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal: add HTTPProxy authorization support
Add HTTPProxy fields to specify how to bind a virtual host to an ExtensionService that can authorize inbound client requests. This fixes projectcontour#2715. Signed-off-by: James Peach <[email protected]>
- Loading branch information
Showing
17 changed files
with
1,545 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright Project Contour Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v1 | ||
|
||
// AuthorizationConfigured returns whether authorization is | ||
// configured on this virtual host. | ||
func (v *VirtualHost) AuthorizationConfigured() bool { | ||
return v.TLS != nil && v.Authorization != nil | ||
} | ||
|
||
// DisableAuthorization returns true if this virtual host disables | ||
// authorization. If an authorization server is present, the default | ||
// policy is to not disable. | ||
func (v *VirtualHost) DisableAuthorization() bool { | ||
// No authorization, so it is disabled. | ||
if v.AuthorizationConfigured() { | ||
// No policy specified, default is to not disable. | ||
if v.Authorization.AuthPolicy == nil { | ||
return false | ||
} | ||
|
||
return v.Authorization.AuthPolicy.Disabled | ||
} | ||
|
||
return false | ||
} | ||
|
||
// AuthorizationContext returns the authorization policy context (if present). | ||
func (v *VirtualHost) AuthorizationContext() map[string]string { | ||
if v.AuthorizationConfigured() { | ||
if v.Authorization.AuthPolicy != nil { | ||
return v.Authorization.AuthPolicy.Context | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetPrefixReplacements returns replacement prefixes from the path | ||
// rewrite policy (if any). | ||
func (r *Route) GetPrefixReplacements() []ReplacePrefix { | ||
if r.PathRewritePolicy != nil { | ||
return r.PathRewritePolicy.ReplacePrefix | ||
} | ||
return nil | ||
} | ||
|
||
// AuthorizationContext merges the parent context entries with the | ||
// context from this Route. Common keys from the parent map will be | ||
// overwritten by keys from the route. The parent map may be nil. | ||
func (r *Route) AuthorizationContext(parent map[string]string) map[string]string { | ||
values := make(map[string]string, len(parent)) | ||
|
||
for k, v := range parent { | ||
values[k] = v | ||
} | ||
|
||
if r.AuthPolicy != nil { | ||
for k, v := range r.AuthPolicy.Context { | ||
values[k] = v | ||
} | ||
} | ||
|
||
if len(values) == 0 { | ||
return nil | ||
} | ||
|
||
return values | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.