kubeadm: Remove .AuthorizationModes in the v1alpha2 API

pull/8/head
Lucas Käldström 2018-05-21 08:49:12 +03:00
parent 4f0020d1b4
commit 5687f652db
No known key found for this signature in database
GPG Key ID: 3FA3783D77751514
16 changed files with 25 additions and 109 deletions

View File

@ -39,7 +39,6 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
obj.API.AdvertiseAddress = "foo" obj.API.AdvertiseAddress = "foo"
obj.Networking.ServiceSubnet = "foo" obj.Networking.ServiceSubnet = "foo"
obj.Networking.DNSDomain = "foo" obj.Networking.DNSDomain = "foo"
obj.AuthorizationModes = []string{"foo"}
obj.CertificatesDir = "foo" obj.CertificatesDir = "foo"
obj.APIServerCertSANs = []string{"foo"} obj.APIServerCertSANs = []string{"foo"}
obj.Etcd.ServerCertSANs = []string{"foo"} obj.Etcd.ServerCertSANs = []string{"foo"}

View File

@ -45,10 +45,6 @@ type MasterConfiguration struct {
// NodeName is the name of the node that will host the k8s control plane. // NodeName is the name of the node that will host the k8s control plane.
// Defaults to the hostname if not provided. // Defaults to the hostname if not provided.
NodeName string NodeName string
// AuthorizationModes is a set of authorization modes used inside the cluster.
// If not specified, defaults to Node and RBAC, meaning both the node
// authorizer and RBAC are enabled.
AuthorizationModes []string
// NoTaintMaster will, if set, suppress the tainting of the // NoTaintMaster will, if set, suppress the tainting of the
// master node allowing workloads to be run on it (e.g. in // master node allowing workloads to be run on it (e.g. in
// single node configurations). // single node configurations).

View File

@ -17,6 +17,9 @@ limitations under the License.
package v1alpha1 package v1alpha1
import ( import (
"reflect"
"strings"
"k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
@ -41,6 +44,7 @@ func Convert_v1alpha1_MasterConfiguration_To_kubeadm_MasterConfiguration(in *Mas
} }
UpgradeCloudProvider(in, out) UpgradeCloudProvider(in, out)
UpgradeAuthorizationModes(in, out)
// We don't support migrating information from the .PrivilegedPods field which was removed in v1alpha2 // We don't support migrating information from the .PrivilegedPods field which was removed in v1alpha2
return nil return nil
@ -69,3 +73,14 @@ func UpgradeCloudProvider(in *MasterConfiguration, out *kubeadm.MasterConfigurat
out.ControllerManagerExtraArgs["cloud-provider"] = in.CloudProvider out.ControllerManagerExtraArgs["cloud-provider"] = in.CloudProvider
} }
} }
func UpgradeAuthorizationModes(in *MasterConfiguration, out *kubeadm.MasterConfiguration) {
// If .AuthorizationModes was set to something else than the default, preserve the information via extraargs
if !reflect.DeepEqual(in.AuthorizationModes, strings.Split(DefaultAuthorizationModes, ",")) {
if out.APIServerExtraArgs == nil {
out.APIServerExtraArgs = map[string]string{}
}
out.APIServerExtraArgs["authorization-mode"] = strings.Join(in.AuthorizationModes, ",")
}
}

View File

@ -18,7 +18,6 @@ package v1alpha2
import ( import (
"net/url" "net/url"
"strings"
"time" "time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -42,8 +41,6 @@ const (
DefaultKubernetesVersion = "stable-1.10" DefaultKubernetesVersion = "stable-1.10"
// DefaultAPIBindPort defines default API port // DefaultAPIBindPort defines default API port
DefaultAPIBindPort = 6443 DefaultAPIBindPort = 6443
// DefaultAuthorizationModes defines default authorization modes
DefaultAuthorizationModes = "Node,RBAC"
// DefaultCertificatesDir defines default certificate directory // DefaultCertificatesDir defines default certificate directory
DefaultCertificatesDir = "/etc/kubernetes/pki" DefaultCertificatesDir = "/etc/kubernetes/pki"
// DefaultImageRepository defines default image registry // DefaultImageRepository defines default image registry
@ -96,10 +93,6 @@ func SetDefaults_MasterConfiguration(obj *MasterConfiguration) {
obj.Networking.DNSDomain = DefaultServiceDNSDomain obj.Networking.DNSDomain = DefaultServiceDNSDomain
} }
if len(obj.AuthorizationModes) == 0 {
obj.AuthorizationModes = strings.Split(DefaultAuthorizationModes, ",")
}
if obj.CertificatesDir == "" { if obj.CertificatesDir == "" {
obj.CertificatesDir = DefaultCertificatesDir obj.CertificatesDir = DefaultCertificatesDir
} }

View File

@ -45,10 +45,6 @@ type MasterConfiguration struct {
// NodeName is the name of the node that will host the k8s control plane. // NodeName is the name of the node that will host the k8s control plane.
// Defaults to the hostname if not provided. // Defaults to the hostname if not provided.
NodeName string `json:"nodeName"` NodeName string `json:"nodeName"`
// AuthorizationModes is a set of authorization modes used inside the cluster.
// If not specified, defaults to Node and RBAC, meaning both the node
// authorizer and RBAC are enabled.
AuthorizationModes []string `json:"authorizationModes,omitempty"`
// NoTaintMaster will, if set, suppress the tainting of the // NoTaintMaster will, if set, suppress the tainting of the
// master node allowing workloads to be run on it (e.g. in // master node allowing workloads to be run on it (e.g. in
// single node configurations). // single node configurations).

View File

@ -37,7 +37,6 @@ import (
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
tokenutil "k8s.io/kubernetes/cmd/kubeadm/app/util/token" tokenutil "k8s.io/kubernetes/cmd/kubeadm/app/util/token"
apivalidation "k8s.io/kubernetes/pkg/apis/core/validation" apivalidation "k8s.io/kubernetes/pkg/apis/core/validation"
authzmodes "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes"
"k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig" "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig"
kubeletscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme" kubeletscheme "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/scheme"
kubeletvalidation "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/validation" kubeletvalidation "k8s.io/kubernetes/pkg/kubelet/apis/kubeletconfig/validation"
@ -49,16 +48,9 @@ import (
"k8s.io/kubernetes/pkg/util/node" "k8s.io/kubernetes/pkg/util/node"
) )
// Describes the authorization modes that are enforced by kubeadm
var requiredAuthzModes = []string{
authzmodes.ModeRBAC,
authzmodes.ModeNode,
}
// ValidateMasterConfiguration validates master configuration and collects all encountered errors // ValidateMasterConfiguration validates master configuration and collects all encountered errors
func ValidateMasterConfiguration(c *kubeadm.MasterConfiguration) field.ErrorList { func ValidateMasterConfiguration(c *kubeadm.MasterConfiguration) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
allErrs = append(allErrs, ValidateAuthorizationModes(c.AuthorizationModes, field.NewPath("authorizationModes"))...)
allErrs = append(allErrs, ValidateNetworking(&c.Networking, field.NewPath("networking"))...) allErrs = append(allErrs, ValidateNetworking(&c.Networking, field.NewPath("networking"))...)
allErrs = append(allErrs, ValidateCertSANs(c.APIServerCertSANs, field.NewPath("apiServerCertSANs"))...) allErrs = append(allErrs, ValidateCertSANs(c.APIServerCertSANs, field.NewPath("apiServerCertSANs"))...)
allErrs = append(allErrs, ValidateCertSANs(c.Etcd.ServerCertSANs, field.NewPath("etcd").Child("serverCertSANs"))...) allErrs = append(allErrs, ValidateCertSANs(c.Etcd.ServerCertSANs, field.NewPath("etcd").Child("serverCertSANs"))...)
@ -102,29 +94,6 @@ func ValidateNodeConfiguration(c *kubeadm.NodeConfiguration) field.ErrorList {
return allErrs return allErrs
} }
// ValidateAuthorizationModes validates authorization modes and collects all encountered errors
func ValidateAuthorizationModes(authzModes []string, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
found := map[string]bool{}
for _, authzMode := range authzModes {
if !authzmodes.IsValidAuthorizationMode(authzMode) {
allErrs = append(allErrs, field.Invalid(fldPath, authzMode, "invalid authorization mode"))
}
if found[authzMode] {
allErrs = append(allErrs, field.Invalid(fldPath, authzMode, "duplicate authorization mode"))
continue
}
found[authzMode] = true
}
for _, requiredMode := range requiredAuthzModes {
if !found[requiredMode] {
allErrs = append(allErrs, field.Required(fldPath, fmt.Sprintf("authorization mode %s must be enabled", requiredMode)))
}
}
return allErrs
}
// ValidateDiscovery validates discovery related configuration and collects all encountered errors // ValidateDiscovery validates discovery related configuration and collects all encountered errors
func ValidateDiscovery(c *kubeadm.NodeConfiguration) field.ErrorList { func ValidateDiscovery(c *kubeadm.NodeConfiguration) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}

View File

@ -104,34 +104,6 @@ func TestValidateTokenGroups(t *testing.T) {
} }
} }
func TestValidateAuthorizationModes(t *testing.T) {
var tests = []struct {
s []string
f *field.Path
expected bool
}{
{[]string{""}, nil, false},
{[]string{"rBAC"}, nil, false}, // mode not supported
{[]string{"rBAC", "Webhook"}, nil, false}, // mode not supported
{[]string{"RBAC", "Webhook"}, nil, false}, // mode Node required
{[]string{"Node", "RBAC", "Webhook", "Webhook"}, nil, false}, // no duplicates allowed
{[]string{"not valid"}, nil, false}, // invalid mode
{[]string{"Node", "RBAC"}, nil, true}, // supported
{[]string{"RBAC", "Node"}, nil, true}, // supported
{[]string{"Node", "RBAC", "Webhook", "ABAC"}, nil, true}, // supported
}
for _, rt := range tests {
actual := ValidateAuthorizationModes(rt.s, rt.f)
if (len(actual) == 0) != rt.expected {
t.Errorf(
"failed ValidateAuthorizationModes:\n\texpected: %t\n\t actual: %t",
rt.expected,
(len(actual) == 0),
)
}
}
}
func TestValidateNodeName(t *testing.T) { func TestValidateNodeName(t *testing.T) {
var tests = []struct { var tests = []struct {
s string s string
@ -431,7 +403,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -445,7 +416,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "2001:db8::1/98", ServiceSubnet: "2001:db8::1/98",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -459,7 +429,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -473,7 +442,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
AdvertiseAddress: "1.2.3.4", AdvertiseAddress: "1.2.3.4",
BindPort: 6443, BindPort: 6443,
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -515,7 +483,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
}, },
}, },
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "10.96.0.1/12", ServiceSubnet: "10.96.0.1/12",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",
@ -557,7 +524,6 @@ func TestValidateMasterConfiguration(t *testing.T) {
}, },
}, },
}, },
AuthorizationModes: []string{"Node", "RBAC"},
Networking: kubeadm.Networking{ Networking: kubeadm.Networking{
ServiceSubnet: "2001:db8::1/98", ServiceSubnet: "2001:db8::1/98",
DNSDomain: "cluster.local", DNSDomain: "cluster.local",

View File

@ -252,7 +252,6 @@ func NewInit(cfgPath string, externalcfg *kubeadmapiv1alpha2.MasterConfiguration
} }
glog.Infof("[init] using Kubernetes version: %s\n", cfg.KubernetesVersion) glog.Infof("[init] using Kubernetes version: %s\n", cfg.KubernetesVersion)
glog.Infof("[init] using Authorization modes: %v\n", cfg.AuthorizationModes)
glog.Infoln("[preflight] running pre-flight checks") glog.Infoln("[preflight] running pre-flight checks")

View File

@ -275,11 +275,6 @@ var (
Effect: v1.TaintEffectNoSchedule, Effect: v1.TaintEffectNoSchedule,
} }
// AuthorizationPolicyPath defines the supported location of authorization policy file
AuthorizationPolicyPath = filepath.Join(KubernetesDir, "abac_policy.json")
// AuthorizationWebhookConfigPath defines the supported location of webhook config file
AuthorizationWebhookConfigPath = filepath.Join(KubernetesDir, "webhook_authz.conf")
// DefaultTokenUsages specifies the default functions a token will get // DefaultTokenUsages specifies the default functions a token will get
DefaultTokenUsages = bootstrapapi.KnownTokenUsages DefaultTokenUsages = bootstrapapi.KnownTokenUsages

View File

@ -46,14 +46,13 @@ const (
waitForPodsWithLabel = "wait-for-pods-with-label" waitForPodsWithLabel = "wait-for-pods-with-label"
testConfiguration = ` testConfiguration = `
apiVersion: kubeadm.k8s.io/v1alpha2
kind: MasterConfiguration
api: api:
advertiseAddress: 1.2.3.4 advertiseAddress: 1.2.3.4
bindPort: 6443 bindPort: 6443
apiServerCertSANs: null apiServerCertSANs: null
apiServerExtraArgs: null apiServerExtraArgs: null
authorizationModes:
- Node
- RBAC
certificatesDir: %s certificatesDir: %s
controllerManagerExtraArgs: null controllerManagerExtraArgs: null
etcd: etcd:
@ -508,6 +507,7 @@ func getAPIServerHash(dir string) (string, error) {
return fmt.Sprintf("%x", sha256.Sum256(fileBytes)), nil return fmt.Sprintf("%x", sha256.Sum256(fileBytes)), nil
} }
// TODO: Make this test function use the rest of the "official" API machinery helper funcs we have inside of kubeadm
func getConfig(version, certsDir, etcdDataDir string) (*kubeadmapi.MasterConfiguration, error) { func getConfig(version, certsDir, etcdDataDir string) (*kubeadmapi.MasterConfiguration, error) {
externalcfg := &kubeadmapiv1alpha2.MasterConfiguration{} externalcfg := &kubeadmapiv1alpha2.MasterConfiguration{}
internalcfg := &kubeadmapi.MasterConfiguration{} internalcfg := &kubeadmapi.MasterConfiguration{}

View File

@ -47,7 +47,6 @@ import (
kubeadmdefaults "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1" kubeadmdefaults "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha1"
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/kubernetes/pkg/apis/core/validation" "k8s.io/kubernetes/pkg/apis/core/validation"
authzmodes "k8s.io/kubernetes/pkg/kubeapiserver/authorizer/modes"
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator" "k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
"k8s.io/kubernetes/pkg/util/initsystem" "k8s.io/kubernetes/pkg/util/initsystem"
"k8s.io/kubernetes/pkg/util/procfs" "k8s.io/kubernetes/pkg/util/procfs"
@ -889,16 +888,6 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfi
) )
} }
// Check the config for authorization mode
for _, authzMode := range cfg.AuthorizationModes {
switch authzMode {
case authzmodes.ModeABAC:
checks = append(checks, FileExistingCheck{Path: kubeadmconstants.AuthorizationPolicyPath})
case authzmodes.ModeWebhook:
checks = append(checks, FileExistingCheck{Path: kubeadmconstants.AuthorizationWebhookConfigPath})
}
}
if ip := net.ParseIP(cfg.API.AdvertiseAddress); ip != nil { if ip := net.ParseIP(cfg.API.AdvertiseAddress); ip != nil {
if ip.To4() == nil && ip.To16() != nil { if ip.To4() == nil && ip.To16() != nil {
checks = append(checks, checks = append(checks,

View File

@ -3,15 +3,13 @@ API:
BindPort: 6443 BindPort: 6443
ControlPlaneEndpoint: "" ControlPlaneEndpoint: ""
APIServerCertSANs: null APIServerCertSANs: null
APIServerExtraArgs: null APIServerExtraArgs:
authorization-mode: Node,RBAC,Webhook
APIServerExtraVolumes: null APIServerExtraVolumes: null
AuditPolicyConfiguration: AuditPolicyConfiguration:
LogDir: /var/log/kubernetes/audit LogDir: /var/log/kubernetes/audit
LogMaxAge: 2 LogMaxAge: 2
Path: "" Path: ""
AuthorizationModes:
- Node
- RBAC
CIImageRepository: "" CIImageRepository: ""
CRISocket: /var/run/dockershim.sock CRISocket: /var/run/dockershim.sock
CertificatesDir: /etc/kubernetes/pki CertificatesDir: /etc/kubernetes/pki

View File

@ -10,6 +10,7 @@ auditPolicy:
authorizationModes: authorizationModes:
- Node - Node
- RBAC - RBAC
- Webhook
certificatesDir: /etc/kubernetes/pki certificatesDir: /etc/kubernetes/pki
cloudProvider: "" cloudProvider: ""
clusterName: kubernetes clusterName: kubernetes

View File

@ -10,6 +10,7 @@ auditPolicy:
authorizationModes: authorizationModes:
- Node - Node
- RBAC - RBAC
- Webhook
certificatesDir: /etc/kubernetes/pki certificatesDir: /etc/kubernetes/pki
cloudProvider: "" cloudProvider: ""
clusterName: kubernetes clusterName: kubernetes

View File

@ -2,14 +2,13 @@ api:
advertiseAddress: 192.168.2.2 advertiseAddress: 192.168.2.2
bindPort: 6443 bindPort: 6443
controlPlaneEndpoint: "" controlPlaneEndpoint: ""
apiServerExtraArgs:
authorization-mode: Node,RBAC,Webhook
apiVersion: kubeadm.k8s.io/v1alpha2 apiVersion: kubeadm.k8s.io/v1alpha2
auditPolicy: auditPolicy:
logDir: /var/log/kubernetes/audit logDir: /var/log/kubernetes/audit
logMaxAge: 2 logMaxAge: 2
path: "" path: ""
authorizationModes:
- Node
- RBAC
certificatesDir: /etc/kubernetes/pki certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes clusterName: kubernetes
criSocket: /var/run/dockershim.sock criSocket: /var/run/dockershim.sock