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

API for authorization #3138

Closed
wants to merge 1 commit into from
Closed
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
76 changes: 76 additions & 0 deletions api/v1alpha1/authorization_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright Envoy Gateway Authors
// SPDX-License-Identifier: Apache-2.0
// The full text of the Apache license is available in the LICENSE file at
// the root of the repo.

package v1alpha1

// AuthorizationAction defines the action to take if a request matches the rule.
type AuthorizationAction string

const (
// AuthorizationActionAllow allows the request.
AuthorizationActionAllow AuthorizationAction = "ALLOW"
// AuthorizationActionDeny denies the request.
AuthorizationActionDeny AuthorizationAction = "DENY"
)

// Authorization defines the configuration for request authorization.
type Authorization struct {
// Rules define a list of authorization rules.
// +kubebuilder:validation:MinItems=1
Rules []AuthorizationRule `json:"policies"`
}

// AuthorizationRule defines the configuration for an authorization rule.
type AuthorizationRule struct {
// Action defines the action to take if a request matches the rule.
// ALLOW allows the request, and DENY denies the request.
// +kubebuilder:validation:Enum=ALLOW;DENY
Action AuthorizationAction `json:"action"`

// Policies define which principals are allowed/denied access to specified permissions based on the action.
Policies []AuthorizationPolicy `json:"policy"`
}

// AuthorizationPolicy defines the configuration for an authorization policy.
type AuthorizationPolicy struct {
// Principals define the list of principals that are allowed/denied access based on the action.
// If no principals are specified, all requests are matched.
Principles []Principle `json:"principles"`

// Permissions define the list of permissions that are allowed/denied access based on the action.
// If no permissions are specified, all requests are matched.
Permissions []Permission `json:"permissions"`
}

// Principle defines the configuration for a principle.
type Principle struct {
// SourceIP is an IP CIDR that represents the range of the source IP addresses for clients.
// This address will honor proxy protocol, but will not honor XFF.
// For example, `192.168.0.1/32`, `192.168.0.0/24`, `001:db8::/64`.
// One of SourceIP or JWTClaim must be specified.
SourceIP *string `json:"sourceIP,omitempty"`

// JWTClaims is a JWT claim that can be used to authorize requests.
// To use this claim, the JWT settings must be configured in the SecurityPolicy,
// and the specified claim must be present in the JWT token.
// One of SourceIP or JWTClaim must be specified.
JWTClaim *JWTClaim
}

// JWTClaim defines a JWT claim that can be used to authorize requests.
type JWTClaim struct {
// Name is the name of the claim.
Name string `json:"name"`

// Value is the value of the claim.
Value string `json:"value"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thinking like groups parameter. Use case could be "i want allow group x only" or "i want allow/deny groups x y z".

}

// Permission defines actions that the authorized principals can take.
type Permission struct {
// Methods define the list of HTTP methods that are allowed/denied access based on the action.
// If no methods are specified, all methods are matched.
Method []string `json:"method"`
}
5 changes: 5 additions & 0 deletions api/v1alpha1/securitypolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
//
// +optional
ExtAuth *ExtAuth `json:"extAuth,omitempty"`

// Authorization defines the configuration for authorization.
//
// +optional
Authorization *Authorization `json:"authorization
}

// SecurityPolicyStatus defines the state of SecurityPolicy
Expand All @@ -80,7 +85,7 @@
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=8
Conditions []metav1.Condition `json:"conditions,omitempty"`

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected json in struct type; possibly missing semicolon or newline or }

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

expected ';', found json (typecheck)

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected json in struct type; possibly missing semicolon or newline or }

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected ';', found json

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected ';', found json

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected ';', found json

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected ';', found json

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected ';', found json

Check failure on line 88 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected ';', found json
}

//+kubebuilder:object:root=true
Expand All @@ -89,9 +94,9 @@
type SecurityPolicyList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SecurityPolicy `json:"items"`

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

string not terminated (typecheck)

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

raw string literal not terminated (typecheck)

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

string not terminated) (typecheck)

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

raw string literal not terminated

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

raw string literal not terminated

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

raw string literal not terminated

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

raw string literal not terminated

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

raw string literal not terminated

Check failure on line 97 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

raw string literal not terminated
}

func init() {
SchemeBuilder.Register(&SecurityPolicy{}, &SecurityPolicyList{})
}

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / lint

expected '}', found 'EOF' (typecheck)

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected ';', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected '}', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected ';', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / gen-check

expected '}', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected ';', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected '}', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected ';', found 'EOF'

Check failure on line 102 in api/v1alpha1/securitypolicy_types.go

View workflow job for this annotation

GitHub Actions / coverage-test

expected '}', found 'EOF'
Loading