Skip to content

Commit

Permalink
api: ACL API design
Browse files Browse the repository at this point in the history
  • Loading branch information
zetaab committed Feb 19, 2024
1 parent a5125bf commit 7ff7ff0
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 0 deletions.
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 @@ type SecurityPolicySpec struct {
//
// +optional
ExtAuth *ExtAuth `json:"extAuth,omitempty"`

// ACL defines the IP deny/allow configuration.
//
// +optional
ACL *ACL `json:"acl,omitempty"`

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

View workflow job for this annotation

GitHub Actions / coverage-test

undefined: ACL

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

View workflow job for this annotation

GitHub Actions / gen-check

unknown type ACL

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

View workflow job for this annotation

GitHub Actions / gen-check

undefined: ACL

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

View workflow job for this annotation

GitHub Actions / lint

undefined: ACL
}

// SecurityPolicyStatus defines the state of SecurityPolicy
Expand Down
29 changes: 29 additions & 0 deletions api/v1alpha1/validation/securitypolicy_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package validation
import (
"errors"
"fmt"
"net"
"net/mail"
"net/url"

Expand Down Expand Up @@ -56,6 +57,34 @@ func validateSecurityPolicySpec(spec *egv1a1.SecurityPolicySpec) error {
errs = append(errs, err)
}

if err := ValidateACL(spec.ACL); err != nil {
errs = append(errs, err)
}

return utilerrors.NewAggregate(errs)
}

// ValidateACL validates the provided ACL configuration.
func ValidateACL(acl *egv1a1.ACL) error {
var errs []error
if acl == nil {
return nil
}

for _, ipBlock := range acl.Allow {
_, _, err := net.ParseCIDR(ipBlock.CIDR)
if err != nil {
errs = append(errs, fmt.Errorf("invalid allow CIDR: %s", ipBlock.CIDR))
}
}

for _, ipBlock := range acl.Deny {
_, _, err := net.ParseCIDR(ipBlock.CIDR)
if err != nil {
errs = append(errs, fmt.Errorf("invalid deny CIDR: %s", ipBlock.CIDR))
}
}

return utilerrors.NewAggregate(errs)
}

Expand Down
45 changes: 45 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ spec:
spec:
description: Spec defines the desired state of SecurityPolicy.
properties:
acl:
description: ACL defines the IP deny/allow configuration.
properties:
allow:
items:
description: IPSpec defines the configuration for IP.
properties:
length:
description: 'Length contains the length of the IP network
prefix. Example: 24'
format: int32
type: integer
prefix:
description: 'Prefix contains the IP prefix. Example: 1.2.3.0'
type: string
type: object
type: array
deny:
items:
description: IPSpec defines the configuration for IP.
properties:
length:
description: 'Length contains the length of the IP network
prefix. Example: 24'
format: int32
type: integer
prefix:
description: 'Prefix contains the IP prefix. Example: 1.2.3.0'
type: string
type: object
type: array
type: object
x-kubernetes-validations:
- message: one of allow or deny must be specified
rule: (has(self.allow) || has(self.deny))
basicAuth:
description: BasicAuth defines the configuration for the HTTP Basic
Authentication.
Expand Down
30 changes: 30 additions & 0 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ API group.



#### ACL



ACL defines the IP deny/allow configuration.

_Appears in:_
- [SecurityPolicySpec](#securitypolicyspec)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `allow` | _[IPBlock](#ipblock) array_ | true | Allow specifies the list of IPBlocks that are allowed to access the service. Other cidrs are denied. |
| `deny` | _[IPBlock](#ipblock) array_ | true | Deny specifies the list of IPBlocks that are denied to access the service. |


#### ALPNProtocol

_Underlying type:_ _string_
Expand Down Expand Up @@ -1229,6 +1244,20 @@ _Appears in:_
| `passive` | _[PassiveHealthCheck](#passivehealthcheck)_ | false | Passive passive check configuration |


#### IPBlock



IPBlock defines policy on a particular IPBlock.

_Appears in:_
- [ACL](#acl)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `cidr` | _string_ | true | cidr is a string representing the IPBlock Valid examples are "192.168.1.0/24" or "2001:db8::/64" |


#### InfrastructureProviderType

_Underlying type:_ _string_
Expand Down Expand Up @@ -2154,6 +2183,7 @@ _Appears in:_
| `jwt` | _[JWT](#jwt)_ | false | JWT defines the configuration for JSON Web Token (JWT) authentication. |
| `oidc` | _[OIDC](#oidc)_ | false | OIDC defines the configuration for the OpenID Connect (OIDC) authentication. |
| `extAuth` | _[ExtAuth](#extauth)_ | false | ExtAuth defines the configuration for External Authorization. |
| `acl` | _[ACL](#acl)_ | false | ACL defines the IP deny/allow configuration. |



Expand Down

0 comments on commit 7ff7ff0

Please sign in to comment.