github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/interfaces/builtin/gpg_keys.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 gpgKeysSummary = `allows reading gpg user configuration and keys and updating gpg's random seed file`
    23  
    24  const gpgKeysBaseDeclarationSlots = `
    25    gpg-keys:
    26      allow-installation:
    27        slot-snap-type:
    28          - core
    29      deny-auto-connection: true
    30  `
    31  
    32  const gpgKeysConnectedPlugAppArmor = `
    33  # Description: Can read gpg user configuration as well as public and private
    34  # keys. Also allows updating gpg's random seed file.
    35  
    36  # Allow gpg encrypt, decrypt, list-keys, verify, sign, etc
    37  /usr/bin/gpg{,1,2,v} ixr,
    38  /usr/share/gnupg/options.skel r,
    39  
    40  owner @{HOME}/.gnupg/{,**} r,
    41  # gpg sometimes updates the trustdb to decide whether or not to update the
    42  # trustdb. For now, silence the denial since no other policy references this
    43  deny @{HOME}/.gnupg/trustdb.gpg w,
    44  
    45  # 'wk' is required for gpg encrypt and sign unless --no-random-seed-file is
    46  # used. Ideally we would not allow this access, but denying it causes gpg to
    47  # hang for all applications that don't specify --no-random-seed-file. Allow it
    48  # with the understanding that this interface already requires a high level of
    49  # trust to access the user's keys and the level of trust for the random_seed
    50  # is commensurate with accessing the private keys.
    51  owner @{HOME}/.gnupg/random_seed wk,
    52  `
    53  
    54  func init() {
    55  	registerIface(&commonInterface{
    56  		name:                  "gpg-keys",
    57  		summary:               gpgKeysSummary,
    58  		implicitOnCore:        true,
    59  		implicitOnClassic:     true,
    60  		baseDeclarationSlots:  gpgKeysBaseDeclarationSlots,
    61  		connectedPlugAppArmor: gpgKeysConnectedPlugAppArmor,
    62  	})
    63  }