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

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016 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 timezoneControlSummary = `allows setting system timezone`
    23  
    24  const timezoneControlBaseDeclarationSlots = `
    25    timezone-control:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  // http://bazaar.launchpad.net/~ubuntu-security/ubuntu-core-security/trunk/view/head:/data/apparmor/policygroups/ubuntu-core/16.04/timezone-control
    33  const timezoneControlConnectedPlugAppArmor = `
    34  # Description: Can manage timezones directly separate from 'config ubuntu-core'.
    35  # Can change timezone via timedated D-Bus interface,
    36  # Can read all properties of /org/freedesktop/timedate1 D-Bus object, see:
    37  # https://www.freedesktop.org/wiki/Software/systemd/timedated/
    38  
    39  #include <abstractions/dbus-strict>
    40  
    41  /usr/share/zoneinfo/      r,
    42  /usr/share/zoneinfo/**    r,
    43  /etc/{,writable/}timezone rw,
    44  /etc/{,writable/}localtime rw,
    45  /etc/{,writable/}localtime.tmp rw, # Required for the timedatectl wrapper (LP: #1650688)
    46  
    47  # Introspection of org.freedesktop.timedate1
    48  # do not use peer=(label=unconfined) here since this is DBus activated
    49  dbus (send)
    50      bus=system
    51      path=/org/freedesktop/timedate1
    52      interface=org.freedesktop.DBus.Introspectable
    53      member=Introspect,
    54  
    55  dbus (send)
    56      bus=system
    57      path=/org/freedesktop/timedate1
    58      interface=org.freedesktop.timedate1
    59      member="SetTimezone"
    60      peer=(label=unconfined),
    61  
    62  dbus (send)
    63      bus=system
    64      path=/org/freedesktop/timedate1
    65      interface=org.freedesktop.timedate1
    66      member="ListTimezones"
    67      peer=(label=unconfined),
    68  
    69  # Read all properties from timedate1
    70  # do not use peer=(label=unconfined) here since this is DBus activated
    71  dbus (send)
    72      bus=system
    73      path=/org/freedesktop/timedate1
    74      interface=org.freedesktop.DBus.Properties
    75      member=Get{,All},
    76  
    77  # Receive timedate1 property changed events
    78  dbus (receive)
    79      bus=system
    80      path=/org/freedesktop/timedate1
    81      interface=org.freedesktop.DBus.Properties
    82      member=PropertiesChanged
    83      peer=(label=unconfined),
    84  
    85  # As the core snap ships the timedatectl utility we can also allow
    86  # clients to use it now that they have access to the relevant
    87  # D-Bus method for setting the timezone via timedatectl's set-timezone
    88  # command.
    89  /usr/bin/timedatectl{,.real} ixr,
    90  
    91  # Silence this noisy denial. systemd utilities look at /proc/1/environ to see
    92  # if running in a container, but they will fallback gracefully. No other
    93  # interfaces allow this denial, so no problems with silencing it for now. Note
    94  # that allowing this triggers a 'ptrace trace peer=unconfined' denial, which we
    95  # want to avoid.
    96  deny @{PROC}/1/environ r,
    97  `
    98  
    99  func init() {
   100  	registerIface(&commonInterface{
   101  		name:                  "timezone-control",
   102  		summary:               timezoneControlSummary,
   103  		implicitOnCore:        true,
   104  		implicitOnClassic:     true,
   105  		baseDeclarationSlots:  timezoneControlBaseDeclarationSlots,
   106  		connectedPlugAppArmor: timezoneControlConnectedPlugAppArmor,
   107  	})
   108  }