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.
A token has your access to that owner. Keep it out of repositories and logs.
Procedure
Create the token. Set
ownerandname.from kloudlite import Kloudlitekl = Kloudlite()t = kl.request("POST", "/v1/tokens", body={"owner": "acme", "name": "ci"})print(t["_id"]) # t["token"] is the valueimport { 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 valuekl := 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 valuerequire_relative "kloudlite"kl = Kloudlite::Client.newt = kl.request("POST", "/v1/tokens", body: { owner: "acme", name: "ci" })puts t["_id"] # t["token"] is the valuevar 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\"}"));kloudlite request POST /v1/tokens --body '{"owner": "acme", "name": "ci"}'Put the
tokenvalue in your secret store. The platform does not show it again.
Close-out
- 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
- Access: you.
- References:
POST /v1/tokens.
Procedure
Use the token as the password for git. The user name is ignored; use
x.git clone https://x:API_TOKEN@CLONE_HOST/OWNER/NAME.gitSign in to the registry with the owner as the user name and the token as the password.
docker login REGISTRY_HOST -u OWNER
Close-out
- Make sure that the clone and
docker loginfinish 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
Show the tokens. Set
ownerto your handle or a team handle.for t in kl.request("GET", "/v1/tokens", query={"owner": "acme"}): print(t["_id"], t["name"])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);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"])}kl.request("GET", "/v1/tokens", query: { owner: "acme" }).each { |t| puts "#{t["_id"]} #{t["name"]}" }System.out.println(kl.request(new Kloudlite.RawRequest().method("GET").path("/v1/tokens").query("owner", "acme")));kloudlite request GET /v1/tokens --query owner=acme
Close-out
- 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
- Access: you. A team's tokens need an active team member.
- References:
DELETE /v1/tokens/{id}.
A revoked token stops at once. Programs that use it fail.
Procedure
Find the
_idof the token as in task 003.Delete the token. Replace
IDwith its_id.kl.request("DELETE", "/v1/tokens/ID")await kl.request("DELETE", "/v1/tokens/ID");if err := kl.Request("DELETE", "/v1/tokens/ID", kloudlite.RequestOptions{}); err != nil { log.Fatal(err)}kl.request("DELETE", "/v1/tokens/ID")kl.request("DELETE", "/v1/tokens/ID");kloudlite request DELETE /v1/tokens/ID
Close-out
- Show the tokens. Make sure that the
_idis gone.
Troubleshooting
| Symptom | Possible cause | Corrective action |
|---|---|---|
400 with give the token a name | The name is empty. | Set name. |
404 with no such owner | The 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 /v1 | An 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 registry | The 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 lost | The platform shows it once. | Revoke the token and create a new one. |