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

MAISTRA-1739 Fix validation of AuthorizationPolicy fields #157

Merged
merged 1 commit into from
Aug 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ spec:
when:
- key: "request.headers[X-header]"
values: ["header", "header-prefix-*", "*-suffix-header", "*"]
- key: "request.regex.headers[X-header-regex]"
values: ["some.*value"]
- key: "source.ip"
values: ["10.10.10.10", "192.168.10.0/24"]
- key: "source.namespace"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ rules:
- header:
name: X-header
presentMatch: true
- header:
name: X-header-regex
safeRegexMatch:
googleRe2: {}
regex: some.*value
- orIds:
ids:
- sourceIp:
Expand Down
37 changes: 20 additions & 17 deletions pkg/config/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ type JwksInfo struct {
}

const (
attrRequestHeader = "request.headers" // header name is surrounded by brackets, e.g. "request.headers[User-Agent]".
attrSrcIP = "source.ip" // supports both single ip and cidr, e.g. "10.1.2.3" or "10.1.0.0/16".
attrSrcNamespace = "source.namespace" // e.g. "default".
attrSrcUser = "source.user" // source identity, e.g. "cluster.local/ns/default/sa/productpage".
attrSrcPrincipal = "source.principal" // source identity, e,g, "cluster.local/ns/default/sa/productpage".
attrRequestPrincipal = "request.auth.principal" // authenticated principal of the request.
attrRequestAudiences = "request.auth.audiences" // intended audience(s) for this authentication information.
attrRequestPresenter = "request.auth.presenter" // authorized presenter of the credential.
attrRequestClaims = "request.auth.claims" // claim name is surrounded by brackets, e.g. "request.auth.claims[iss]".
attrDestIP = "destination.ip" // supports both single ip and cidr, e.g. "10.1.2.3" or "10.1.0.0/16".
attrDestPort = "destination.port" // must be in the range [0, 65535].
attrDestLabel = "destination.labels" // label name is surrounded by brackets, e.g. "destination.labels[version]".
attrDestName = "destination.name" // short service name, e.g. "productpage".
attrDestNamespace = "destination.namespace" // e.g. "default".
attrDestUser = "destination.user" // service account, e.g. "bookinfo-productpage".
attrConnSNI = "connection.sni" // server name indication, e.g. "www.example.com".
attrExperimental = "experimental.envoy.filters."
attrRequestHeader = "request.headers" // header name is surrounded by brackets, e.g. "request.headers[User-Agent]".
attrRequestHeaderRegex = "request.regex.headers" // header regex is surrounded by brackets, e.g. "request.regex.headers[X-Random-.*]".
attrSrcIP = "source.ip" // supports both single ip and cidr, e.g. "10.1.2.3" or "10.1.0.0/16".
attrSrcNamespace = "source.namespace" // e.g. "default".
attrSrcUser = "source.user" // source identity, e.g. "cluster.local/ns/default/sa/productpage".
attrSrcPrincipal = "source.principal" // source identity, e,g, "cluster.local/ns/default/sa/productpage".
attrRequestPrincipal = "request.auth.principal" // authenticated principal of the request.
attrRequestAudiences = "request.auth.audiences" // intended audience(s) for this authentication information.
attrRequestPresenter = "request.auth.presenter" // authorized presenter of the credential.
attrRequestClaims = "request.auth.claims" // claim name is surrounded by brackets, e.g. "request.auth.claims[iss]".
attrDestIP = "destination.ip" // supports both single ip and cidr, e.g. "10.1.2.3" or "10.1.0.0/16".
attrDestPort = "destination.port" // must be in the range [0, 65535].
attrDestLabel = "destination.labels" // label name is surrounded by brackets, e.g. "destination.labels[version]".
attrDestName = "destination.name" // short service name, e.g. "productpage".
attrDestNamespace = "destination.namespace" // e.g. "default".
attrDestUser = "destination.user" // service account, e.g. "bookinfo-productpage".
attrConnSNI = "connection.sni" // server name indication, e.g. "www.example.com".
attrExperimental = "experimental.envoy.filters."
)

// ParseJwksURI parses the input URI and returns the corresponding hostname, port, and whether SSL is used.
Expand Down Expand Up @@ -93,6 +94,8 @@ func ValidateAttribute(key string, values []string) error {
switch {
case hasPrefix(key, attrRequestHeader):
return validateMapKey(key)
case hasPrefix(key, attrRequestHeaderRegex):
return validateMapKey(key)
case isEqual(key, attrSrcIP):
return validateIPs(values)
case isEqual(key, attrSrcNamespace):
Expand Down