From 72b44a17c6d5452f14745679cedd057cd36bdb17 Mon Sep 17 00:00:00 2001 From: Ricardo Pchevuzinske Katz Date: Tue, 8 Nov 2016 20:12:58 -0200 Subject: [PATCH] Improved Harbor URL detection on Notary Requests --- src/ui/service/token/authutils.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ui/service/token/authutils.go b/src/ui/service/token/authutils.go index ffe7fcdb4..9e41409a6 100644 --- a/src/ui/service/token/authutils.go +++ b/src/ui/service/token/authutils.go @@ -107,11 +107,13 @@ func FilterAccess(username string, a *token.ResourceActions) { if a.Type == "repository" { repoSplit := strings.Split(a.Name, "/") repoLength := len(repoSplit) - if repoLength > 1 { //Only check the permission when the requested image has a namespace, i.e. project/alpine + if repoLength > 1 { //Only check the permission when the requested image has a namespace, i.e. project var projectName string - if repoLength > 2 { //If the repo contains more than 1 separation (as privateregistry.local/library/alpine) consider the second item from array (library) + registryUrl := os.Getenv("HARBOR_REG_URL") + if repoSplit[0] == registryUrl { projectName = repoSplit[1] - } else { // Otherwise (only library/alpine) consider the first item from array (library) + log.Infof("Detected Registry URL in Project Name. Assuming this is a notary request and setting Project Name as %s\n", projectName) + } else { projectName = repoSplit[0] } var permission string