Skip to content

Commit 7ce5a74

Browse files
authored
feat: use the "zot" namespace for the authentication url (#1947)
Some other minor fixes for swaggo comments (indentation and a bad description) Signed-off-by: Andrei Aaron <[email protected]>
1 parent a345ba0 commit 7ce5a74

File tree

9 files changed

+476
-475
lines changed

9 files changed

+476
-475
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ CRICTL := $(TOOLSDIR)/bin/crictl
2424
CRICTL_VERSION := v1.26.1
2525
ACTION_VALIDATOR := $(TOOLSDIR)/bin/action-validator
2626
ACTION_VALIDATOR_VERSION := v0.5.3
27-
ZUI_VERSION := commit-19e366e
27+
ZUI_VERSION := commit-fad5572
2828
SWAGGER_VERSION := v1.8.12
2929
STACKER := $(TOOLSDIR)/bin/stacker
3030
BATS := $(TOOLSDIR)/bin/bats

examples/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ zot can be configured to use the above providers with:
209209
}
210210
```
211211

212-
To login with either provider use http://127.0.0.1:8080/auth/login?provider=\<provider\>&callback_ui=http://127.0.0.1:8080/home
213-
for example to login with github use http://127.0.0.1:8080/auth/login?provider=github&callback_ui=http://127.0.0.1:8080/home
212+
To login with either provider use http://127.0.0.1:8080/zot/auth/login?provider=\<provider\>&callback_ui=http://127.0.0.1:8080/home
213+
for example to login with github use http://127.0.0.1:8080/zot/auth/login?provider=github&callback_ui=http://127.0.0.1:8080/home
214214

215215
callback_ui query parameter is used by zot to redirect to UI after a successful openid/oauth2 authentication
216216

217-
The callback url which should be used when making oauth2 provider setup is http://127.0.0.1:8080/auth/callback/\<provider\>
218-
for example github callback url would be http://127.0.0.1:8080/auth/callback/github
217+
The callback url which should be used when making oauth2 provider setup is http://127.0.0.1:8080/zot/auth/callback/\<provider\>
218+
for example github callback url would be http://127.0.0.1:8080/zot/auth/callback/github
219219

220220
If network policy doesn't allow inbound connections, this callback wont work!
221221

@@ -228,7 +228,7 @@ To configure zot as a client in dex (assuming zot is hosted at 127.0.0.1:8080),
228228
staticClients:
229229
- id: zot-client
230230
redirectURIs:
231-
- 'http://127.0.0.1:8080/auth/callback/oidc'
231+
- 'http://127.0.0.1:8080/zot/auth/callback/oidc'
232232
name: 'zot'
233233
secret: ZXhhbXBsZS1hcHAtc2VjcmV0
234234
```
@@ -254,7 +254,7 @@ zot can be configured to use dex with:
254254
}
255255
```
256256

257-
To login using openid dex provider use http://127.0.0.1:8080/auth/login?provider=oidc
257+
To login using openid dex provider use http://127.0.0.1:8080/zot/auth/login?provider=oidc
258258

259259
NOTE: Social login is not supported by command line tools, or other software responsible for pushing/pulling
260260
images to/from zot.
@@ -323,14 +323,14 @@ To activate API keys use:
323323

324324
Create an API key for the current user using the REST API
325325

326-
**Usage**: POST /auth/apikey
326+
**Usage**: POST /zot/auth/apikey
327327

328328
**Produces**: application/json
329329

330330
**Sample input**:
331331

332332
```
333-
POST /auth/apikey
333+
POST /zot/auth/apikey
334334
Body: {"label": "git", "scopes": ["repo1", "repo2"], "expirationDate": "2023-08-28T17:10:05+03:00"}'
335335
```
336336

@@ -339,7 +339,7 @@ The time format of expirationDate is RFC1123Z.
339339
**Example cURL without expiration date**
340340

341341
```bash
342-
curl -u user:password -X POST http://localhost:8080/auth/apikey -d '{"label": "git", "scopes": ["repo1", "repo2"]}'
342+
curl -u user:password -X POST http://localhost:8080/zot/auth/apikey -d '{"label": "git", "scopes": ["repo1", "repo2"]}'
343343
```
344344

345345
**Sample output**:
@@ -365,7 +365,7 @@ curl -u user:password -X POST http://localhost:8080/auth/apikey -d '{"label": "g
365365
**Example cURL with expiration date**
366366

367367
```bash
368-
curl -u user:password -X POST http://localhost:8080/auth/apikey -d '{"label": "myAPIKEY", "expirationDate": "2023-08-28T17:10:05+03:00"}'
368+
curl -u user:password -X POST http://localhost:8080/zot/auth/apikey -d '{"label": "myAPIKEY", "expirationDate": "2023-08-28T17:10:05+03:00"}'
369369
```
370370

371371
**Sample output**:
@@ -389,7 +389,7 @@ curl -u user:password -X POST http://localhost:8080/auth/apikey -d '{"label": "m
389389

390390
Get list of API keys for the current user using the REST API
391391

392-
**Usage**: GET /auth/apikey
392+
**Usage**: GET /zot/auth/apikey
393393

394394
**Produces**: application/json
395395

@@ -448,14 +448,14 @@ Other command line tools will similarly accept the API key instead of a password
448448

449449
How to revoke an API key for the current user
450450

451-
**Usage**: DELETE /auth/apikey?id=$uuid
451+
**Usage**: DELETE /zot/auth/apikey?id=$uuid
452452

453453
**Produces**: application/json
454454

455455
**Example cURL**
456456

457457
```bash
458-
curl -u user:password -X DELETE http://localhost:8080/v2/auth/apikey?id=46a45ce7-5d92-498a-a9cb-9654b1da3da1
458+
curl -u user:password -X DELETE http://localhost:8080/zot/auth/apikey?id=46a45ce7-5d92-498a-a9cb-9654b1da3da1
459459
```
460460

461461
#### Authentication Failures

pkg/api/constants/consts.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ const (
1414
DefaultMediaType = "application/json"
1515
BinaryMediaType = "application/octet-stream"
1616
DefaultMetricsExtensionRoute = "/metrics"
17-
CallbackBasePath = "/auth/callback"
18-
LoginPath = "/auth/login"
19-
LogoutPath = "/auth/logout"
20-
APIKeyPath = "/auth/apikey" //nolint: gosec
17+
AppNamespacePath = "/zot"
18+
CallbackBasePath = AppNamespacePath + "/auth/callback"
19+
LoginPath = AppNamespacePath + "/auth/login"
20+
LogoutPath = AppNamespacePath + "/auth/logout"
21+
APIKeyPath = AppNamespacePath + "/auth/apikey"
2122
SessionClientHeaderName = "X-ZOT-API-CLIENT"
2223
SessionClientHeaderValue = "zot-ui"
2324
APIKeysPrefix = "zak_"

pkg/api/routes.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ func getUIHeadersHandler(config *config.Config, allowedMethods ...string) func(h
226226
// CheckVersionSupport godoc
227227
// @Summary Check API support
228228
// @Description Check if this API version is supported
229-
// @Router /v2/ [get]
229+
// @Router /v2/ [get]
230230
// @Accept json
231231
// @Produce json
232-
// @Success 200 {string} string "ok".
232+
// @Success 200 {string} string "ok".
233233
func (rh *RouteHandler) CheckVersionSupport(response http.ResponseWriter, request *http.Request) {
234234
if request.Method == http.MethodOptions {
235235
return
@@ -255,15 +255,15 @@ func (rh *RouteHandler) CheckVersionSupport(response http.ResponseWriter, reques
255255
// ListTags godoc
256256
// @Summary List image tags
257257
// @Description List all image tags in a repository
258-
// @Router /v2/{name}/tags/list [get]
258+
// @Router /v2/{name}/tags/list [get]
259259
// @Accept json
260260
// @Produce json
261-
// @Param name path string true "test"
262-
// @Param n query integer true "limit entries for pagination"
263-
// @Param last query string true "last tag value for pagination"
264-
// @Success 200 {object} common.ImageTags
265-
// @Failure 404 {string} string "not found"
266-
// @Failure 400 {string} string "bad request".
261+
// @Param name path string true "repository name"
262+
// @Param n query integer true "limit entries for pagination"
263+
// @Param last query string true "last tag value for pagination"
264+
// @Success 200 {object} common.ImageTags
265+
// @Failure 404 {string} string "not found"
266+
// @Failure 400 {string} string "bad request".
267267
func (rh *RouteHandler) ListTags(response http.ResponseWriter, request *http.Request) {
268268
if request.Method == http.MethodOptions {
269269
return
@@ -389,12 +389,12 @@ func (rh *RouteHandler) ListTags(response http.ResponseWriter, request *http.Req
389389
// CheckManifest godoc
390390
// @Summary Check image manifest
391391
// @Description Check an image's manifest given a reference or a digest
392-
// @Router /v2/{name}/manifests/{reference} [head]
392+
// @Router /v2/{name}/manifests/{reference} [head]
393393
// @Accept json
394394
// @Produce json
395-
// @Param name path string true "repository name"
395+
// @Param name path string true "repository name"
396396
// @Param reference path string true "image reference or digest"
397-
// @Success 200 {string} string "ok"
397+
// @Success 200 {string} string "ok"
398398
// @Header 200 {object} constants.DistContentDigestKey
399399
// @Failure 404 {string} string "not found"
400400
// @Failure 500 {string} string "internal server error".
@@ -461,9 +461,9 @@ type ExtensionList struct {
461461
// @Description Get an image's manifest given a reference or a digest
462462
// @Accept json
463463
// @Produce application/vnd.oci.image.manifest.v1+json
464-
// @Param name path string true "repository name"
465-
// @Param reference path string true "image reference or digest"
466-
// @Success 200 {object} api.ImageManifest
464+
// @Param name path string true "repository name"
465+
// @Param reference path string true "image reference or digest"
466+
// @Success 200 {object} api.ImageManifest
467467
// @Header 200 {object} constants.DistContentDigestKey
468468
// @Failure 404 {string} string "not found"
469469
// @Failure 500 {string} string "internal server error"
@@ -562,10 +562,10 @@ func getReferrers(ctx context.Context, routeHandler *RouteHandler,
562562
// @Description Get referrers given a digest
563563
// @Accept json
564564
// @Produce application/vnd.oci.image.index.v1+json
565-
// @Param name path string true "repository name"
565+
// @Param name path string true "repository name"
566566
// @Param digest path string true "digest"
567567
// @Param artifactType query string false "artifact type"
568-
// @Success 200 {object} api.ImageIndex
568+
// @Success 200 {object} api.ImageIndex
569569
// @Failure 404 {string} string "not found"
570570
// @Failure 500 {string} string "internal server error"
571571
// @Router /v2/{name}/referrers/{digest} [get].
@@ -633,10 +633,10 @@ func (rh *RouteHandler) GetReferrers(response http.ResponseWriter, request *http
633633
// @Description Update an image's manifest given a reference or a digest
634634
// @Accept json
635635
// @Produce json
636-
// @Param name path string true "repository name"
637-
// @Param reference path string true "image reference or digest"
636+
// @Param name path string true "repository name"
637+
// @Param reference path string true "image reference or digest"
638638
// @Header 201 {object} constants.DistContentDigestKey
639-
// @Success 201 {string} string "created"
639+
// @Success 201 {string} string "created"
640640
// @Failure 400 {string} string "bad request"
641641
// @Failure 404 {string} string "not found"
642642
// @Failure 500 {string} string "internal server error"
@@ -744,9 +744,9 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
744744
// @Description Delete an image's manifest given a reference or a digest
745745
// @Accept json
746746
// @Produce json
747-
// @Param name path string true "repository name"
747+
// @Param name path string true "repository name"
748748
// @Param reference path string true "image reference or digest"
749-
// @Success 200 {string} string "ok"
749+
// @Success 200 {string} string "ok"
750750
// @Router /v2/{name}/manifests/{reference} [delete].
751751
func (rh *RouteHandler) DeleteManifest(response http.ResponseWriter, request *http.Request) {
752752
vars := mux.Vars(request)
@@ -853,8 +853,8 @@ func (rh *RouteHandler) DeleteManifest(response http.ResponseWriter, request *ht
853853
// @Description Check an image's blob/layer given a digest
854854
// @Accept json
855855
// @Produce json
856-
// @Param name path string true "repository name"
857-
// @Param digest path string true "blob/layer digest"
856+
// @Param name path string true "repository name"
857+
// @Param digest path string true "blob/layer digest"
858858
// @Success 200 {object} api.ImageManifest
859859
// @Header 200 {object} constants.DistContentDigestKey
860860
// @Router /v2/{name}/blobs/{digest} [head].
@@ -967,8 +967,8 @@ func parseRangeHeader(contentRange string) (int64, int64, error) {
967967
// @Description Get an image's blob/layer given a digest
968968
// @Accept json
969969
// @Produce application/vnd.oci.image.layer.v1.tar+gzip
970-
// @Param name path string true "repository name"
971-
// @Param digest path string true "blob/layer digest"
970+
// @Param name path string true "repository name"
971+
// @Param digest path string true "blob/layer digest"
972972
// @Header 200 {object} constants.DistContentDigestKey
973973
// @Success 200 {object} api.ImageManifest
974974
// @Router /v2/{name}/blobs/{digest} [get].
@@ -1077,8 +1077,8 @@ func (rh *RouteHandler) GetBlob(response http.ResponseWriter, request *http.Requ
10771077
// @Description Delete an image's blob/layer given a digest
10781078
// @Accept json
10791079
// @Produce json
1080-
// @Param name path string true "repository name"
1081-
// @Param digest path string true "blob/layer digest"
1080+
// @Param name path string true "repository name"
1081+
// @Param digest path string true "blob/layer digest"
10821082
// @Success 202 {string} string "accepted"
10831083
// @Router /v2/{name}/blobs/{digest} [delete].
10841084
func (rh *RouteHandler) DeleteBlob(response http.ResponseWriter, request *http.Request) {
@@ -1137,8 +1137,8 @@ func (rh *RouteHandler) DeleteBlob(response http.ResponseWriter, request *http.R
11371137
// @Description Create a new image blob/layer upload
11381138
// @Accept json
11391139
// @Produce json
1140-
// @Param name path string true "repository name"
1141-
// @Success 202 {string} string "accepted"
1140+
// @Param name path string true "repository name"
1141+
// @Success 202 {string} string "accepted"
11421142
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
11431143
// @Header 202 {string} Range "0-0"
11441144
// @Failure 401 {string} string "unauthorized"
@@ -1292,8 +1292,8 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
12921292
// @Description Get an image's blob/layer upload given a session_id
12931293
// @Accept json
12941294
// @Produce json
1295-
// @Param name path string true "repository name"
1296-
// @Param session_id path string true "upload session_id"
1295+
// @Param name path string true "repository name"
1296+
// @Param session_id path string true "upload session_id"
12971297
// @Success 204 {string} string "no content"
12981298
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
12991299
// @Header 202 {string} Range "0-128"
@@ -1353,9 +1353,9 @@ func (rh *RouteHandler) GetBlobUpload(response http.ResponseWriter, request *htt
13531353
// @Description Resume an image's blob/layer upload given an session_id
13541354
// @Accept json
13551355
// @Produce json
1356-
// @Param name path string true "repository name"
1357-
// @Param session_id path string true "upload session_id"
1358-
// @Success 202 {string} string "accepted"
1356+
// @Param name path string true "repository name"
1357+
// @Param session_id path string true "upload session_id"
1358+
// @Success 202 {string} string "accepted"
13591359
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
13601360
// @Header 202 {string} Range "0-128"
13611361
// @Header 200 {object} api.BlobUploadUUID
@@ -1452,10 +1452,10 @@ func (rh *RouteHandler) PatchBlobUpload(response http.ResponseWriter, request *h
14521452
// @Description Update and finish an image's blob/layer upload given a digest
14531453
// @Accept json
14541454
// @Produce json
1455-
// @Param name path string true "repository name"
1456-
// @Param session_id path string true "upload session_id"
1457-
// @Param digest query string true "blob/layer digest"
1458-
// @Success 201 {string} string "created"
1455+
// @Param name path string true "repository name"
1456+
// @Param session_id path string true "upload session_id"
1457+
// @Param digest query string true "blob/layer digest"
1458+
// @Success 201 {string} string "created"
14591459
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{digest}"
14601460
// @Header 200 {object} constants.DistContentDigestKey
14611461
// @Failure 404 {string} string "not found"
@@ -1610,8 +1610,8 @@ finish:
16101610
// @Description Delete an image's blob/layer given a digest
16111611
// @Accept json
16121612
// @Produce json
1613-
// @Param name path string true "repository name"
1614-
// @Param session_id path string true "upload session_id"
1613+
// @Param name path string true "repository name"
1614+
// @Param session_id path string true "upload session_id"
16151615
// @Success 200 {string} string "ok"
16161616
// @Failure 404 {string} string "not found"
16171617
// @Failure 500 {string} string "internal server error"
@@ -1665,7 +1665,7 @@ type RepositoryList struct {
16651665
// @Description List all image repositories
16661666
// @Accept json
16671667
// @Produce json
1668-
// @Success 200 {object} api.RepositoryList
1668+
// @Success 200 {object} api.RepositoryList
16691669
// @Failure 500 {string} string "internal server error"
16701670
// @Router /v2/_catalog [get].
16711671
func (rh *RouteHandler) ListRepositories(response http.ResponseWriter, request *http.Request) {
@@ -1729,7 +1729,7 @@ func (rh *RouteHandler) ListRepositories(response http.ResponseWriter, request *
17291729
// @Description List all extensions present on registry
17301730
// @Accept json
17311731
// @Produce json
1732-
// @Success 200 {object} api.ExtensionList
1732+
// @Success 200 {object} api.ExtensionList
17331733
// @Router /v2/_oci/ext/discover [get].
17341734
func (rh *RouteHandler) ListExtensions(w http.ResponseWriter, r *http.Request) {
17351735
if r.Method == http.MethodOptions {
@@ -1746,10 +1746,10 @@ func (rh *RouteHandler) ListExtensions(w http.ResponseWriter, r *http.Request) {
17461746
// Logout godoc
17471747
// @Summary Logout by removing current session
17481748
// @Description Logout by removing current session
1749-
// @Router /auth/logout [post]
1749+
// @Router /zot/auth/logout [post]
17501750
// @Accept json
17511751
// @Produce json
1752-
// @Success 200 {string} string "ok".
1752+
// @Success 200 {string} string "ok".
17531753
// @Failure 500 {string} string "internal server error".
17541754
func (rh *RouteHandler) Logout(response http.ResponseWriter, request *http.Request) {
17551755
if request.Method == http.MethodOptions {
@@ -1958,9 +1958,9 @@ type ReferenceList struct {
19581958
// @Description Get references for an image given a digest and artifact type
19591959
// @Accept json
19601960
// @Produce json
1961-
// @Param name path string true "repository name"
1962-
// @Param digest path string true "image digest"
1963-
// @Param artifactType query string true "artifact type"
1961+
// @Param name path string true "repository name"
1962+
// @Param digest path string true "image digest"
1963+
// @Param artifactType query string true "artifact type"
19641964
// @Success 200 {string} string "ok"
19651965
// @Failure 404 {string} string "not found"
19661966
// @Failure 500 {string} string "internal server error"
@@ -2035,7 +2035,7 @@ type APIKeyPayload struct { //nolint:revive
20352035
// @Success 200 {string} string "ok"
20362036
// @Failure 401 {string} string "unauthorized"
20372037
// @Failure 500 {string} string "internal server error"
2038-
// @Router /auth/apikey [get].
2038+
// @Router /zot/auth/apikey [get].
20392039
func (rh *RouteHandler) GetAPIKeys(resp http.ResponseWriter, req *http.Request) {
20402040
apiKeys, err := rh.c.MetaDB.GetUserAPIKeys(req.Context())
20412041
if err != nil {
@@ -2077,7 +2077,7 @@ func (rh *RouteHandler) GetAPIKeys(resp http.ResponseWriter, req *http.Request)
20772077
// @Failure 400 {string} string "bad request"
20782078
// @Failure 401 {string} string "unauthorized"
20792079
// @Failure 500 {string} string "internal server error"
2080-
// @Router /auth/apikey [post].
2080+
// @Router /zot/auth/apikey [post].
20812081
func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request) {
20822082
var payload APIKeyPayload
20832083

@@ -2178,7 +2178,7 @@ func (rh *RouteHandler) CreateAPIKey(resp http.ResponseWriter, req *http.Request
21782178
// @Failure 500 {string} string "internal server error"
21792179
// @Failure 401 {string} string "unauthorized"
21802180
// @Failure 400 {string} string "bad request"
2181-
// @Router /auth/apikey [delete].
2181+
// @Router /zot/auth/apikey [delete].
21822182
func (rh *RouteHandler) RevokeAPIKey(resp http.ResponseWriter, req *http.Request) {
21832183
ids, ok := req.URL.Query()["id"]
21842184
if !ok || len(ids) != 1 {

0 commit comments

Comments
 (0)