检查点:保存请求取消栅栏与监听保护,准备补齐Linux发布包
This commit is contained in:
1 parent
76b4d94ca0
commit
822e204ae0
16 files changed
+685
-51
No files matched your search
@@ -42,6 +42,9 @@ func (a coordinatedManagementActivator) coordinator(expected *httpapi.Management
|
||||
}
|
||||
|
||||
func (a coordinatedManagementActivator) Ready(ctx context.Context, state httpapi.ManagementCertificateState) error {
|
||||
if err := requireManagementListener(ctx, a.server); err != nil {
|
||||
return err
|
||||
}
|
||||
if state.HTTPSMode == "direct" {
|
||||
if err := a.coordinator(nil).Recover(ctx); err != nil {
|
||||
return err
|
||||
@@ -52,6 +55,9 @@ func (a coordinatedManagementActivator) Ready(ctx context.Context, state httpapi
|
||||
}
|
||||
|
||||
func (a coordinatedManagementActivator) Activate(ctx context.Context, state httpapi.ManagementCertificateState, saved certificate.SavedResource) error {
|
||||
if err := requireManagementListener(ctx, a.server); err != nil {
|
||||
return err
|
||||
}
|
||||
if state.HTTPSMode == "direct" {
|
||||
if err := a.Ready(ctx, state); err != nil {
|
||||
return err
|
||||
|
||||
@@ -114,3 +114,20 @@ func TestManagementRecoveryWaitsForHTTPS(t *testing.T) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagementActivationRequiresHTTPSListener(t *testing.T) {
|
||||
for _, server := range []*httpapi.Server{nil, httpapi.New(httpapi.Dependencies{})} {
|
||||
if err := requireManagementListener(t.Context(), server); err == nil {
|
||||
t.Fatal("没有监听器的桌面或嵌入式运行时不能申请管理证书")
|
||||
}
|
||||
activator := directManagementActivator{server: server}
|
||||
if err := activator.Ready(t.Context(), httpapi.ManagementCertificateState{HTTPSMode: "direct"}); err == nil {
|
||||
t.Fatal("直接模式不能绕过监听检查")
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithCancel(t.Context())
|
||||
cancel()
|
||||
if err := requireManagementListener(ctx, nil); !errors.Is(err, context.Canceled) {
|
||||
t.Fatal("监听检查应保留取消原因", err)
|
||||
}
|
||||
}
|
||||
@@ -240,10 +240,24 @@ type directManagementActivator struct {
|
||||
server *httpapi.Server
|
||||
}
|
||||
|
||||
func (a directManagementActivator) Ready(ctx context.Context, state httpapi.ManagementCertificateState) error {
|
||||
func requireManagementListener(ctx context.Context, server *httpapi.Server) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if server != nil {
|
||||
select {
|
||||
case <-server.Listening():
|
||||
return nil
|
||||
default:
|
||||
}
|
||||
}
|
||||
return errors.New("当前进程尚未启动管理 HTTPS 监听,已阻止申请管理证书")
|
||||
}
|
||||
|
||||
func (a directManagementActivator) Ready(ctx context.Context, state httpapi.ManagementCertificateState) error {
|
||||
if err := requireManagementListener(ctx, a.server); err != nil {
|
||||
return err
|
||||
}
|
||||
if state.HTTPSMode != "direct" {
|
||||
return errors.New("管理证书代理激活器尚未配置,已阻止申请和上游单独切换")
|
||||
}
|
||||
|
||||
@@ -156,13 +156,15 @@ func TestManagementRenewalSkipsFreshAndIPCertificates(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestManagementRenewalPreflightRejectsBeforeIssuance(t *testing.T) {
|
||||
for _, name := range []string{"dns", "proxy"} {
|
||||
for _, name := range []string{"dns", "proxy", "no_listener"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
f := newManagementFixture(t)
|
||||
if name == "dns" {
|
||||
f.state.DNSVerified = false
|
||||
} else {
|
||||
f.state.HTTPSMode = "proxy"
|
||||
if name == "proxy" {
|
||||
f.state.HTTPSMode = "proxy"
|
||||
}
|
||||
f.m.activator = directManagementActivator{server: f.app.HTTP}
|
||||
}
|
||||
report, err := f.m.RunRenewal(t.Context(), f.policy, f.now)
|
||||
|
||||
Reference in new issue
Block a user