@@ -44,39 +44,50 @@ type authConfig struct {
4444
4545type MapAuthorizer map [string ]authConfig
4646
47- func (a MapAuthorizer ) Authorize (host string ) (user , pass string , err error ) {
47+ func (a MapAuthorizer ) Authorize (hostHeader string ) (user , pass string , err error ) {
4848 defer func () {
4949 log .WithFields (logrus.Fields {
50- "host" : host ,
50+ "host" : hostHeader ,
5151 "user" : user ,
5252 }).Info ("authorizing registry access" )
5353 }()
5454
55- // Strip any port from the host if present
56- hostSlice := strings .Split (host , ":" )
57- portStrippedHost := hostSlice [0 ]
58- var port string
59- if len (hostSlice ) > 1 {
60- port = hostSlice [1 ]
55+ parseHostHeader := func (hostHeader string ) (string , string ) {
56+ hostHeaderSlice := strings .Split (hostHeader , ":" )
57+ hostname := strings .TrimSpace (hostHeaderSlice [0 ])
58+ var port string
59+ if len (hostHeaderSlice ) > 1 {
60+ port = strings .TrimSpace (hostHeaderSlice [1 ])
61+ }
62+ return hostname , port
63+ }
64+ hostname , port := parseHostHeader (hostHeader )
65+ // gpl: Could be port 80 as well, but we don't know if we are servinc http or https, we assume https
66+ if port == "" {
67+ port = "443"
6168 }
69+ host := hostname + ":" + port
6270
6371 explicitHostMatcher := func () (authConfig , bool ) {
64- eval := host
65- if port == "443" {
66- eval = portStrippedHost
72+ // 1. precise host match
73+ res , ok := a [host ]
74+ if ok {
75+ return res , ok
6776 }
68- res , ok := a [eval ]
77+
78+ // 2. make sure we not have a hostname match
79+ res , ok = a [hostname ]
6980 return res , ok
7081 }
7182 ecrHostMatcher := func () (authConfig , bool ) {
72- if isECRRegistry (portStrippedHost ) {
83+ if isECRRegistry (hostname ) {
7384 res , ok := a [DummyECRRegistryDomain ]
7485 return res , ok
7586 }
7687 return authConfig {}, false
7788 }
7889 dockerHubHostMatcher := func () (authConfig , bool ) {
79- if isDockerHubRegistry (portStrippedHost ) {
90+ if isDockerHubRegistry (hostname ) {
8091 res , ok := a ["docker.io" ]
8192 return res , ok
8293 }
0 commit comments