Skip to content

Commit 7bd6bc8

Browse files
authored
Merge pull request #386 from smallstep/carl/api-refresh
Closes CON-206
2 parents 860b3de + ee5e53b commit 7bd6bc8

File tree

1 file changed

+51
-58
lines changed

1 file changed

+51
-58
lines changed

platform/smallstep-api.mdx

Lines changed: 51 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ description: The Smallstep platform is used across security, IT, and DevOps team
66

77
With the Smallstep API, you can:
88

9-
- Register VMs with Smallstep as you spin them up, for instant trust bootstrapping
10-
- Integrate certificate lifecycle management into your Terraform and Ansible definitions
11-
- Programmatically manage CAs, SSH grants and tags, and more!
9+
- Register new devices in your Smallstep inventory
10+
- Manage your high-level protected resources, such as Wi-Fi or VPN configurations
11+
- Manage low-level resources like X.509 CAs, Attestation authorities, and provisioners
12+
- Manage hosts, host grants, and tags for [Smallstep SSH](../ssh/README.mdx)
13+
- And more!
1214

1315
The Smallstep API is [OpenAPI conformant](https://www.openapis.org/), with JSON requests and responses.
1416

@@ -17,8 +19,9 @@ The Smallstep API is [OpenAPI conformant](https://www.openapis.org/), with JSON
1719
👉 [Smallstep API Specification and Playground](https://gateway.smallstep.com)
1820

1921
You can get an API token in two ways:
20-
- In your [Smallstep settings](https://smallstep.com/app?next=/settings). Under **API Tokens**, choose **+ Add Token.**
21-
- On the command line, using the [`step` CLI](https://smallstep.com/docs/step-cli/). The [`step api token create`](https://smallstep.com/docs/step-cli/reference/api/token/create/index.html) command accepts a client certificate and private key to authenticate with Smallstep and issue a temporary API token. To use this option, you must first configure a trusted root CA in your [Smallstep settings](https://smallstep.com/app?next=/settings). The trusted root can be a Smallstep CA or an external CA. Only one trusted root CA may be configured.
22+
- **Long-term token**: In your [Smallstep settings](https://smallstep.com/app?next=/settings). Under **API Tokens**, choose **+ Add Token.** This token has a 10 year validity period and will only be displayed once. Please store it in a safe place!
23+
- **Short-term token**: On the command line, using the [`step` CLI](../step-cli/README.mdx). The [`step api token create`](../step-cli/reference/api/token/create/README.mdx) command accepts a client certificate and private key to authenticate with Smallstep and issue a temporary API token with a 1 hour validity period.
24+
To use this option, you must configure a trusted root CA in your [Smallstep settings](https://smallstep.com/app?next=/settings). The trusted root can be a Smallstep CA or an external CA. Only one trusted root CA may be configured.
2225

2326
### API Clients
2427

@@ -27,19 +30,6 @@ You can get an API token in two ways:
2730

2831
### Getting Started
2932

30-
You’ll need an API token to get started. You can create one by [signing into the Smallstep dashboard](https://smallstep.com/app/). In the bottom-left **** menu, go to **Settings**. Under **API Tokens**, choose **+ Add Token.**
31-
32-
Your API token has a 10 year validity period and will only be displayed once. Please store it in a safe place!
33-
34-
Once you have a token, try your first API call:
35-
36-
```bash
37-
set +o history
38-
echo "Authorization: Bearer [your token]" > api_headers
39-
set -o history
40-
curl -sH @api_headers https://gateway.smallstep.com/api/users | jq
41-
```
42-
4333
Output:
4434

4535
```bash
@@ -71,43 +61,46 @@ Output:
7161
]
7262
```
7363

74-
### Configure Devices and Workloads via the API
75-
76-
Here’s the most common workflow for using the Smallstepi API, either directly or via the Terraform or Ansible integrations:
77-
78-
#### 1. [Create a device collection](https://gateway.smallstep.com/operations/PutDeviceCollection).
79-
80-
Set the device type according to your deployment. Note that each device type is going to have its own `deviceTypeConfiguration` as well. For example, an Azure VM device will require you to set your Azure tenant ID, for access control.
81-
82-
You’ll register your individual devices in step 3.
83-
84-
#### 2. [Add workloads](https://gateway.smallstep.com/operations/PutWorkload).
85-
86-
This is where you set up your workload configuration. You can specify things like certificate SANs and duration, certificate and key file ownership and permissions, reload options for the workload, and so on.
87-
88-
A single workload can be associated with multiple devices.
89-
90-
Have three HAProxy hosts in front of a fleet of `internal.example.com` web servers? That’s one workload.
91-
92-
Have a PostgreSQL server with several hot standby servers? That’s one workload.
93-
94-
Have an etcd cluster comprised of three hosts? That’s one workload.
95-
96-
On this endpoint, you can use the `deviceMetadataKeySANs` property to dynamically map certificate SANs for each device that’s running a workload. Or, statically assign SANs for every certificate in the workload, using `staticSANs`.
97-
98-
#### 3. [Add devices to collection](https://gateway.smallstep.com/operations/PutCollectionInstance).
99-
100-
Each device’s `instanceID` should be set according to the device type:
101-
102-
- For AWS EC2 instances, use the EC2 instance ID (eg. [`i-0d460b88a96dfdd08`](https://us-east-2.console.aws.amazon.com/ec2/home?region=us-east-2#InstanceDetails:instanceId=i-0d460b88a96dfdd08))
103-
- For Azure VMs, use the managed identity principal object ID
104-
- For Compute Engine VMs, use the instance ID (eg. `16979701088048819`)
105-
106-
Use the `data` field to store any relevant instance metadata, such as:
107-
108-
- an instance’s region, name, or role(s)
109-
- DNS names (these can be mapped to a SANs using `deviceMetadataKeySANs`, above)
110-
111-
#### 4. Install the Smallstep app on each device.
112-
113-
See [Smallstep App](./smallstep-app.mdx) for details.
64+
### Example: Add devices via the API
65+
66+
You can import devices from any source into Smallstep using our API.
67+
68+
Devices added via API are automatically approved.
69+
but they will not be marked as high-assurance
70+
until Smallstep receives an attestation from the device.
71+
72+
#### Example: I have a list of device identifiers
73+
74+
For each device, use the [Save Collection Instance](https://gateway.smallstep.com/v2023-11-01/operations/PutCollectionInstance) endpoint to create a device.
75+
- For the `collectionSlug`, use `default`
76+
- For Apple devices, the `instanceID` must be the device's serial number.
77+
- For TPM 2.0 devices, the `instanceID` must be the TPM Endorsement Key URI, in the format `urn:ek:sha256:ul3sYf6uQ6jVEXAMPLEXoAuHI10U8gTvEJ6bMj95LXI=`. (You can retrieve the EK URI by running `step agent tpm --fingerprint` on the device.)
78+
79+
For the body of the request,
80+
create a user using the following value
81+
(replacing `[email protected]` with the device owner's email address):
82+
83+
```
84+
{
85+
"data": {
86+
"name": "Carl's MacBook Pro",
87+
"smallstep:identity": "[email protected]"
88+
}
89+
}
90+
```
91+
92+
Once added,
93+
the devices will be automatically approved.
94+
95+
You can see the device using the [ListCollectionInstances](https://gateway.smallstep.com/v2023-11-01/operations/ListCollectionInstances) endpoint:
96+
97+
```bash
98+
set +o history
99+
echo "Authorization: Bearer [your token]" > api_headers
100+
set -o history
101+
curl -sH @api_headers https://gateway.smallstep.com/api/collections/default/items | jq
102+
```
103+
104+
Or, in your Smallstep dashboard,
105+
you'll see the device listed under Recent Devices.
106+

0 commit comments

Comments
 (0)