gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/backends/backends.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2022 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package backends
    21  
    22  import (
    23  	"gitee.com/mysnapcore/mysnapd/interfaces"
    24  	"gitee.com/mysnapcore/mysnapd/interfaces/apparmor"
    25  	"gitee.com/mysnapcore/mysnapd/interfaces/dbus"
    26  	"gitee.com/mysnapcore/mysnapd/interfaces/kmod"
    27  	"gitee.com/mysnapcore/mysnapd/interfaces/mount"
    28  	"gitee.com/mysnapcore/mysnapd/interfaces/polkit"
    29  	"gitee.com/mysnapcore/mysnapd/interfaces/seccomp"
    30  	"gitee.com/mysnapcore/mysnapd/interfaces/systemd"
    31  	"gitee.com/mysnapcore/mysnapd/interfaces/udev"
    32  	"gitee.com/mysnapcore/mysnapd/logger"
    33  	apparmor_sandbox "gitee.com/mysnapcore/mysnapd/sandbox/apparmor"
    34  )
    35  
    36  // All returns a set of all available security backends.
    37  func All() []interfaces.SecurityBackend {
    38  	all := []interfaces.SecurityBackend{
    39  		// Because of how the GPIO interface is implemented the systemd backend
    40  		// must be earlier in the sequence than the apparmor backend.
    41  		&systemd.Backend{},
    42  		&seccomp.Backend{},
    43  		&dbus.Backend{},
    44  		&udev.Backend{},
    45  		&mount.Backend{},
    46  		&kmod.Backend{},
    47  		&polkit.Backend{},
    48  	}
    49  
    50  	// TODO use something like:
    51  	// level, summary := apparmor.ProbeResults()
    52  
    53  	// TODO: on this should become a user-visible message via the user-warning
    54  	// framework, so that users are aware that we have non-strict confinement.
    55  	// By printing this directly we ensure it will end up the journal for the
    56  	// snapd.service. This aspect should be retained even after the switch to
    57  	// user-warning.
    58  	logger.Noticef("AppArmor status: %s\n", apparmor_sandbox.Summary())
    59  
    60  	// Enable apparmor backend if there is any level of apparmor support,
    61  	// including partial feature set. This will allow snap-confine to always
    62  	// link to apparmor and check if it is enabled on boot, knowing that there
    63  	// is always *some* profile to apply to each snap process.
    64  	//
    65  	// When some features are missing the backend will generate more permissive
    66  	// profiles that keep applications operational, in forced-devmode.
    67  	switch apparmor_sandbox.ProbedLevel() {
    68  	case apparmor_sandbox.Partial, apparmor_sandbox.Full:
    69  		all = append(all, &apparmor.Backend{})
    70  	}
    71  	return all
    72  }