// requirementsForImageRef selects the appropriate requirements for ref. func (pc *PolicyContext) requirementsForImageRef(ref types.ImageReference) PolicyRequirements { // Do we have a PolicyTransportScopes for this transport? transportName := ref.Transport().Name() if transportScopes, ok := pc.Policy.Transports[transportName]; ok { // Look for a full match. identity := ref.PolicyConfigurationIdentity() if req, ok := transportScopes[identity]; ok { logrus.Debugf(` Using transport "%s" policy section %s`, transportName, identity) return req } // Look for a match of the possible parent namespaces. for _, name := range ref.PolicyConfigurationNamespaces() { if req, ok := transportScopes[name]; ok { logrus.Debugf(` Using transport "%s" specific policy section %s`, transportName, name) return req } } // Look for a default match for the transport. if req, ok := transportScopes[""]; ok { logrus.Debugf(` Using transport "%s" policy section ""`, transportName) return req } } logrus.Debugf(" Using default policy section") return pc.Policy.Default }
// policyIdentityLogName returns a string description of the image identity for policy purposes. // ONLY use this for log messages, not for any decisions! func policyIdentityLogName(ref types.ImageReference) string { return ref.Transport().Name() + ":" + ref.PolicyConfigurationIdentity() }