Skip to content

Commit

Permalink
feat(cluster): enabled authn by x509 and authz in webhook mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiezzhao authored and tke-robot committed Jul 1, 2020
1 parent 38c227f commit f447e37
Show file tree
Hide file tree
Showing 164 changed files with 2,363 additions and 1,031 deletions.
5 changes: 5 additions & 0 deletions api/platform/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ func (in *Cluster) Host() (string, error) {

return fmt.Sprintf("%s:%d", address.Host, address.Port), nil
}

func (in *Cluster) AuthzWebhookEnable() bool {
return in.Spec.Features.AuthzWebhookAddr != nil &&
(in.Spec.Features.AuthzWebhookAddr.Builtin != nil || in.Spec.Features.AuthzWebhookAddr.External != nil)
}
17 changes: 17 additions & 0 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ type ClusterFeature struct {
Hooks map[HookType]string
// +optional
CSIOperator *CSIOperatorFeature
// For kube-apiserver authorization webhook
// +optional
AuthzWebhookAddr *AuthzWebhookAddr
}

type HA struct {
Expand Down Expand Up @@ -359,6 +362,20 @@ type CSIOperatorFeature struct {
Version string
}

type AuthzWebhookAddr struct {
// +optional
Builtin *BuiltinAuthzWebhookAddr
// +optional
External *ExternalAuthzWebhookAddr
}

type BuiltinAuthzWebhookAddr struct{}

type ExternalAuthzWebhookAddr struct {
IP string `json:"ip" protobuf:"bytes,1,name=ip"`
Port int32 `json:"port" protobuf:"varint,2,name=port"`
}

const (
HookPreInstall HookType = "PreInstall"
HookPostInstall HookType = "PostInstall"
Expand Down
21 changes: 21 additions & 0 deletions api/platform/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"math/rand"
"time"

"tkestack.io/tke/pkg/util/http"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"tkestack.io/tke/pkg/util/ssh"
)
Expand Down Expand Up @@ -147,3 +149,22 @@ func (in *Cluster) Host() (string, error) {

return fmt.Sprintf("%s:%d", address.Host, address.Port), nil
}

func (in *Cluster) AuthzWebhookEnable() bool {
return in.Spec.Features.AuthzWebhookAddr != nil &&
(in.Spec.Features.AuthzWebhookAddr.Builtin != nil || in.Spec.Features.AuthzWebhookAddr.External != nil)
}

func (in *Cluster) AuthzWebhookExternEndpoint() (string, bool) {
if in.Spec.Features.AuthzWebhookAddr == nil {
return "", false
}

if in.Spec.Features.AuthzWebhookAddr.External == nil {
return "", false
}

ip := in.Spec.Features.AuthzWebhookAddr.External.IP
port := int(in.Spec.Features.AuthzWebhookAddr.External.Port)
return http.MakeEndpoint("https", ip, port, "/auth/authz"), true
}
Loading

0 comments on commit f447e37

Please sign in to comment.