@@ -698,14 +698,31 @@ func consolidateAutomationPolicies(aps []*caddytls.AutomationPolicy) []*caddytls
698698 emptyAPCount := 0
699699 origLenAPs := len (aps )
700700 // compute the number of empty policies (disregarding subjects) - see #4128
701+ // while we're at it,
701702 emptyAP := new (caddytls.AutomationPolicy )
702703 for i := 0 ; i < len (aps ); i ++ {
703704 emptyAP .SubjectsRaw = aps [i ].SubjectsRaw
705+ emptyAP .ManagersRaw = nil
704706 if reflect .DeepEqual (aps [i ], emptyAP ) {
707+ // AP is empty
705708 emptyAPCount ++
706- if ! automationPolicyHasAllPublicNames (aps [i ]) {
707- // if this automation policy has internal names, we might as well remove it
708- // so auto-https can implicitly use the internal issuer
709+
710+ // see if this AP shadows something later
711+ shadowIdx := automationPolicyShadows (i , aps )
712+ emptyAP .SubjectsRaw = nil
713+ if shadowIdx >= 0 {
714+ emptyAP .SubjectsRaw = aps [shadowIdx ].SubjectsRaw
715+ // allow the later policy, which is likely for a wildcard, to have cert
716+ // managers ("get_certificate"), since wildcards now cover specific
717+ // subdomains by default, when configured (see discussion in #7559)
718+ emptyAP .ManagersRaw = aps [shadowIdx ].ManagersRaw
719+ }
720+
721+ // if this is the last AP, we can delete it, since auto-https should
722+ // pick it up; if it shadows something later that is also empty, we
723+ // can similarly delete this; but if it shadows something that is NOT
724+ // empty, we must not delete it since the shadowing has a purpose
725+ if i == len (aps )- 1 || (shadowIdx >= 0 && reflect .DeepEqual (aps [shadowIdx ], emptyAP )) {
709726 aps = slices .Delete (aps , i , i + 1 )
710727 i --
711728 }
0 commit comments