]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Add new secret type "tls"
authorJohn Ferlan <jferlan@redhat.com>
Thu, 14 Jul 2016 19:09:08 +0000 (15:09 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 9 Sep 2016 12:20:05 +0000 (08:20 -0400)
Add a new secret usage type known as "tls" - it will handle adding the
secret objects for various TLS objects that need to provide some sort
of passphrase in order to access the credentials.

The format is:

   <secret ephemeral='no' private='no'>
     <description>Sample TLS secret</description>
     <usage type='tls'>
       <name>mumblyfratz</name>
     </usage>
</secret>

Once defined and a passphrase set, future patches will allow the UUID
to be set in the qemu.conf file and thus used as a secret for various
TLS options such as a chardev serial TCP connection, a NBD client/server
connection, and migration.

Signed-off-by: John Ferlan <jferlan@redhat.com>
docs/aclpolkit.html.in
docs/formatsecret.html.in
docs/schemas/secret.rng
include/libvirt/libvirt-secret.h
src/access/viraccessdriverpolkit.c
src/conf/secret_conf.c
src/conf/secret_conf.h
src/conf/virsecretobj.c
tests/secretxml2xmlin/usage-tls.xml [new file with mode: 0644]
tests/secretxml2xmltest.c

index dae0814a828d92db34748bca84e0aae05174d7c3..dd4c5fb3ab5cd132af988908fbedac403a183e41 100644 (file)
           <td>secret_usage_target</td>
           <td>Name of the associated iSCSI target, if any</td>
         </tr>
+        <tr>
+          <td>secret_usage_name</td>
+          <td>Name of the associated TLS secret, if any</td>
+        </tr>
       </tbody>
     </table>
 
index 216a83cca6b71fb8485e1dde284b9778a1c594f1..e4bf50f9e729b43c36bfeb6dac1fbdeb710f00a2 100644 (file)
@@ -41,8 +41,9 @@
       <dd>
         Specifies what this secret is used for.  A mandatory
         <code>type</code> attribute specifies the usage category, currently
-        only <code>volume</code>, <code>ceph</code>, and <code>iscsi</code>
-        are defined. Specific usage categories are described below.
+        only <code>volume</code>, <code>ceph</code>, <code>iscsi</code>,
+        and <code>tls</code> are defined. Specific usage categories
+        are described below.
       </dd>
     </dl>
 
       &lt;/auth&gt;
     </pre>
 
+    <h3><a name="tlsUsageType">Usage type "tls"</a></h3>
+
+    <p>
+      This secret may be used in order to provide the passphrase for the
+      private key used to provide TLS credentials.
+      The <code>&lt;usage type='tls'&gt;</code> element must contain a
+      single <code>name</code> element that specifies a usage name
+      for the secret.
+      <span class="since">Since 2.3.0</span>.
+      The following is an example of the expected XML and processing to
+      define the secret:
+    </p>
+
+    <pre>
+      # cat tls-secret.xml
+      &lt;secret ephemeral='no' private='yes'&gt;
+         &lt;description&gt;sample tls secret&lt;/description&gt;
+         &lt;usage type='tls'&gt;
+            &lt;name&gt;TLS_example&lt;/name&gt;
+         &lt;/usage&gt;
+      &lt;/secret&gt;
+
+      # virsh secret-define tls-secret.xml
+      Secret 718c71bd-67b5-4a2b-87ec-a24e8ca200dc created
+
+      # virsh secret-list
+       UUID                                 Usage
+      -----------------------------------------------------------
+       718c71bd-67b5-4a2b-87ec-a24e8ca200dc  tls TLS_example
+      #
+
+    </pre>
+
+    <p>
+      A secret may also be defined via the
+      <a href="html/libvirt-libvirt-secret.html#virSecretDefineXML">
+       <code>virSecretDefineXML</code></a> API.
+
+      Once the secret is defined, a secret value will need to be set. The
+      secret would be the passphrase used to access the TLS credentials.
+      The following is a simple example of using
+      <code>virsh secret-set-value</code> to set the secret value. The
+      <a href="html/libvirt-libvirt-secret.html#virSecretSetValue">
+      <code>virSecretSetValue</code></a> API may also be used to set
+      a more secure secret without using printable/readable characters.
+    </p>
+
+    <pre>
+      # MYSECRET=`printf %s "letmein" | base64`
+      # virsh secret-set-value 718c71bd-67b5-4a2b-87ec-a24e8ca200dc $MYSECRET
+      Secret value set
+
+    </pre>
+
   </body>
 </html>
index e21e7003253d8ab75ef40720039384fd32bf1fcd..1e94d66e48939786f4e7f6d0d8b9941bcac34be4 100644 (file)
@@ -36,6 +36,7 @@
               <ref name='usagevolume'/>
               <ref name='usageceph'/>
               <ref name='usageiscsi'/>
+              <ref name='usagetls'/>
               <!-- More choices later -->
             </choice>
           </element>
     </element>
   </define>
 
+  <define name='usagetls'>
+    <attribute name='type'>
+      <value>tls</value>
+    </attribute>
+    <element name='name'>
+      <ref name='genericName'/>
+    </element>
+  </define>
+
 </grammar>
index 02728ba6cd41d7edd0d558ab40af1662d1872a0c..2ae36f66b17a049695fcbaa4040698fb74c7c2b4 100644 (file)
@@ -43,6 +43,7 @@ typedef enum {
     VIR_SECRET_USAGE_TYPE_VOLUME = 1,
     VIR_SECRET_USAGE_TYPE_CEPH = 2,
     VIR_SECRET_USAGE_TYPE_ISCSI = 3,
+    VIR_SECRET_USAGE_TYPE_TLS = 4,
 
 # ifdef VIR_ENUM_SENTINELS
     VIR_SECRET_USAGE_TYPE_LAST
index 89bc8908f234d2424b360f76dcd39f229a615949..0d9e0a148a953c72204b5d8ddaf123722ba7e918 100644 (file)
@@ -338,6 +338,19 @@ virAccessDriverPolkitCheckSecret(virAccessManagerPtr manager,
                                           virAccessPermSecretTypeToString(perm),
                                           attrs);
     }   break;
+    case VIR_SECRET_USAGE_TYPE_TLS: {
+        const char *attrs[] = {
+                    "connect_driver", driverName,
+                    "secret_uuid", uuidstr,
+                    "secret_usage_name", secret->usage.name,
+                    NULL,
+                };
+
+        return virAccessDriverPolkitCheck(manager,
+                                         "secret",
+                                         virAccessPermSecretTypeToString(perm),
+                                         attrs);
+    }   break;
     }
 }
 
index d510645496b9e0e272f6c5d3fdf04958745fb000..e662455736cb4e7584e8f4508c4b296fb2dc87c3 100644 (file)
@@ -30,6 +30,7 @@
 #include "secret_conf.h"
 #include "virsecretobj.h"
 #include "virerror.h"
+#include "virstring.h"
 #include "virxml.h"
 #include "viruuid.h"
 
@@ -38,7 +39,7 @@
 VIR_LOG_INIT("conf.secret_conf");
 
 VIR_ENUM_IMPL(virSecretUsage, VIR_SECRET_USAGE_TYPE_LAST,
-              "none", "volume", "ceph", "iscsi")
+              "none", "volume", "ceph", "iscsi", "tls")
 
 const char *
 virSecretUsageIDForDef(virSecretDefPtr def)
@@ -56,6 +57,9 @@ virSecretUsageIDForDef(virSecretDefPtr def)
     case VIR_SECRET_USAGE_TYPE_ISCSI:
         return def->usage.target;
 
+    case VIR_SECRET_USAGE_TYPE_TLS:
+        return def->usage.name;
+
     default:
         return NULL;
     }
@@ -85,6 +89,10 @@ virSecretDefFree(virSecretDefPtr def)
         VIR_FREE(def->usage.target);
         break;
 
+    case VIR_SECRET_USAGE_TYPE_TLS:
+        VIR_FREE(def->usage.name);
+        break;
+
     default:
         VIR_ERROR(_("unexpected secret usage type %d"), def->usage_type);
         break;
@@ -145,6 +153,15 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
         }
         break;
 
+    case VIR_SECRET_USAGE_TYPE_TLS:
+        def->usage.name = virXPathString("string(./usage/name)", ctxt);
+        if (!def->usage.name) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("TLS usage specified, but name is missing"));
+            return -1;
+        }
+        break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected secret usage type %d"),
@@ -297,6 +314,10 @@ virSecretDefFormatUsage(virBufferPtr buf,
         virBufferEscapeString(buf, "<target>%s</target>\n", def->usage.target);
         break;
 
+    case VIR_SECRET_USAGE_TYPE_TLS:
+        virBufferEscapeString(buf, "<name>%s</name>\n", def->usage.name);
+        break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unexpected secret usage type %d"),
index 4584403dcb47f50c5f4bb1ac8f504ef6f5105089..c34880fb099319f5f838f5d3cc4cf93de08050ba 100644 (file)
@@ -40,6 +40,7 @@ struct _virSecretDef {
         char *volume;               /* May be NULL */
         char *ceph;
         char *target;
+        char *name;
     } usage;
 };
 
index 30a5e80f6e40f8e5147a85fc805877894996990b..2bdfe08eab13464e2636d26bf7edf8e4ec339530 100644 (file)
@@ -237,6 +237,11 @@ virSecretObjSearchName(const void *payload,
         if (STREQ(secret->def->usage.target, data->usageID))
             found = 1;
         break;
+
+    case VIR_SECRET_USAGE_TYPE_TLS:
+        if (STREQ(secret->def->usage.name, data->usageID))
+            found = 1;
+        break;
     }
 
  cleanup:
diff --git a/tests/secretxml2xmlin/usage-tls.xml b/tests/secretxml2xmlin/usage-tls.xml
new file mode 100644 (file)
index 0000000..88068b5
--- /dev/null
@@ -0,0 +1,7 @@
+<secret ephemeral='no' private='no'>
+  <uuid>f52a81b2-424e-490c-823d-6bd4235bc572</uuid>
+  <description>Sample TLS Secret</description>
+  <usage type='tls'>
+    <name>mumblyfratz</name>
+  </usage>
+</secret>
index 8dcbb40080b7e1d89c57d628e5033d2cbb47f2e6..714c709090a4cd87411df6df574dfa6449fa9150 100644 (file)
@@ -80,6 +80,7 @@ mymain(void)
     DO_TEST("usage-volume");
     DO_TEST("usage-ceph");
     DO_TEST("usage-iscsi");
+    DO_TEST("usage-tls");
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }