github.com/rigado/snapd@v2.42.5-go-mod+incompatible/interfaces/builtin/hostname_control.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2018 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 hostnameControlSummary = `allows configuring the system hostname`
    23  
    24  const hostnameControlBaseDeclarationSlots = `
    25    hostname-control:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  const hostnameControlConnectedPlugAppArmor = `
    33  # Description: Can configure the system hostname.
    34  # /{,usr/}bin/hostname ixr, # already allowed by default
    35  /etc/hostname w,            # read allowed by default
    36  
    37  # on core /etc/hostname is a link to /etc/writable/hostname
    38  /etc/writable/hostname w,
    39  
    40  #include <abstractions/dbus-strict>
    41  /{,usr/}{,s}bin/hostnamectl           ixr,
    42  
    43  # Allow access to hostname system service
    44  # do not use peer=(label=unconfined) here since this is DBus activated
    45  dbus (send)
    46      bus=system
    47      path=/org/freedesktop/hostname1
    48      interface=org.freedesktop.DBus.Properties
    49      member="Get{,All}",
    50  dbus (send)
    51      bus=system
    52      path=/org/freedesktop/hostname1
    53      interface=org.freedesktop.DBus.Introspectable
    54      member=Introspect,
    55  
    56  dbus (receive)
    57      bus=system
    58      path=/org/freedesktop/hostname1
    59      interface=org.freedesktop.DBus.Properties
    60      member=PropertiesChanged
    61      peer=(label=unconfined),
    62  dbus(receive, send)
    63      bus=system
    64      path=/org/freedesktop/hostname1
    65      interface=org.freedesktop.hostname1
    66      member=Set{,Pretty,Static}Hostname
    67      peer=(label=unconfined),
    68  
    69  # Needed to use 'sethostname' and 'hostnamectl set-hostname'. See man 7
    70  # capabilities
    71  capability sys_admin,
    72  `
    73  
    74  const hostnameControlConnectedPlugSecComp = `
    75  # Description: Can configure the system hostname.
    76  sethostname
    77  `
    78  
    79  func init() {
    80  	registerIface(&commonInterface{
    81  		name:                  "hostname-control",
    82  		summary:               hostnameControlSummary,
    83  		implicitOnCore:        true,
    84  		implicitOnClassic:     true,
    85  		baseDeclarationSlots:  hostnameControlBaseDeclarationSlots,
    86  		connectedPlugAppArmor: hostnameControlConnectedPlugAppArmor,
    87  		connectedPlugSecComp:  hostnameControlConnectedPlugSecComp,
    88  		reservedForOS:         true,
    89  	})
    90  
    91  }