Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append "AppArmor enabled" to the Node ready condition message #31659

Merged
merged 1 commit into from
Aug 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/util/sliceutils"
"k8s.io/kubernetes/pkg/kubelet/volumemanager"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/security/apparmor"
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util/bandwidth"
"k8s.io/kubernetes/pkg/util/clock"
Expand Down Expand Up @@ -736,7 +737,8 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Kub
klet.AddPodSyncLoopHandler(activeDeadlineHandler)
klet.AddPodSyncHandler(activeDeadlineHandler)

klet.AddPodAdmitHandler(lifecycle.NewAppArmorAdmitHandler(kubeCfg.ContainerRuntime))
klet.appArmorValidator = apparmor.NewValidator(kubeCfg.ContainerRuntime)
klet.AddPodAdmitHandler(lifecycle.NewAppArmorAdmitHandler(klet.appArmorValidator))

// apply functional Option's
for _, opt := range kubeDeps.Options {
Expand Down Expand Up @@ -1041,6 +1043,9 @@ type Kubelet struct {

// The bit of the fwmark space to mark packets for dropping.
iptablesDropBit int

// The AppArmor validator for checking whether AppArmor is supported.
appArmorValidator apparmor.Validator
}

// setupDataDirs creates:
Expand Down
7 changes: 7 additions & 0 deletions pkg/kubelet/kubelet_node_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@ func (kl *Kubelet) setNodeReadyCondition(node *api.Node) {
}
}

// Append AppArmor status if it's enabled.
// TODO(timstclair): This is a temporary message until node feature reporting is added.
if newNodeReadyCondition.Status == api.ConditionTrue &&
kl.appArmorValidator != nil && kl.appArmorValidator.ValidateHost() == nil {
newNodeReadyCondition.Message = fmt.Sprintf("%s. AppArmor enabled", newNodeReadyCondition.Message)
}

// Record any soft requirements that were not met in the container manager.
status := kl.containerManager.Status()
if status.SoftRequirements != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/lifecycle/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func getHttpRespBody(resp *http.Response) string {
return ""
}

func NewAppArmorAdmitHandler(runtime string) PodAdmitHandler {
func NewAppArmorAdmitHandler(validator apparmor.Validator) PodAdmitHandler {
return &appArmorAdmitHandler{
Validator: apparmor.NewValidator(runtime),
Validator: validator,
}
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/security/apparmor/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var isDisabledBuild bool
// Interface for validating that a pod with with an AppArmor profile can be run by a Node.
type Validator interface {
Validate(pod *api.Pod) error
ValidateHost() error
}

func NewValidator(runtime string) Validator {
Expand Down Expand Up @@ -64,7 +65,7 @@ func (v *validator) Validate(pod *api.Pod) error {
return nil
}

if v.validateHostErr != nil {
if v.ValidateHost() != nil {
return v.validateHostErr
}

Expand All @@ -87,6 +88,10 @@ func (v *validator) Validate(pod *api.Pod) error {
return nil
}

func (v *validator) ValidateHost() error {
return v.validateHostErr
}

// Verify that the host and runtime is capable of enforcing AppArmor profiles.
func validateHost(runtime string) error {
// Check feature-gates
Expand Down