Merge pull request #13100 from pweil-/cap-priv-sources

use privileged source object
This commit is contained in:
Yu-Ju Hong 2015-08-25 16:10:50 -07:00
commit 3bc2157889
5 changed files with 31 additions and 11 deletions

View File

@ -294,7 +294,9 @@ func (s *APIServer) Run(_ []string) error {
capabilities.Initialize(capabilities.Capabilities{ capabilities.Initialize(capabilities.Capabilities{
AllowPrivileged: s.AllowPrivileged, AllowPrivileged: s.AllowPrivileged,
// TODO(vmarmol): Implement support for HostNetworkSources. // TODO(vmarmol): Implement support for HostNetworkSources.
PrivilegedSources: capabilities.PrivilegedSources{
HostNetworkSources: []string{}, HostNetworkSources: []string{},
},
PerConnectionBandwidthLimitBytesPerSec: s.MaxConnectionBytesPerSec, PerConnectionBandwidthLimitBytesPerSec: s.MaxConnectionBytesPerSec,
}) })

View File

@ -642,7 +642,11 @@ func RunKubelet(kcfg *KubeletConfig, builder KubeletBuilder) error {
} else { } else {
glog.Warning("No api server defined - no events will be sent to API server.") glog.Warning("No api server defined - no events will be sent to API server.")
} }
capabilities.Setup(kcfg.AllowPrivileged, kcfg.HostNetworkSources, 0)
privilegedSources := capabilities.PrivilegedSources{
HostNetworkSources: kcfg.HostNetworkSources,
}
capabilities.Setup(kcfg.AllowPrivileged, privilegedSources, 0)
credentialprovider.SetPreferredDockercfgPath(kcfg.RootDirectory) credentialprovider.SetPreferredDockercfgPath(kcfg.RootDirectory)

View File

@ -25,13 +25,21 @@ import (
type Capabilities struct { type Capabilities struct {
AllowPrivileged bool AllowPrivileged bool
// List of pod sources for which using host network is allowed. // Pod sources from which to allow privileged capabilities like host networking, sharing the host
HostNetworkSources []string // IPC namespace, and sharing the host PID namespace.
PrivilegedSources PrivilegedSources
// PerConnectionBandwidthLimitBytesPerSec limits the throughput of each connection (currently only used for proxy, exec, attach) // PerConnectionBandwidthLimitBytesPerSec limits the throughput of each connection (currently only used for proxy, exec, attach)
PerConnectionBandwidthLimitBytesPerSec int64 PerConnectionBandwidthLimitBytesPerSec int64
} }
// PrivilegedSources defines the pod sources allowed to make privileged requests for certain types
// of capabilities like host networking, sharing the host IPC namespace, and sharing the host PID namespace.
type PrivilegedSources struct {
// List of pod sources for which using host network is allowed.
HostNetworkSources []string
}
// TODO: Clean these up into a singleton // TODO: Clean these up into a singleton
var once sync.Once var once sync.Once
var lock sync.Mutex var lock sync.Mutex
@ -46,10 +54,10 @@ func Initialize(c Capabilities) {
} }
// Setup the capability set. It wraps Initialize for improving usibility. // Setup the capability set. It wraps Initialize for improving usibility.
func Setup(allowPrivileged bool, hostNetworkSources []string, perConnectionBytesPerSec int64) { func Setup(allowPrivileged bool, privilegedSources PrivilegedSources, perConnectionBytesPerSec int64) {
Initialize(Capabilities{ Initialize(Capabilities{
AllowPrivileged: allowPrivileged, AllowPrivileged: allowPrivileged,
HostNetworkSources: hostNetworkSources, PrivilegedSources: privilegedSources,
PerConnectionBandwidthLimitBytesPerSec: perConnectionBytesPerSec, PerConnectionBandwidthLimitBytesPerSec: perConnectionBytesPerSec,
}) })
} }
@ -69,7 +77,9 @@ func Get() Capabilities {
if capabilities == nil { if capabilities == nil {
Initialize(Capabilities{ Initialize(Capabilities{
AllowPrivileged: false, AllowPrivileged: false,
PrivilegedSources: PrivilegedSources{
HostNetworkSources: []string{}, HostNetworkSources: []string{},
},
}) })
} }
return *capabilities return *capabilities

View File

@ -2831,7 +2831,9 @@ func TestHostNetworkAllowed(t *testing.T) {
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
capabilities.SetForTests(capabilities.Capabilities{ capabilities.SetForTests(capabilities.Capabilities{
PrivilegedSources: capabilities.PrivilegedSources{
HostNetworkSources: []string{ApiserverSource, FileSource}, HostNetworkSources: []string{ApiserverSource, FileSource},
},
}) })
pod := &api.Pod{ pod := &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
@ -2861,7 +2863,9 @@ func TestHostNetworkDisallowed(t *testing.T) {
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
capabilities.SetForTests(capabilities.Capabilities{ capabilities.SetForTests(capabilities.Capabilities{
PrivilegedSources: capabilities.PrivilegedSources{
HostNetworkSources: []string{}, HostNetworkSources: []string{},
},
}) })
pod := &api.Pod{ pod := &api.Pod{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{

View File

@ -66,7 +66,7 @@ func allowHostNetwork(pod *api.Pod) (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
for _, source := range capabilities.Get().HostNetworkSources { for _, source := range capabilities.Get().PrivilegedSources.HostNetworkSources {
if source == podSource { if source == podSource {
return true, nil return true, nil
} }