Skip to content

Commit fbef71d

Browse files
stevsmitSteven Smith
andauthored
8287 token creation (quay#1188)
* Fixes syntax issue in Quay docs * Updates API docs --------- Co-authored-by: Steven Smith <[email protected]>
1 parent fabe334 commit fbef71d

14 files changed

+431
-268
lines changed

api/master.adoc

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@ The following guide describes the {productname} API in more detail, and provides
2222
* Using the {productname} API
2323
* {productname} API configuration examples
2424
25-
This guide is accompanied with a second guide, . . ., that provides information about all `api/v1` endpoints and how to access those endpoints with example commands.
25+
//This guide is accompanied with a second guide, . . ., that provides information about all `api/v1` endpoints and how to access those endpoints with example commands.
2626
27+
//overview
2728
include::modules/token-overview.adoc[leveloffset=+1]
2829
29-
include::modules/proc_use-api.adoc[leveloffset=+1]
30+
//creating oauth 2 access token
31+
include::modules/oauth2-access-tokens.adoc[leveloffset=+1]
32+
include::modules/creating-oauth-access-token.adoc[leveloffset=+2]
33+
include::modules/reassigning-oauth-access-token.adoc[leveloffset=+2]
34+
include::modules/deleting-oauth-access-token.adoc[leveloffset=+2]
35+
36+
//robot account tokens
37+
include::modules/robot-account-tokens.adoc[leveloffset=+1]
38+
include::modules/regenerating-robot-account-token-ui.adoc[leveloffset=+2]
39+
include::modules/regenerating-robot-account-token-api.adoc[leveloffset=+2]
40+
41+
//oci referrers
42+
include::modules/oci-referrers-oauth-access-token.adoc[leveloffset=+1]
43+
include::modules/creating-v2-oauth-access-token.adoc[leveloffset=+2]
44+
45+
46+
//include::modules/proc_use-api.adoc[leveloffset=+1]
47+
48+
include::modules/creating-oauth-application-api.adoc[leveloffset=+1]
3049
3150
== {productname} Application Programming Interface (API)
3251
[id="ref-api-quay"]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:_content-type: PROCEDURE
2+
[id="creating-oauth-access-token"]
3+
= Creating an OAuth 2 access token
4+
5+
With {productname}, you must create an OAuth 2 access token before you can access the API endpoints of your organization. OAuth 2 access token can only be generated by using the {productname} UI; the CLI cannot be used to generate an OAuth 2 access token.
6+
7+
Use the following procedure to create an OAuth2 access token.
8+
9+
.Prerequisites
10+
11+
* You have logged in to {productname} as an administrator.
12+
* You have created an OAuth 2 application.
13+
14+
.Procedure
15+
16+
. On the main page, select an Organization.
17+
18+
. In the navigation pane, select *Applications*.
19+
20+
. Click the name of your application, for example, *Test application*.
21+
22+
. In the navigation pane, select *Generate Token*.
23+
24+
. Check the boxes for the following options:
25+
26+
.. *Administer Organization*. When selected, allows the user to be able to administer organizations, including creating robots, creating teams, adjusting team membership, and changing billing settings.
27+
28+
.. *Administer Repositories*. When selected, provides the user administrator access to all repositories to which the granting user has access.
29+
30+
.. *Create Repositories*. When selected, provides the user the ability to create repositories in any namespaces that the granting user is allowed to create repositories.
31+
32+
.. *View all visible repositories*. When selected, provides the user the ability to view and pull all repositories visible to the granting user.
33+
34+
.. *Read/Write to any accessible repositories*. When selected, provides the user the ability to view, push and pull to all repositories to which the granting user has write access.
35+
36+
.. *Super User Access*. When selected, provides the user the ability to administer your installation including managing users, managing organizations and other features found in the superuser panel.
37+
38+
.. *Administer User* When selected, provides the user the ability to administer your account including creating robots and granting them permissions to your repositories.
39+
40+
.. *Read User Information*. When selected, provides the user the ability to read user information such as username and email address.
41+
42+
. Click *Generate Access Token*. You are redirected to a new page.
43+
44+
. Review the permissions that you are allowing, then click *Authorize Application*. Confirm your decision by clicking *Authorize Application*.
45+
46+
. You are redirected to the *Access Token* page. Copy and save the access token.
47+
+
48+
[IMPORTANT]
49+
====
50+
This is the only opportunity to copy and save the access token. It cannot be reobtained after leaving this page.
51+
====
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
:_content-type: PROCEDURE
2+
[id="creating-oauth-application-api"]
3+
= Managing a user application by using the API
4+
5+
{productname} users can create, list information about, and delete a _user application_ that can be used as an alternative to using your password for Docker, Podman, or other service providers. User application tokens work like your username and password, but are encrypted and do not provide any information to third parties regarding who is accessing {productname}.
6+
7+
[NOTE]
8+
====
9+
After creation via the CLI, the user application token is listed under *User Settings* of the {productname} UI. Note that this differs from an application token that is created under user settings, and should be considered a different application entirely.
10+
====
11+
12+
Use the following procedure to create a user application token.
13+
14+
.Prerequisites
15+
16+
* You have access to the {productname} API, which entails having already created an OAuth 2 access token.
17+
18+
.Procedure
19+
20+
* Create a user application by entering the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#appspecifictokens[`POST /api/v1/user/apptoken`] API call:
21+
+
22+
[source,terminal]
23+
----
24+
$ curl -X POST \
25+
-H "Authorization: Bearer <access_token>" \
26+
-H "Content-Type: application/json" \
27+
-d '{
28+
"title": "MyAppToken"
29+
}' \
30+
"http://quay-server.example.com/api/v1/user/apptoken"
31+
----
32+
+
33+
.Example output
34+
+
35+
[source,terminal]
36+
----
37+
{"token": {"uuid": "6b5aa827-cee5-4fbe-a434-4b7b8a245ca7", "title": "MyAppToken", "last_accessed": null, "created": "Wed, 08 Jan 2025 19:32:48 -0000", "expiration": null, "token_code": "K2YQB1YO0ABYV5OBUYOMF9MCUABN12Y608Q9RHFXBI8K7IE8TYCI4WEEXSVH1AXWKZCKGUVA57PSA8N48PWED9F27PXATFUVUD9QDNCE9GOT9Q8ACYPIN0HL"}}
38+
----
39+
40+
* You can obtain information about your application, including when the application expires, by using the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#listapptokens[`GET /api/v1/user/apptoken`] command. For example:
41+
+
42+
[source,terminal]
43+
----
44+
$ curl -X GET \
45+
-H "Authorization: Bearer <access_token>" \
46+
"http://quay-server.example.com/api/v1/user/apptoken"
47+
----
48+
+
49+
[source,terminal]
50+
----
51+
{"tokens": [{"uuid": "6b5aa827-cee5-4fbe-a434-4b7b8a245ca7", "title": "MyAppToken", "last_accessed": null, "created": "Wed, 08 Jan 2025 19:32:48 -0000", "expiration": null}], "only_expiring": null}
52+
----
53+
54+
* You can obtain information about a specific user application by entering the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#getapptoken[`GET /api/v1/user/apptoken/{token_uuid}`] command:
55+
+
56+
[source,terminal]
57+
----
58+
$ curl -X GET \
59+
-H "Authorization: Bearer <access_token>" \
60+
"http://quay-server.example.com/api/v1/user/apptoken/<token_uuid>"
61+
----
62+
+
63+
.Example output
64+
+
65+
[source,terminal]
66+
----
67+
{"token": {"uuid": "6b5aa827-cee5-4fbe-a434-4b7b8a245ca7", "title": "MyAppToken", "last_accessed": null, "created": "Wed, 08 Jan 2025 19:32:48 -0000", "expiration": null, "token_code": "K2YQB1YO0ABYV5OBUYOMF9MCUABN12Y608Q9RHFXBI8K7IE8TYCI4WEEXSVH1AXWKZCKGUVA57PSA8N48PWED9F27PXATFUVUD9QDNCE9GOT9Q8ACYPIN0HL"}}
68+
----
69+
70+
* You can delete a user application token by entering the
71+
+
72+
[source,terminal]
73+
----
74+
$ curl -X DELETE \
75+
-H "Authorization: Bearer <access_token>" \
76+
"http://quay-server.example.com/api/v1/user/apptoken/<token_uuid>"
77+
----
78+
+
79+
This command does not return output in the CLI. You can return a list of tokens by entering one of the aforementioned commands.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:_content-type: PROCEDURE
2+
[id="creating-oauth-application"]
3+
= Creating an OAuth 2 application by using the UI
4+
5+
{productname} administrators can define an application by specifying a unique name, a homepage URL, a description of the application's uses, an e-mail, or a redirect/callback URL.
6+
7+
[NOTE]
8+
====
9+
The following application token is created under an Organization. This differs from an application token that is created under user settings, and should be considered a different application entirely.
10+
====
11+
12+
Use the following procedure to create an OAuth2 application.
13+
14+
.Prerequisites
15+
16+
* You have logged in to {productname} as an administrator.
17+
18+
.Procedure
19+
20+
. On the main page, select an Organization.
21+
22+
. In the navigation pane, select *Applications*.
23+
24+
. Click *Create New Application* and provide a new application name, then press *Enter*.
25+
26+
. On the *OAuth Applications* page, select the name of your application.
27+
28+
. Optional. Enter the following information:
29+
30+
.. *Application Name*
31+
.. *Homepage URL*
32+
.. *Description*
33+
.. *Avatar E-mail*
34+
.. *Redirect/Callback URL prefix*
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
:_content-type: PROCEDURE
2+
[id="creating-v2-oauth-access-token"]
3+
= Creating an OCI referrers OAuth access token
4+
5+
This OCI referrers OAuth access token is used to list OCI referrers of a manifest under a repository.
6+
7+
.Procedure
8+
9+
. Update your `config.yaml` file to include the `FEATURE_REFERRERS_API: true` field. For example:
10+
+
11+
[source,yaml]
12+
----
13+
# ...
14+
FEATURE_REFERRERS_API: true
15+
# ...
16+
----
17+
18+
. Enter the following command to Base64 encode your credentials:
19+
+
20+
[source,terminal]
21+
----
22+
$ echo -n '<username>:<password>' | base64
23+
----
24+
+
25+
.Example output
26+
+
27+
[source,terminal]
28+
----
29+
abcdeWFkbWluOjE5ODlraWROZXQxIQ==
30+
----
31+
32+
. Enter the following command to use the base64 encoded string and modify the URL endpoint to your {productname} server:
33+
+
34+
[source,terminal]
35+
----
36+
$ curl --location '<quay-server.example.com>/v2/auth?service=<quay-server.example.com>&scope=repository:quay/listocireferrs:pull,push' --header 'Authorization: Basic <base64_username:password_encode_token>' -k | jq
37+
----
38+
+
39+
.Example output
40+
+
41+
[source,terminal]
42+
----
43+
{
44+
"token": "<example_secret>
45+
}
46+
----
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
:_content-type: PROCEDURE
2+
[id="deleting-oauth-access-token"]
3+
= Deleting an OAuth 2 access token
4+
5+
Because OAuth 2 access tokens are created through the OAuth application, they cannot be rotated or renewed. In the event that a token is compromised, or you need to delete a token, you must deleted its associated application through the {productname} UI.
6+
7+
[IMPORTANT]
8+
====
9+
Deleting an application deletes all tokens that were made within that specific application. Use with caution.
10+
====
11+
12+
.Prerequisites
13+
14+
* You have created an OAuth 2 access token.
15+
16+
.Procedure
17+
18+
. On the {productname} UI, click the name of the organization hosting the application. Then, in the navigation pane, click *Applications*.
19+
20+
. Click the application name, for example, *Test application*.
21+
22+
. In the navigation pane, click *Delete Application*. You are redirected to a new page. Click *Delete application* and confirm your decision.

modules/keyless-authentication-robot-accounts.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
In previous versions of {productname}, robot account tokens were valid for the lifetime of the token unless deleted or regenerated. Tokens that do not expire have security implications for users who do not want to store long-term passwords or manage the deletion, or regeneration, or new authentication tokens.
66

7-
With {productname} {producty}, {productname} administrators are provided the ability to exchange external OIDC token for short-lived, or _ephemeral_ robot account tokens with either Red Hat Single Sign-On (based on the Keycloak project) or Microsoft Entra ID. This allows robot accounts to leverage tokens that last one hour, which are are refreshed regularly and can be used to authenticate individual transactions.
7+
With {productname} {producty}, {productname} administrators are provided the ability to exchange external OIDC tokens for short-lived, or _ephemeral_ robot account tokens with either Red Hat Single Sign-On (based on the Keycloak project) or Microsoft Entra ID. This allows robot accounts to leverage tokens that last one hour, which are are refreshed regularly and can be used to authenticate individual transactions.
88

99
This feature greatly enhances the security of your {productname} registry by mitigating the possibility of robot token exposure by removing the tokens after one hour.
1010

modules/oauth2-access-tokens.adoc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
:_content-type: REFERENCE
2+
[id="oauth2-access-tokens"]
3+
= OAuth 2 access tokens
4+
5+
link:https://oauth.net/2/[OAuth 2] access tokens (considered "API tokens" for {productname}) enable user-authenticated access to the {productname} API, suitable for applications that require user identity verification. These tokens are obtained through an OAuth 2 authorization process, where a {productname} administrator generates a token on behalf of themselves or another user to access {productname} API endpoints. OAuth 2 tokens authorize actions on API endpoints based on the scopes defined for the token.
6+
7+
[NOTE]
8+
====
9+
Although OAuth 2 tokens authorize actions on API endpoints based on the scopes defined for the token, access to the resources themselves is governed by {productname}'s role-based access control (RBAC) mechanisms. Actions can be created on a resource, for example, a repository, provided that you have the proper role (*Admin* or *Creator*) to do so for that namespace. This is true even if the API token was granted the `repo:admin` scope.
10+
====
11+
12+
OAuth 2 access tokens can only be created by using the {productname} UI; there is no way to create an OAuth 2 access token by using the CLI. When creating an OAuth 2 token, the following options can be selected for a token holder:
13+
14+
* *Administer Organization*. When selected, allows the user to be able to administer organizations, including creating robots, creating teams, adjusting team membership, and changing billing settings.
15+
16+
* *Administer Repositories*. When selected, provides the user administrator access to all repositories to which the granting user has access.
17+
18+
* *Create Repositories*. When selected, provides the user the ability to create repositories in any namespaces that the granting user is allowed to create repositories.
19+
20+
* *View all visible repositories*. When selected, provides the user the ability to view and pull all repositories visible to the granting user.
21+
22+
* *Read/Write to any accessible repositories*. When selected, provides the user the ability to view, push and pull to all repositories to which the granting user has write access.
23+
24+
* *Super User Access*. When selected, provides the user the ability to administer your installation including managing users, managing organizations and other features found in the superuser panel.
25+
26+
* *Administer User* When selected, provides the user the ability to administer your account including creating robots and granting them permissions to your repositories.
27+
28+
* *Read User Information*. When selected, provides the user the ability to read user information such as username and email address.
29+
30+
Token distributors should be mindful of the permissions that they are granting when generating a token on behalf of a user, and should have absolute trust in a user before granting such permissions as *Administer organization*, *Super User Access*, and *Administer User*. Additionally, the access token is only revealed at the time of creation; they cannot be listed from the CLI, nor can they be found on the {productname} UI. If an access token is lost or forgotten, a new token must be created; a token cannot be recovered.
31+
32+
OAuth 2 access tokens are passed as a `Bearer` token in the `Authorization` header of an API call and, as a result, are used to provide authentication and authorization to the defined API endpoint, such as an image tag, a repository, an organization, and so on.
33+
34+
The API is available from the `/api/v1` endpoint of your {productname} host. For example, `\https://<quay-server.example.com>/api/v1`. It allows users to connect to endpoints through their browser to `GET`, `POST`, `DELETE`, and `PUT` {productname} settings by enabling the Swagger UI. The API can be accessed by applications that make API calls and use OAuth tokens, and it sends and receives data as JSON.
35+
36+
With {productname}, there is currently no way to rotate or to set an expiration time on an OAuth 2 access token, and the token lifespan is 10 years. Tokens can be deleted by deleting the applications in which they were created in the event that they are compromised, however, this deletes all tokens that were made within that specific application.
37+
38+
[NOTE]
39+
====
40+
In practice, {productname} administrators _could_ create a new OAuth application on the *Applications* page of their organization each time they wanted to create a new OAuth token for a user. This would ensure that a single application is not responsible for all OAuth tokens. As a result, in the event that a user's token is compromised, the administrator would delete the application of the compromised token. This would help avoid disruption for other users whose tokens might be part of the same application.
41+
====
42+
43+
The following sections shows you how to generate and reassign an OAuth 2 access token.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
:_content-type: REFERENCE
2+
[id="oci-referrers-oauth-access-token"]
3+
= OCI referrers OAuth access token
4+
5+
In some cases, depending on the features that your {productname} deployment is configured to use, you might need to leverage an _OCI referrers OAuth access token_. OCI referrers OAuth access tokens are used to list OCI referrers of a manifest under a repository, and uses a `curl` command to make a `GET` request to the {productname} `v2/auth` endpoint.
6+
7+
These tokens are obtained via basic HTTP authentication, wherein the user provides a username and password encoded in Base64 to authenticate directly with the `v2/auth` API endpoint. As such, they are based directly on the user's credentials aod do not follow the same detailed authorization flow as OAuth 2, but still allow a user to authorize API requests.
8+
9+
_OCI referrers OAuth access tokens_ do not offer scope-based permissions and do not expire. They are solely used to list OCI referrers of a manifest under a repository.
10+
11+
[discrete]
12+
== Additional resource
13+
14+
* link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/use_red_hat_quay/index#attaching-referrers-image-tag[Attaching referrers to an image tag]

0 commit comments

Comments
 (0)