add support for multiple signature keys (#209)

This commit is contained in:
Mauro Ciancio 2020-02-01 22:03:59 -03:00 committed by GitHub
parent 3bdd0fe8ed
commit ef09c1ba31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 21 deletions

View file

@ -64,8 +64,9 @@ type Proxy struct {
// The Logger used by the image proxy
Logger *log.Logger
// SignatureKey is the HMAC key used to verify signed requests.
SignatureKey []byte
// SignatureKeys is a list of HMAC keys used to verify signed requests.
// Any of them can be used to verify signed requests.
SignatureKeys [][]byte
// Allow images to scale beyond their original dimensions.
ScaleUp bool
@ -258,7 +259,7 @@ func (p *Proxy) allowed(r *Request) error {
return errDeniedHost
}
if len(p.AllowHosts) == 0 && len(p.SignatureKey) == 0 {
if len(p.AllowHosts) == 0 && len(p.SignatureKeys) == 0 {
return nil // no allowed hosts or signature key, all requests accepted
}
@ -266,8 +267,10 @@ func (p *Proxy) allowed(r *Request) error {
return nil
}
if len(p.SignatureKey) > 0 && validSignature(p.SignatureKey, r) {
return nil
for _, signatureKey := range p.SignatureKeys {
if len(signatureKey) > 0 && validSignature(signatureKey, r) {
return nil
}
}
return errNotAllowed