Improved Harbor URL detection on Notary Requests

This commit is contained in:
Ricardo Pchevuzinske Katz 2016-11-08 20:12:58 -02:00
parent 802fea6633
commit 72b44a17c6

View File

@ -107,11 +107,13 @@ func FilterAccess(username string, a *token.ResourceActions) {
if a.Type == "repository" { if a.Type == "repository" {
repoSplit := strings.Split(a.Name, "/") repoSplit := strings.Split(a.Name, "/")
repoLength := len(repoSplit) 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 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] 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] projectName = repoSplit[0]
} }
var permission string var permission string