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

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 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 builtin
    21  
    22  const networkSetupControlSummary = `allows access to netplan configuration`
    23  
    24  const networkSetupControlBaseDeclarationSlots = `
    25    network-setup-control:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  const networkSetupControlConnectedPlugAppArmor = `
    33  # Description: Can read/write netplan configuration files
    34  
    35  # Allow use of the netplan binary from the base snap. With this interface, this 
    36  # is expected to be able to apply and generate new network configuration, as 
    37  # well as get information about the current network configuration.
    38  /usr/sbin/netplan ixr,
    39  # core18+ has /usr/sbin/netplan as a symlink to this script
    40  /usr/share/netplan/netplan.script ixr,
    41  # netplan related files
    42  /usr/share/netplan/ r,
    43  /usr/share/netplan/** r,
    44  
    45  # Netplan uses busctl internally, so allow using that as well
    46  /usr/bin/busctl ixr,
    47  
    48  /etc/netplan/{,**} rw,
    49  /etc/network/{,**} rw,
    50  /etc/systemd/network/{,**} rw,
    51  
    52  # netplan generate
    53  /run/ r,
    54  /run/systemd/network/{,**} r,
    55  /run/systemd/network/*-netplan-* w,
    56  /run/NetworkManager/conf.d/{,**} r,
    57  /run/NetworkManager/conf.d/*netplan*.conf* w,
    58  
    59  /run/udev/rules.d/ rw,                 # needed for cloud-init
    60  /run/udev/rules.d/[0-9]*-netplan-* rw,
    61  
    62  #include <abstractions/dbus-strict>
    63  
    64  # Allow use of Netplan Generate API, used to generate network configuration
    65  dbus (send)
    66  	bus=system
    67  	interface=io.netplan.Netplan
    68  	path=/io/netplan/Netplan
    69  	member=Generate
    70  	peer=(label=unconfined),
    71  
    72  # Allow use of Netplan Apply API, used to apply network configuration
    73  dbus (send)
    74      bus=system
    75      interface=io.netplan.Netplan
    76      path=/io/netplan/Netplan
    77  	member=Apply
    78  	peer=(label=unconfined),
    79  
    80  # Allow use of Netplan Info API, used to get information on available netplan
    81  # features and version
    82  dbus (send)
    83  	bus=system
    84  	interface=io.netplan.Netplan
    85  	path=/io/netplan/Netplan
    86  	member=Info
    87  	peer=(label=unconfined),
    88  `
    89  
    90  func init() {
    91  	registerIface(&commonInterface{
    92  		name:                  "network-setup-control",
    93  		summary:               networkSetupControlSummary,
    94  		implicitOnCore:        true,
    95  		implicitOnClassic:     true,
    96  		baseDeclarationSlots:  networkSetupControlBaseDeclarationSlots,
    97  		connectedPlugAppArmor: networkSetupControlConnectedPlugAppArmor,
    98  	})
    99  }