2015-04-07 03:46:11 +00:00
|
|
|
---
|
|
|
|
layout: "intro"
|
2017-07-14 15:15:22 +00:00
|
|
|
page_title: "Your First Secret - Getting Started"
|
New Docs Website (#5535)
* conversion stage 1
* correct image paths
* add sidebar title to frontmatter
* docs/concepts and docs/internals
* configuration docs and multi-level nav corrections
* commands docs, index file corrections, small item nav correction
* secrets converted
* auth
* add enterprise and agent docs
* add extra dividers
* secret section, wip
* correct sidebar nav title in front matter for apu section, start working on api items
* auth and backend, a couple directory structure fixes
* remove old docs
* intro side nav converted
* reset sidebar styles, add hashi-global-styles
* basic styling for nav sidebar
* folder collapse functionality
* patch up border length on last list item
* wip restructure for content component
* taking middleman hacking to the extreme, but its working
* small css fix
* add new mega nav
* fix a small mistake from the rebase
* fix a content resolution issue with middleman
* title a couple missing docs pages
* update deps, remove temporary markup
* community page
* footer to layout, community page css adjustments
* wip downloads page
* deps updated, downloads page ready
* fix community page
* homepage progress
* add components, adjust spacing
* docs and api landing pages
* a bunch of fixes, add docs and api landing pages
* update deps, add deploy scripts
* add readme note
* update deploy command
* overview page, index title
* Update doc fields
Note this still requires the link fields to be populated -- this is solely related to copy on the description fields
* Update api_basic_categories.yml
Updated API category descriptions. Like the document descriptions you'll still need to update the link headers to the proper target pages.
* Add bottom hero, adjust CSS, responsive friendly
* Add mega nav title
* homepage adjustments, asset boosts
* small fixes
* docs page styling fixes
* meganav title
* some category link corrections
* Update API categories page
updated to reflect the second level headings for api categories
* Update docs_detailed_categories.yml
Updated to represent the existing docs structure
* Update docs_detailed_categories.yml
* docs page data fix, extra operator page remove
* api data fix
* fix makefile
* update deps, add product subnav to docs and api landing pages
* Rearrange non-hands-on guides to _docs_
Since there is no place for these on learn.hashicorp, we'll put them
under _docs_.
* WIP Redirects for guides to docs
* content and component updates
* font weight hotfix, redirects
* fix guides and intro sidenavs
* fix some redirects
* small style tweaks
* Redirects to learn and internally to docs
* Remove redirect to `/vault`
* Remove `.html` from destination on redirects
* fix incorrect index redirect
* final touchups
* address feedback from michell for makefile and product downloads
2018-10-19 15:40:11 +00:00
|
|
|
sidebar_title: "Your First Secret"
|
|
|
|
sidebar_current: "gettingstarted-first-secret"
|
2015-04-07 03:46:11 +00:00
|
|
|
description: |-
|
|
|
|
With the Vault server running, let's read and write our first secret.
|
|
|
|
---
|
|
|
|
|
|
|
|
# Your First Secret
|
|
|
|
|
|
|
|
Now that the dev server is up and running, let's get straight to it and
|
|
|
|
read and write our first secret.
|
|
|
|
|
|
|
|
One of the core features of Vault is the ability to read and write
|
|
|
|
arbitrary secrets securely. On this page, we'll do this using the CLI,
|
|
|
|
but there is also a complete
|
2017-03-17 18:06:03 +00:00
|
|
|
[HTTP API](/api/index.html)
|
2015-04-07 03:46:11 +00:00
|
|
|
that can be used to programmatically do anything with Vault.
|
|
|
|
|
2016-12-14 15:39:45 +00:00
|
|
|
Secrets written to Vault are encrypted and then written to backend
|
2015-04-07 03:46:11 +00:00
|
|
|
storage. For our dev server, backend storage is in-memory, but in production
|
|
|
|
this would more likely be on disk or in [Consul](https://www.consul.io).
|
|
|
|
Vault encrypts the value before it is ever handed to the storage driver.
|
|
|
|
The backend storage mechanism _never_ sees the unencrypted value and doesn't
|
|
|
|
have the means necessary to decrypt it without Vault.
|
|
|
|
|
|
|
|
## Writing a Secret
|
|
|
|
|
|
|
|
Let's start by writing a secret. This is done very simply with the
|
2018-04-18 20:32:37 +00:00
|
|
|
`vault kv` command, as shown below:
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-04-04 20:22:27 +00:00
|
|
|
$ vault kv put secret/hello foo=world
|
2015-04-07 03:46:11 +00:00
|
|
|
Success! Data written to: secret/hello
|
|
|
|
```
|
|
|
|
|
2018-04-04 20:22:27 +00:00
|
|
|
This writes the pair `foo=world` to the path `secret/hello`. We'll
|
2015-04-07 03:46:11 +00:00
|
|
|
cover paths in more detail later, but for now it is important that the
|
|
|
|
path is prefixed with `secret/`, otherwise this example won't work. The
|
|
|
|
`secret/` prefix is where arbitrary secrets can be read and written.
|
|
|
|
|
|
|
|
You can even write multiple pieces of data, if you want:
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-04-04 20:22:27 +00:00
|
|
|
$ vault kv put secret/hello foo=world excited=yes
|
2015-04-07 03:46:11 +00:00
|
|
|
Success! Data written to: secret/hello
|
|
|
|
```
|
|
|
|
|
2018-04-16 17:57:12 +00:00
|
|
|
`vault kv put` is a very powerful command. In addition to writing data
|
2016-12-14 15:39:45 +00:00
|
|
|
directly from the command-line, it can read values and key pairs from
|
|
|
|
`STDIN` as well as files. For more information, see the
|
2017-09-13 01:48:52 +00:00
|
|
|
[command documentation](/docs/commands/index.html).
|
2015-04-28 19:59:12 +00:00
|
|
|
|
2016-12-14 15:39:45 +00:00
|
|
|
~> **Warning:** The documentation uses the `key=value` based entry
|
2015-04-28 19:59:12 +00:00
|
|
|
throughout, but it is more secure to use files if possible. Sending
|
|
|
|
data via the CLI is often logged in shell history. For real secrets,
|
2016-12-14 15:39:45 +00:00
|
|
|
please use files. See the link above about reading in from `STDIN` for more information.
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2018-04-26 20:41:23 +00:00
|
|
|
## Getting a Secret
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2018-04-26 20:41:23 +00:00
|
|
|
As you might expect, secrets can be gotten with `vault get`:
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-04-04 06:22:41 +00:00
|
|
|
$ vault kv get secret/hello
|
2017-09-21 17:39:26 +00:00
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
refresh_interval 768h
|
|
|
|
excited yes
|
2018-04-04 20:22:27 +00:00
|
|
|
foo world
|
2015-04-07 03:46:11 +00:00
|
|
|
```
|
|
|
|
|
2018-04-26 20:41:23 +00:00
|
|
|
As you can see, the values we wrote are given back to us. Vault gets
|
2016-12-14 15:39:45 +00:00
|
|
|
the data from storage and decrypts it.
|
|
|
|
|
2015-04-07 03:46:11 +00:00
|
|
|
The output format is purposefully whitespace separated to make it easy
|
|
|
|
to pipe into a tool like `awk`.
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
This contains some extra information. Many secrets engines create leases for
|
|
|
|
secrets that allow time-limited access to other systems, and in those cases
|
|
|
|
`lease_id` would contain a lease identifier and `lease_duration` would contain
|
|
|
|
the length of time for which the lease is valid, in seconds.
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Optional JSON output is very useful for scripts. For example below we use the
|
|
|
|
`jq` tool to extract the value of the `excited` secret:
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-05-09 15:41:41 +00:00
|
|
|
$ vault kv get -format=json secret/hello | jq -r .data.data.excited
|
2017-09-21 17:39:26 +00:00
|
|
|
yes
|
|
|
|
```
|
2015-10-12 14:01:15 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
When supported, you can also get a field directly:
|
2015-04-07 03:46:11 +00:00
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-04-04 06:22:41 +00:00
|
|
|
$ vault kv get -field=excited secret/hello
|
2015-04-07 03:46:11 +00:00
|
|
|
yes
|
|
|
|
```
|
|
|
|
|
|
|
|
## Deleting a Secret
|
|
|
|
|
|
|
|
Now that we've learned how to read and write a secret, let's go ahead
|
|
|
|
and delete it. We can do this with `vault delete`:
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
```text
|
2018-04-04 06:22:41 +00:00
|
|
|
$ vault kv delete secret/hello
|
2017-09-21 17:39:26 +00:00
|
|
|
Success! Data deleted (if it existed) at: secret/hello
|
2015-04-07 03:46:11 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Next
|
|
|
|
|
|
|
|
In this section we learned how to use the powerful CRUD features of
|
|
|
|
Vault to store arbitrary secrets. On its own this is already a useful
|
|
|
|
but basic feature.
|
|
|
|
|
2017-09-21 17:39:26 +00:00
|
|
|
Next, we'll learn the basics about [secrets engines](/intro/getting-started/secrets-engines.html).
|