github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/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  
    68  # Needed to use 'sethostname' and 'hostnamectl set-hostname'. See man 7
    69  # capabilities
    70  capability sys_admin,
    71  `
    72  
    73  const hostnameControlConnectedPlugSecComp = `
    74  # Description: Can configure the system hostname.
    75  sethostname
    76  `
    77  
    78  func init() {
    79  	registerIface(&commonInterface{
    80  		name:                  "hostname-control",
    81  		summary:               hostnameControlSummary,
    82  		implicitOnCore:        true,
    83  		implicitOnClassic:     true,
    84  		baseDeclarationSlots:  hostnameControlBaseDeclarationSlots,
    85  		connectedPlugAppArmor: hostnameControlConnectedPlugAppArmor,
    86  		connectedPlugSecComp:  hostnameControlConnectedPlugSecComp,
    87  	})
    88  
    89  }