Skip to content

Commit

Permalink
drafting new cache model for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
pedy4000 committed Jan 24, 2024
1 parent 20bd6c1 commit dfd8f31
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 207 deletions.
28 changes: 13 additions & 15 deletions api/v1alpha1/accesstoken_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ const (
SuspendedState AccessTokenState = "Suspended"
)

type WebserviceReference corev1.SecretReference

// AccessTokenSpec defines the desired state of AccessToken
type AccessTokenSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// State shows the state of the token (whether you use token or it's just a draft)
// Valid values are:
// - "Active" (default): uses token in authorization procedure
Expand All @@ -53,26 +52,25 @@ type AccessTokenSpec struct {
// +optional
State AccessTokenState `json:"state,omitempty"`

// IP Allow List is a list of IP and IP CIDRs that will be tested against X-Forwarded-For
// Priority shows the access level of the token
// +kubebuilder:default=0
// +kubebuilder:validation:Minimum=0
// +optional
IpAllowList []string `json:"ipAllowList,omitempty"`
Priority int `json:"priority,omitempty"`

// Domain Allow list is a list of Domain glob patterns that will be tested against Referer header
// AllowedIPs is a list of IP and IP CIDRs that will be tested against X-Forwarded-For
// +optional
DomainAllowList []string `json:"domainAllowList,omitempty"`
AllowedIPs []string `json:"ipAllowList,omitempty"`

// Secret Ref points to secret containing the API Key secret
// if it exists it will use the token value in it and will create a new secret if not exists
TokenSecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
// AllowedDomains is a list of Domain glob patterns that will be tested against Referer header
// +optional
AllowedDomains []string `json:"domainAllowList,omitempty"`

// Priority shows the access level of the token
// +kubebuilder:default=0
// +kubebuilder:validation:Minimum=0
// AllowedWebservices is a list of Webservice that the token has access to
// +optional
Priority int `json:"priority,omitempty"`
AllowedWebservices []*WebserviceReference `json:"allowedWebservices,omitempty"`
}

// TODO use AccessToken.Metadata.Name as TokenSecretRef
// TODO next step: create copy of secret in AccessToken's namespace

// AccessTokenStatus defines the observed state of AccessToken
Expand Down
7 changes: 4 additions & 3 deletions api/v1alpha1/webservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ import (

// WebServiceSpec defines the desired state of WebService
type WebServiceSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:default=X-Cerberus-Token
// +kubebuilder:validation:Pattern=^(X-[A-Za-z-]*[A-Za-z]|Authorization)$
// LookupHeader tells Cerberus which header should be used as the access token for authentication (case-sensitive).
Expand Down Expand Up @@ -103,6 +100,10 @@ type WebServiceList struct {
Items []WebService `json:"items"`
}

func (w WebService) encodedName() string {
return w.Namespace + "/" + w.Name
}

func init() {
SchemeBuilder.Register(&WebService{}, &WebServiceList{})
}
5 changes: 1 addition & 4 deletions api/v1alpha1/webserviceaccessbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import (

// WebserviceAccessBindingSpec defines the desired state of WebserviceAccessBinding
type WebserviceAccessBindingSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Subjects are the name of AccessTokens which the access will be granted to
// Subjects are the name of Namespaces which the access will be granted to their tokens
Subjects []string `json:"subjects,omitempty"`

// WebServices are the target service accesses
Expand Down
38 changes: 29 additions & 9 deletions api/v1alpha1/zz_generated.deepcopy.go

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

35 changes: 21 additions & 14 deletions config/crd/bases/cerberus.snappcloud.io_accesstokens.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,33 @@ spec:
spec:
description: AccessTokenSpec defines the desired state of AccessToken
properties:
allowedWebservices:
description: AllowedWebservices is a list of Webservice that the token
has access to
items:
description: SecretReference represents a Secret Reference. It has
enough information to retrieve secret in any namespace
properties:
name:
description: name is unique within a namespace to reference
a secret resource.
type: string
namespace:
description: namespace defines the space within which the secret
name must be unique.
type: string
type: object
x-kubernetes-map-type: atomic
type: array
domainAllowList:
description: Domain Allow list is a list of Domain glob patterns that
description: AllowedDomains is a list of Domain glob patterns that
will be tested against Referer header
items:
type: string
type: array
ipAllowList:
description: IP Allow List is a list of IP and IP CIDRs that will
be tested against X-Forwarded-For
description: AllowedIPs is a list of IP and IP CIDRs that will be
tested against X-Forwarded-For
items:
type: string
type: array
Expand All @@ -52,17 +70,6 @@ spec:
description: Priority shows the access level of the token
minimum: 0
type: integer
secretRef:
description: Secret Ref points to secret containing the API Key secret
if it exists it will use the token value in it and will create a
new secret if not exists
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
x-kubernetes-map-type: atomic
state:
description: 'State shows the state of the token (whether you use
token or it''s just a draft) Valid values are: - "Active" (default):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ spec:
WebserviceAccessBinding
properties:
subjects:
description: Subjects are the name of AccessTokens which the access
will be granted to
description: Subjects are the name of Namespaces which the access
will be granted to their tokens
items:
type: string
type: array
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/cerberus.snappcloud.io_webservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ spec:
type: string
minimumTokenPriority:
default: 0
description: MinimumTokenPriority tells Cerberus whether it should
stablish the minimum priority threshold for token authentication
description: MinimumTokenPriority tells Cerberus what minimum priority
it should stablish for token authentication
minimum: 0
type: integer
upstreamHttpAuth:
Expand Down
Loading

0 comments on commit dfd8f31

Please sign in to comment.