Skip to content

Commit

Permalink
Update the getting started API doc to not use 'root' policy
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnayak committed Oct 11, 2016
1 parent 8d42361 commit 956fa43
Showing 1 changed file with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions website/source/intro/getting-started/apis.html.md
Expand Up @@ -7,9 +7,15 @@ description: |-
---

# Using the HTTP APIs with Authentication
All of Vault's capabilities are accessible via the HTTP API in addition to the CLI. In fact, most calls from the CLI actually invoke the HTTP API. In some cases, Vault features are not available via the CLI and can only be accessed via the HTTP API.
All of Vault's capabilities are accessible via the HTTP API in addition to the
CLI. In fact, most calls from the CLI actually invoke the HTTP API. In some
cases, Vault features are not available via the CLI and can only be accessed
via the HTTP API.

Once you have started the Vault server, you can use `curl` or any other http client to make API calls. For example, if you started the Vault server in [development mode](/docs/concepts/dev-server.html), you could validate the initialization status like this:
Once you have started the Vault server, you can use `curl` or any other http
client to make API calls. For example, if you started the Vault server in
[development mode](/docs/concepts/dev-server.html), you could validate the
initialization status like this:

```
$ curl http://127.0.0.1:8200/v1/sys/init
Expand All @@ -22,9 +28,15 @@ This will return a JSON response:
```

## Accessing Secrets via the REST APIs
Machines that need access to information stored in Vault will most likely access Vault via its REST API. For example, if a machine were using [app-id](/docs/auth/app-id.html) for authentication, the application would first authenticate to Vault which would return a Vault API token. The application would use that token for future communication with Vault.
Machines that need access to information stored in Vault will most likely
access Vault via its REST API. For example, if a machine were using
[app-id](/docs/auth/app-id.html) for authentication, the application would
first authenticate to Vault which would return a Vault API token. The
application would use that token for future communication with Vault.

For the purpose of this guide, we will use the following configuration which disables TLS and uses a file-based backend. You should never disable TLS in production, but it is okay for the purposes of this tutorial.
For the purpose of this guide, we will use the following configuration which
disables TLS and uses a file-based backend. You should never disable TLS in
production, but it is okay for the purposes of this tutorial.

```javascript
backend "file" {
Expand All @@ -42,7 +54,8 @@ Save this file on disk and then start the Vault server with this command:
$ vault server -config=/etc/vault.conf
```

At this point, we can use Vault's API for all our interactions. For example, we can initialize Vault like this:
At this point, we can use Vault's API for all our interactions. For example, we
can initialize Vault like this:

```
$ curl \
Expand All @@ -60,15 +73,20 @@ The response should be JSON and look something like this:
}
```

This response contains our initial root token. It also includes the unseal key. You can use the unseal key to unseal the Vault and use the root token perform other requests in Vault that require authentication.
This response contains our initial root token. It also includes the unseal key.
You can use the unseal key to unseal the Vault and use the root token perform
other requests in Vault that require authentication.

To make this guide easy to copy-and-paste, we will be using the environment variable `$VAULT_TOKEN` to store the root token. You can export this Vault token in your current shell like this:
To make this guide easy to copy-and-paste, we will be using the environment
variable `$VAULT_TOKEN` to store the root token. You can export this Vault
token in your current shell like this:

```
$ export VAULT_TOKEN=0e2ede5a-6664-a49e-ca33-8f204d1cdb95
```

Using the unseal key (not the root token) from above, you can unseal the Vault via the HTTP API:
Using the unseal key (not the root token) from above, you can unseal the Vault
via the HTTP API:

```
$ curl \
Expand All @@ -77,7 +95,8 @@ $ curl \
http://127.0.0.1:8200/v1/sys/unseal
```

Note that you should replace `69cf1c1...` with the generated key from your output. This will return a JSON response:
Note that you should replace `69cf1c1...` with the generated key from your
output. This will return a JSON response:

```javascript
{
Expand All @@ -88,7 +107,9 @@ Note that you should replace `69cf1c1...` with the generated key from your outpu
}
```

Now we can enable an authentication backend such as [GitHub authentication](/docs/auth/github.html) or [App ID](/docs/auth/app-id.html). For the purposes of this guide, we will enable App ID authentication.
Now we can enable an authentication backend such as [GitHub
authentication](/docs/auth/github.html) or [App ID](/docs/auth/app-id.html).
For the purposes of this guide, we will enable App ID authentication.

We can enable an authentication backend with the following `curl` command:

Expand All @@ -100,23 +121,35 @@ $ curl \
http://127.0.0.1:8200/v1/sys/auth/app-id
```

Notice that the request to the app-id endpoint needed an authentication token. In this case we are passing the root token generated when we started the Vault server. We could also generate tokens using any other authentication mechanisms, but we will use the root token for simplicity.
Notice that the request to the app-id endpoint needed an authentication token.
In this case we are passing the root token generated when we started the Vault
server. We could also generate tokens using any other authentication
mechanisms, but we will use the root token for simplicity.

The last thing we need to do before using our App ID endpoint is writing the data to the store to associate an app id with a user id. For more information on this process, see the documentation on the [app-id auth backend](/docs/auth/app-id.html).
The last thing we need to do before using our App ID endpoint is writing the
data to the store to associate an app id with a user id. For more information
on this process, see the documentation on the [app-id auth
backend](/docs/auth/app-id.html).

First, we need to associate the application with a particular [ACL policy](/docs/concepts/policies.html) in Vault. In the following command, we are going to associate the created tokens with the `root` policy. You would not want to do this in a real production scenario because the root policy allows complete read, write, and administrator access to Vault. For a production application, you should create an ACL policy (which is also possible via the HTTP API), but is not covered in this guide for simplicity.
First, we need to associate the application with a particular [ACL
policy](/docs/concepts/policies.html) in Vault. In the following command, we
are going to associate the created tokens with the `dev-policy` policy (A
policy under the name `dev-policy` should be registered at Vault before the
login endpoint is invoked).

```
$ curl \
-X POST \
-H "X-Vault-Token:$VAULT_TOKEN" \
-d '{"value":"root", "display_name":"demo"}' \
-d '{"value":"dev-policy", "display_name":"demo"}' \
http://localhost:8200/v1/auth/app-id/map/app-id/152AEA38-85FB-47A8-9CBD-612D645BFACA
```

Note that `152AEA38-85FB-47A8-9CBD-612D645BFACA` is a randomly generated UUID. You can use any tool to generate a UUID, but make sure it is unique.
Note that `152AEA38-85FB-47A8-9CBD-612D645BFACA` is a randomly generated UUID.
You can use any tool to generate a UUID, but make sure it is unique.

Next we need to map the application to a particular "user". In Vault, this is actually a particular application:
Next we need to map the application to a particular "user". In Vault, this is
actually a particular application:

```
$ curl \
Expand All @@ -126,7 +159,8 @@ $ curl \
http://localhost:8200/v1/auth/app-id/map/user-id/5ADF8218-D7FB-4089-9E38-287465DBF37E
```

Now your app can identify itself via the app-id and user-id and get access to Vault. The first step is to authenticate:
Now your app can identify itself via the app-id and user-id and get access to
Vault. The first step is to authenticate:

```
$ curl \
Expand Down Expand Up @@ -156,15 +190,20 @@ This will return a response that looks like the following:
}
```

The returned client token (`7a25c58b-9bad-5750-b579-edbb9f10a5ef`) can now be used to authenticate with Vault. As you can see from the returned payload, the App ID backend does not currently support lease expiration or renewal. If you authenticate with backend that does support leases, your application will have to track expiration and handle renewal, but that is a topic for another guide.
The returned client token (`7a25c58b-9bad-5750-b579-edbb9f10a5ef`) can now be
used to authenticate with Vault. As you can see from the returned payload, the
App ID backend does not currently support lease expiration or renewal. If you
authenticate with backend that does support leases, your application will have
to track expiration and handle renewal, but that is a topic for another guide.

We can export this new token as our new `VAULT_TOKEN`:

```
$ export VAULT_TOKEN="7a25c58b-9bad-5750-b579-edbb9f10a5ef"
```

Be sure to replace this with the value returned from your API response. We can now use this token to authentication requests to Vault:
Be sure to replace this with the value returned from your API response. We can
now use this token to authentication requests to Vault:

```
$ curl \
Expand All @@ -175,7 +214,8 @@ $ curl \
http://127.0.0.1:8200/v1/secret/foo
```

This will create a new secret named "foo" with the given JSON contents. We can read this value back with the same token:
This will create a new secret named "foo" with the given JSON contents. We can
read this value back with the same token:

```
$ curl \
Expand All @@ -197,7 +237,8 @@ This should return a response like this:
}
```

You can see the documentation on the [HTTP APIs](/docs/http/index.html) for more details on other available endpoints.
You can see the documentation on the [HTTP APIs](/docs/http/index.html) for
more details on other available endpoints.

Congratulations! You now know all the basics to get started with Vault.

Expand Down

0 comments on commit 956fa43

Please sign in to comment.