Skip to content
DocsAll docs
Console

API tokens

Create, use and revoke the tokens that give git and the container registry access to one owner.

Last updated

On this page

Description and operation

General

An API token gives git over HTTPS and the container registry access to one owner. The owner is your handle, or a team where you are an active member. It does not open the /v1 API; the API and the SDKs use your CLI login.

A token has a name of 1 to 60 characters. The platform shows the value once and stores only a digest, so a lost token must be revoked and replaced. Every active member of a team can see and revoke the team's tokens.

Tasks

Create an API token

Reason for the task: Give a program git and registry access to one owner.

Job set-up

  • Access: you. A team token needs an active team member.
  • References: POST /v1/tokens.
WARNING

A token has your access to that owner. Keep it out of repositories and logs.

Procedure

  1. Create the token. Set owner and name.

    Python
    from kloudlite import Kloudlitekl = Kloudlite()t = kl.request("POST", "/v1/tokens", body={"owner": "acme", "name": "ci"})print(t["_id"])  # t["token"] is the value
    TypeScript
    import { Kloudlite } from "./index.ts";const kl = new Kloudlite();const t = (await kl.request("POST", "/v1/tokens", { owner: "acme", name: "ci" })) as { _id: string; token: string };console.log(t._id); // t.token is the value
    Go
    kl := kloudlite.New(kloudlite.Options{})var t map[string]anyerr := kl.Request("POST", "/v1/tokens", kloudlite.RequestOptions{    Body: map[string]any{"owner": "acme", "name": "ci"},    Out:  &t,})if err != nil {    log.Fatal(err)}fmt.Println(t["_id"]) // t["token"] is the value
    Ruby
    require_relative "kloudlite"kl = Kloudlite::Client.newt = kl.request("POST", "/v1/tokens", body: { owner: "acme", name: "ci" })puts t["_id"] # t["token"] is the value
    Java
    var kl = new Kloudlite();// The JSON answer has "_id" and "token".String t = kl.request(new Kloudlite.RawRequest().method("POST").path("/v1/tokens")    .body("{\"owner\":\"acme\",\"name\":\"ci\"}"));
    CLI
    kloudlite request POST /v1/tokens --body '{"owner": "acme", "name": "ci"}'
  2. Put the token value in your secret store. The platform does not show it again.

Close-out

  1. Show the tokens as in task 003. Make sure that the new token is listed.

Use a token with git and the registry

Reason for the task: Clone, push and pull images from a program.

Job set-up

Procedure

  1. Use the token as the password for git. The user name is ignored; use x.

    CLI
    git clone https://x:API_TOKEN@CLONE_HOST/OWNER/NAME.git
  2. Sign in to the registry with the owner as the user name and the token as the password.

    CLI
    docker login REGISTRY_HOST -u OWNER

Close-out

  1. Make sure that the clone and docker login finish without an error.

Show your tokens

Reason for the task: List the active tokens of one owner.

Job set-up

  • Access: you. A team's tokens need an active team member.
  • References: GET /v1/tokens.

Procedure

  1. Show the tokens. Set owner to your handle or a team handle.

    Python
    for t in kl.request("GET", "/v1/tokens", query={"owner": "acme"}):    print(t["_id"], t["name"])
    TypeScript
    const tokens = (await kl.request("GET", "/v1/tokens", undefined, { owner: "acme" })) as { _id: string; name: string }[];for (const t of tokens) console.log(t._id, t.name);
    Go
    var tokens []map[string]anyerr := kl.Request("GET", "/v1/tokens", kloudlite.RequestOptions{Query: url.Values{"owner": {"acme"}}, Out: &tokens})if err != nil {    log.Fatal(err)}for _, t := range tokens {    fmt.Println(t["_id"], t["name"])}
    Ruby
    kl.request("GET", "/v1/tokens", query: { owner: "acme" }).each { |t| puts "#{t["_id"]} #{t["name"]}" }
    Java
    System.out.println(kl.request(new Kloudlite.RawRequest().method("GET").path("/v1/tokens").query("owner", "acme")));
    CLI
    kloudlite request GET /v1/tokens --query owner=acme

Close-out

  1. Make sure that each token in the list is still in use.

Revoke a token

Reason for the task: Stop a token that is unused or exposed.

Job set-up

CAUTION

A revoked token stops at once. Programs that use it fail.

Procedure

  1. Find the _id of the token as in task 003.

  2. Delete the token. Replace ID with its _id.

    Python
    kl.request("DELETE", "/v1/tokens/ID")
    TypeScript
    await kl.request("DELETE", "/v1/tokens/ID");
    Go
    if err := kl.Request("DELETE", "/v1/tokens/ID", kloudlite.RequestOptions{}); err != nil {    log.Fatal(err)}
    Ruby
    kl.request("DELETE", "/v1/tokens/ID")
    Java
    kl.request("DELETE", "/v1/tokens/ID");
    CLI
    kloudlite request DELETE /v1/tokens/ID

Close-out

  1. Show the tokens. Make sure that the _id is gone.

Troubleshooting

SymptomPossible causeCorrective action
400 with give the token a nameThe name is empty.Set name.
404 with no such ownerThe owner is not you or a team where you are an active member.Use your handle or one of your teams.
401 with invalid or expired token from /v1An API token was used for the API, or the CLI login expired.Use a CLI login. See Sign in.
401 with auth required from git or the registryThe token is wrong or revoked, or the registry user name is not the token's owner.Check both. Create a new token if the value is lost.
The token value is lostThe platform shows it once.Revoke the token and create a new one.