Skip to content
Snippets Groups Projects
  1. Feb 23, 2023
  2. Jun 25, 2021
  3. Jun 02, 2021
  4. Nov 18, 2020
  5. Oct 29, 2020
  6. Oct 13, 2020
  7. Oct 12, 2020
  8. Sep 18, 2020
  9. Aug 21, 2020
  10. May 15, 2020
    • Markus Armbruster's avatar
      qom: Drop parameter @errp of object_property_add() & friends · d2623129
      Markus Armbruster authored
      
      The only way object_property_add() can fail is when a property with
      the same name already exists.  Since our property names are all
      hardcoded, failure is a programming error, and the appropriate way to
      handle it is passing &error_abort.
      
      Same for its variants, except for object_property_add_child(), which
      additionally fails when the child already has a parent.  Parentage is
      also under program control, so this is a programming error, too.
      
      We have a bit over 500 callers.  Almost half of them pass
      &error_abort, slightly fewer ignore errors, one test case handles
      errors, and the remaining few callers pass them to their own callers.
      
      The previous few commits demonstrated once again that ignoring
      programming errors is a bad idea.
      
      Of the few ones that pass on errors, several violate the Error API.
      The Error ** argument must be NULL, &error_abort, &error_fatal, or a
      pointer to a variable containing NULL.  Passing an argument of the
      latter kind twice without clearing it in between is wrong: if the
      first call sets an error, it no longer points to NULL for the second
      call.  ich9_pm_add_properties(), sparc32_ledma_realize(),
      sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
      are wrong that way.
      
      When the one appropriate choice of argument is &error_abort, letting
      users pick the argument is a bad idea.
      
      Drop parameter @errp and assert the preconditions instead.
      
      There's one exception to "duplicate property name is a programming
      error": the way object_property_add() implements the magic (and
      undocumented) "automatic arrayification".  Don't drop @errp there.
      Instead, rename object_property_add() to object_property_try_add(),
      and add the obvious wrapper object_property_add().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200505152926.18877-15-armbru@redhat.com>
      [Two semantic rebase conflicts resolved]
      d2623129
  11. Feb 07, 2020
  12. Jun 12, 2019
  13. May 13, 2019
  14. Apr 02, 2019
    • Daniel P. Berrangé's avatar
      filemon: fix watch IDs to avoid potential wraparound issues · b4682a63
      Daniel P. Berrangé authored
      
      Watch IDs are allocated from incrementing a int counter against
      the QFileMonitor object. In very long life QEMU processes with
      a huge amount of USB MTP activity creating & deleting directories
      it is just about conceivable that the int counter can wrap
      around. This would result in incorrect behaviour of the file
      monitor watch APIs due to clashing watch IDs.
      
      Instead of trying to detect this situation, this patch changes
      the way watch IDs are allocated. It is turned into an int64_t
      variable where the high 32 bits are set from the underlying
      inotify "int" ID. This gives an ID that is guaranteed unique
      for the directory as a whole, and we can rely on the kernel
      to enforce this. QFileMonitor then sets the low 32 bits from
      a per-directory counter.
      
      The USB MTP device only sets watches on the directory as a
      whole, not files within, so there is no risk of guest
      triggered wrap around on the low 32 bits.
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      b4682a63
  15. Mar 22, 2019
  16. Feb 26, 2019
    • Daniel P. Berrangé's avatar
      authz: add QAuthZPAM object type for authorizing using PAM · 8953caf3
      Daniel P. Berrangé authored
      
      Add an authorization backend that talks to PAM to check whether the user
      identity is allowed. This only uses the PAM account validation facility,
      which is essentially just a check to see if the provided username is permitted
      access. It doesn't use the authentication or session parts of PAM, since
      that's dealt with by the relevant part of QEMU (eg VNC server).
      
      Consider starting QEMU with a VNC server and telling it to use TLS with
      x509 client certificates and configuring it to use an PAM to validate
      the x509 distinguished name. In this example we're telling it to use PAM
      for the QAuthZ impl with a service name of "qemu-vnc"
      
       $ qemu-system-x86_64 \
           -object tls-creds-x509,id=tls0,dir=/home/berrange/security/qemutls,\
                   endpoint=server,verify-peer=yes \
           -object authz-pam,id=authz0,service=qemu-vnc \
           -vnc :1,tls-creds=tls0,tls-authz=authz0
      
      This requires an /etc/pam/qemu-vnc file to be created with the auth
      rules. A very simple file based whitelist can be setup using
      
        $ cat > /etc/pam/qemu-vnc <<EOF
        account         requisite       pam_listfile.so item=user sense=allow file=/etc/qemu/vnc.allow
        EOF
      
      The /etc/qemu/vnc.allow file simply contains one username per line. Any
      username not in the file is denied. The usernames in this example are
      the x509 distinguished name from the client's x509 cert.
      
        $ cat > /etc/qemu/vnc.allow <<EOF
        CN=laptop.berrange.com,O=Berrange Home,L=London,ST=London,C=GB
        EOF
      
      More interesting would be to configure PAM to use an LDAP backend, so
      that the QEMU authorization check data can be centralized instead of
      requiring each compute host to have file maintained.
      
      The main limitation with this PAM module is that the rules apply to all
      QEMU instances on the host. Setting up different rules per VM, would
      require creating a separate PAM service name & config file for every
      guest. An alternative approach for the future might be to not pass in
      the plain username to PAM, but instead combine the VM name or UUID with
      the username. This requires further consideration though.
      
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      8953caf3
    • Daniel P. Berrangé's avatar
      authz: add QAuthZListFile object type for a file access control list · 55d86984
      Daniel P. Berrangé authored
      
      Add a QAuthZListFile object type that implements the QAuthZ interface. This
      built-in implementation is a proxy around the QAuthZList object type,
      initializing it from an external file, and optionally, automatically
      reloading it whenever it changes.
      
      To create an instance of this object via the QMP monitor, the syntax
      used would be:
      
            {
              "execute": "object-add",
              "arguments": {
                "qom-type": "authz-list-file",
                "id": "authz0",
                "props": {
                  "filename": "/etc/qemu/vnc.acl",
      	    "refresh": true
                }
              }
            }
      
      If "refresh" is "yes", inotify is used to monitor the file,
      automatically reloading changes. If an error occurs during reloading,
      all authorizations will fail until the file is next successfully
      loaded.
      
      The /etc/qemu/vnc.acl file would contain a JSON representation of a
      QAuthZList object
      
          {
            "rules": [
               { "match": "fred", "policy": "allow", "format": "exact" },
               { "match": "bob", "policy": "allow", "format": "exact" },
               { "match": "danb", "policy": "deny", "format": "glob" },
               { "match": "dan*", "policy": "allow", "format": "exact" },
            ],
            "policy": "deny"
          }
      
      This sets up an authorization rule that allows 'fred', 'bob' and anyone
      whose name starts with 'dan', except for 'danb'. Everyone unmatched is
      denied.
      
      The object can be loaded on the comand line using
      
         -object authz-list-file,id=authz0,filename=/etc/qemu/vnc.acl,refresh=yes
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      55d86984
    • Daniel P. Berrangé's avatar
      authz: add QAuthZList object type for an access control list · c8c99887
      Daniel P. Berrangé authored
      
      Add a QAuthZList object type that implements the QAuthZ interface. This
      built-in implementation maintains a trivial access control list with a
      sequence of match rules and a final default policy. This replicates the
      functionality currently provided by the qemu_acl module.
      
      To create an instance of this object via the QMP monitor, the syntax
      used would be:
      
        {
          "execute": "object-add",
          "arguments": {
            "qom-type": "authz-list",
            "id": "authz0",
            "props": {
              "rules": [
                 { "match": "fred", "policy": "allow", "format": "exact" },
                 { "match": "bob", "policy": "allow", "format": "exact" },
                 { "match": "danb", "policy": "deny", "format": "glob" },
                 { "match": "dan*", "policy": "allow", "format": "exact" },
              ],
              "policy": "deny"
            }
          }
        }
      
      This sets up an authorization rule that allows 'fred', 'bob' and anyone
      whose name starts with 'dan', except for 'danb'. Everyone unmatched is
      denied.
      
      It is not currently possible to create this via -object, since there is
      no syntax supported to specify non-scalar properties for objects. This
      is likely to be addressed by later support for using JSON with -object,
      or an equivalent approach.
      
      In any case the future "authz-listfile" object can be used from the
      CLI and is likely a better choice, as it allows the ACL to be refreshed
      automatically on change.
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      c8c99887
    • Daniel P. Berrangé's avatar
      authz: add QAuthZSimple object type for easy whitelist auth checks · fb5c4ebc
      Daniel P. Berrangé authored
      
      In many cases a single VM will just need to whitelist a single identity
      as the allowed user of network services. This is especially the case for
      TLS live migration (optionally with NBD storage) where we just need to
      whitelist the x509 certificate distinguished name of the source QEMU
      host.
      
      Via QMP this can be configured with:
      
        {
          "execute": "object-add",
          "arguments": {
            "qom-type": "authz-simple",
            "id": "authz0",
            "props": {
              "identity": "fred"
            }
          }
        }
      
      Or via the command line
      
        -object authz-simple,id=authz0,identity=fred
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      fb5c4ebc
    • Daniel P. Berrangé's avatar
      authz: add QAuthZ object as an authorization base class · 5b76dd13
      Daniel P. Berrangé authored
      
      The current qemu_acl module provides a simple access control list
      facility inside QEMU, which is used via a set of monitor commands
      acl_show, acl_policy, acl_add, acl_remove & acl_reset.
      
      Note there is no ability to create ACLs - the network services (eg VNC
      server) were expected to create ACLs that they want to check.
      
      There is also no way to define ACLs on the command line, nor potentially
      integrate with external authorization systems like polkit, pam, ldap
      lookup, etc.
      
      The QAuthZ object defines a minimal abstract QOM class that can be
      subclassed for creating different authorization providers.
      
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      5b76dd13
Loading