Files
teleport/docs/pages/api/getting-started.mdx
T
Paul Gottschling 91c89b6126 Organize docs guide sections chronologically (#15357)
* Organize docs guide sections chronologically

This change aims to make docs navigation easier by organizing some docs
sections according to the sequence of steps a user would take to set up
Teleport.

The current docs organization uses a variety of categories and schemes
to organize the docs. For example, there is a "Home" section that
includes the Changelog, Installation page, and Getting Started guides; a
"Setup" section that includes references and admin guides; and
edition-specific sections (Enterprise, Cloud). For a user who is setting
up Teleport--or who has already done some setup work and wants more
advanced instructions--it's difficult to know where in the docs to find
the right information.

This change organizes our how-to guides into the following categories
that describe the process of setting up Teleport:

- Try out Teleport
- Deploy a Cluster (including choosing an edition)
- Configure Access (including SSO, RBAC, and Access Requests)
- Manage your Cluster (admin guides, operations, etc.)
- Use Teleport (this section already exists)

I moved the Reference section after this chronology, since users can
access the reference guides anywhere in the setup process.

As part of the change, I have also moved the content from the
"Enterprise" and "Cloud" sections into "Deploy a Cluster", since this
content has to do with how to deploy a specific edition of Teleport.

Note that this change does _not_ attempt to reorganize our
protocol-specific sections. While adding resources is part of the
Teleport setup process, we have a lot of content in our
protocol-specific sections, and moving it all into a single section
related to adding resources to a cluster would (a) exceed the maximum
depth for subsections in the nav bar and (b) cause more confusion than
it alleviates.

* Respond to PR feedback

- Create a "Compliance Frameworks" section of "Configure Access" with
  the FedRAMP and SOC 2 guides
- Rename "Use Teleport" to "Connect your Client"
- Move the database GUI client guide into "Connect your Client"

* Add redirects

* Fix linter issues
2022-08-22 19:45:32 +00:00

119 lines
3.7 KiB
Plaintext

---
title: API Getting Started Guide
description: Get started working with the Teleport API programmatically using Go.
---
# Getting Started
In this getting started guide we will use the Teleport API Go client to connect
to a Teleport Auth Service.
Here are the steps we'll walkthrough:
1. Create an API user using a simple role-based authentication method.
2. Generate credentials for that user.
3. Create and connect a Go client to interact with Teleport's API.
## Prerequisites
- Install [Go](https://golang.org/doc/install) (=teleport.golang=)+ and Go development environment.
- Set up Teleport through one of our [getting started guides](../getting-started.mdx). You can also begin a [free trial](https://goteleport.com/signup/) of Teleport Cloud.
## Step 1/3. Create a user
(!docs/pages/includes/permission-warning.mdx!)
<Admonition type="tip" title="Tip">
Read [API authorization](./architecture.mdx#authorization) to learn more about defining custom roles for your API client.
</Admonition>
Create a user `api-admin` with the built-in role `editor`:
```code
# Run this directly on your Auth Server unless you are using Teleport Cloud
# Add a user and login via the Proxy Service
$ sudo tctl users add api-admin --roles=editor
```
## Step 2/3. Generate client credentials
Log in as the newly created user with `tsh`.
```code
# generate tsh profile
$ tsh login --user=api-admin --proxy=tele.example.com
```
The [Profile Credentials loader](https://pkg.go.dev/github.com/gravitational/teleport/api/client#LoadProfile)
will automatically retrieve Credentials from the current profile in the next step.
## Step 3/3. Create a Go project
Set up a new [Go module](https://golang.org/doc/tutorial/create-module) and import the `client` package:
```code
$ mkdir client-demo && cd client-demo
$ go mod init client-demo
$ go get github.com/gravitational/teleport/api/client
```
Create a file called `main.go`, modifying the `Addrs` strings as needed:
```go
package main
import (
"context"
"log"
"github.com/gravitational/teleport/api/client"
)
func main() {
ctx := context.Background()
clt, err := client.New(ctx, client.Config{
Addrs: []string{
// Teleport Cloud customers should use <tenantname>.teleport.sh
"tele.example.com:443",
"tele.example.com:3025",
"tele.example.com:3024",
"tele.example.com:3080",
},
Credentials: []client.Credentials{
client.LoadProfile("", ""),
},
})
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
defer clt.Close()
resp, err := clt.Ping(ctx)
if err != nil {
log.Fatalf("failed to ping server: %v", err)
}
log.Printf("Example success!")
log.Printf("Example server response: %s", resp)
log.Printf("Server version: %s", resp.ServerVersion)
}
```
Now you can run the program and connect the client to the Teleport Auth Server to fetch the server version.
```code
$ go run main.go
```
## Next steps
- Learn about [pkg.go.dev](https://pkg.go.dev/github.com/gravitational/teleport/api/client)
- Learn how to use [the client](https://pkg.go.dev/github.com/gravitational/teleport/api/client#Client)
- Learn how to [work with credentials](https://pkg.go.dev/github.com/gravitational/teleport/api/client#Credentials)
- Read about Teleport [API architecture](./architecture.mdx) for an in-depth overview of the API and API clients.
- Read [API authorization](./architecture.mdx#authorization) to learn more about defining custom roles for your API client.
- Review the `client` [pkg.go reference documentation](https://pkg.go.dev/github.com/gravitational/teleport/api/client) for more information about working with the Teleport API programmatically.
- Familiarize yourself with the [admin manual](../management/admin.mdx) to make the best use of the API.