容器 API - 用户指南¶
容器资源是 barbican 的组织核心。它创建了一个逻辑对象,可用于保存密钥引用。在处理和访问数百个密钥时,这非常有用。
这些类型都有明确的限制,规定了应在其中保存哪种类型的密钥。这些将在各自的章节中进行详细说明。
本指南将假定您正在使用 barbican 的本地运行开发环境。 如果您需要设置方面的帮助,请参考 开发指南。
通用容器¶
通用容器用于用户可能希望创建的任何类型的容器。对可以保存在容器中的密钥类型或数量没有限制。
通用容器的一个用例示例是在同一个容器引用中存储多个密码
{
"type": "generic",
"status": "ACTIVE",
"name": "Test Environment User Passwords",
"consumers": [],
"container_ref": "https://{barbican_host}/v1/containers/{uuid}",
"secret_refs": [
{
"name": "test_admin_user",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "test_audit_user",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
}
],
"created": "2015-03-30T21:10:45.417835",
"updated": "2015-03-30T21:10:45.417835"
}
有关创建通用容器的更多信息,请参考 创建通用容器 部分。
证书容器¶
证书容器用于存储与证书相关的以下密钥
证书
私钥(可选)
私钥密码(可选)
中间证书(可选)
{
"type": "certificate",
"status": "ACTIVE",
"name": "Example.com Certificates",
"consumers": [],
"container_ref": "https://{barbican_host}/v1/containers/{uuid}",
"secret_refs": [
{
"name": "certificate",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "private_key",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "private_key_passphrase",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "intermediates",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
}
],
"created": "2015-03-30T21:10:45.417835",
"updated": "2015-03-30T21:10:45.417835"
}
引用为“证书”的密钥的有效负载应为 PEM 格式的 x509 证书。
引用为“中间证书”的密钥的有效负载应为 PEM 格式的 PKCS7 证书链。
有关创建证书容器的更多信息,请参考 创建证书容器 部分。
RSA 容器¶
RSA 容器用于存储 RSA 公钥、私钥和私钥密码。
{
"type": "rsa",
"status": "ACTIVE",
"name": "John Smith RSA",
"consumers": [],
"container_ref": "https://{barbican_host}/v1/containers/{uuid}",
"secret_refs": [
{
"name": "private_key",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "private_key_passphrase",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
},
{
"name": "public_key",
"secret_ref": "https://{barbican_host}/v1/secrets/{uuid}"
}
],
"created": "2015-03-30T21:10:45.417835",
"updated": "2015-03-30T21:10:45.417835"
}
有关创建证书容器的更多信息,请参考 创建 RSA 容器 部分。
如何创建容器¶
为了创建容器,我们首先需要密钥。如果您不熟悉创建密钥,请花一些时间参考 密钥用户指南,然后再继续。
创建通用容器¶
要创建通用容器,我们必须有一个要存储的密钥。
curl -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type:application/json" -d '{
"type": "generic",
"name": "generic name",
"secret_refs": [
{
"name": "a secret",
"secret_ref": "https://:9311/v1/secrets/feac9896-49e9-49e0-9484-1a6153c9498b"
}
]
}' https://:9311/v1/containers
这应该提供如下响应
{"container_ref": "https://:9311/v1/containers/0fecaec4-7cd7-4e70-a760-cc7eaf5c3afb"}
这是我们的容器引用。我们需要它来检索容器。跳转到 如何检索容器,以确保我们的容器已按预期存储。
创建证书容器¶
要创建证书容器,我们必须有一个要存储的密钥。如我们在 证书容器部分 中提到的那样,您需要提供一个名为 certificate 的密钥,但也可以包含名为 private_key、private_key_passphrase 和 intermediates 的可选密钥。
curl -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type:application/json" -d '{
"type": "certificate",
"name": "certificate container",
"secret_refs": [
{
"name": "certificate",
"secret_ref": "https://:9311/v1/secrets/f91b84ac-fb19-416b-87dc-e7e41b7f6039"
},
{
"name": "private_key",
"secret_ref": "https://:9311/v1/secrets/feac9896-49e9-49e0-9484-1a6153c9498b"
},
{
"name": "private_key_passphrase",
"secret_ref": "https://:9311/v1/secrets/f1106c5b-0347-4197-8947-d9e392bf74a3"
},
{
"name": "intermediates",
"secret_ref": "https://:9311/v1/secrets/2e86c661-28e8-46f1-8e91-f1d95062695d"
}
]
}' https://:9311/v1/containers
这应该提供如下响应
{"container_ref": "https://:9311/v1/containers/0fecaec4-7cd7-4e70-a760-cc7eaf5c3afb"}
这是我们的容器引用。我们需要它来检索容器。跳转到 如何检索容器,以确保我们的容器已按预期存储。
创建 RSA 容器¶
要创建证书容器,我们必须有一个要存储的密钥。如我们在 RSA 容器部分 中提到的那样,您需要提供一个名为 public_key、private_key 和 private_key_passphrase 的密钥。
curl -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type:application/json" -d '{
"type": "rsa",
"name": "rsa container",
"secret_refs": [
{
"name": "public_key",
"secret_ref": "https://:9311/v1/secrets/f91b84ac-fb19-416b-87dc-e7e41b7f6039"
},
{
"name": "private_key",
"secret_ref": "https://:9311/v1/secrets/feac9896-49e9-49e0-9484-1a6153c9498b"
},
{
"name": "private_key_passphrase",
"secret_ref": "https://:9311/v1/secrets/f1106c5b-0347-4197-8947-d9e392bf74a3"
}
]
}' https://:9311/v1/containers
这应该提供如下响应
{"container_ref": "https://:9311/v1/containers/0fecaec4-7cd7-4e70-a760-cc7eaf5c3afb"}
这是我们的容器引用。我们需要它来检索容器。跳转到 如何检索容器,以确保我们的容器已按预期存储。
如何检索容器¶
要检索容器,我们必须有一个容器引用。
curl -X GET -H "X-Auth-Token: $TOKEN" https://:9311/v1/containers/49d3c5e9-80bb-47ec-8787-968bb500d76e
这应该提供如下响应
{
"status": "ACTIVE",
"updated": "2015-03-31T21:21:34.126042",
"name": "container name",
"consumers": [],
"created": "2015-03-31T21:21:34.126042",
"container_ref": "https://:9311/v1/containers/49d3c5e9-80bb-47ec-8787-968bb500d76e",
"secret_refs": [
{
"secret_ref": "https://:9311/v1/secrets/feac9896-49e9-49e0-9484-1a6153c9498b",
"name": "a secret"
}
],
"type": "generic"
}
这是元数据以及存储在容器中的密钥引用的列表。
如何删除容器¶
要删除容器,我们必须有一个容器引用。
curl -X DELETE -H "X-Auth-Token: $TOKEN" https://:9311/v1/containers/d1c23e06-476b-4684-be9f-8afbef42768d
不会提供任何响应。这是预期行为!如果您收到响应,则说明出现问题,您必须在继续操作之前解决该问题。