feat(release): 生产授权支持页面通道(管理员会话 + 固定确认语句)
页面原本没有任何生产入口,授权/重排/回滚只能带 Bearer 调接口,实际还要 admin 会话。 现在三个端点支持两条通道,门禁语义不变: - 运维通道:Authorization: Bearer <token>,审计记 PRODUCTION_RELEASE_AUTHORIZER_REF - 页面通道:已认证 admin 会话 + 固定确认语句,审计记该管理员用户名 - 请求门禁 / 备份恢复门禁 / Release Worker 执行门禁三者不受影响 - 发布管理第 6–8 步加「授权发布 / 重排 / 回滚」按钮,点击需逐字输入确认语句, 仅 admin 可见;重排沿用原执行授权人,不改写历史 - openapi 与 P6 契约同步;测试:双通道各一条 + 非 admin/错短语拒绝 + 前端按钮与确认门禁
This commit is contained in:
@@ -1654,7 +1654,8 @@ func authorizeProductionRelease(w http.ResponseWriter, r *http.Request, config C
|
||||
writeJSON(w, http.StatusPreconditionFailed, map[string]string{"error": "production backup restore verification is required"})
|
||||
return
|
||||
}
|
||||
if !productionReleaseAuthorized(r, config.ProductionReleaseAuthorizationToken) {
|
||||
actor, releaseAuthorized := productionReleaseActor(r, config)
|
||||
if !releaseAuthorized {
|
||||
writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "production release authorization required"})
|
||||
return
|
||||
}
|
||||
@@ -1668,7 +1669,7 @@ func authorizeProductionRelease(w http.ResponseWriter, r *http.Request, config C
|
||||
return
|
||||
}
|
||||
execution, replayed, err := config.Store.AuthorizeReleaseBatchWithOperation(r.Context(), governance.AuthorizeReleaseBatchRequest{
|
||||
BatchID: r.PathValue("id"), AuthorizedBy: productionAuthorizer(r, config),
|
||||
BatchID: r.PathValue("id"), AuthorizedBy: actor,
|
||||
AuthorizationCode: "production_release_authorized", Now: config.Now().UTC(),
|
||||
}, operationID)
|
||||
switch {
|
||||
@@ -1699,7 +1700,8 @@ func authorizeProductionRollback(w http.ResponseWriter, r *http.Request, config
|
||||
writeJSON(w, http.StatusForbidden, map[string]string{"error": "production release requests are disabled"})
|
||||
return
|
||||
}
|
||||
if !productionReleaseAuthorized(r, config.ProductionReleaseAuthorizationToken) {
|
||||
actor, releaseAuthorized := productionReleaseActor(r, config)
|
||||
if !releaseAuthorized {
|
||||
writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "production release authorization required"})
|
||||
return
|
||||
}
|
||||
@@ -1713,7 +1715,7 @@ func authorizeProductionRollback(w http.ResponseWriter, r *http.Request, config
|
||||
return
|
||||
}
|
||||
execution, replayed, err := config.Store.AuthorizeReleaseRollbackWithOperation(r.Context(), governance.AuthorizeReleaseRollbackRequest{
|
||||
PriorExecutionID: r.PathValue("id"), AuthorizedBy: productionAuthorizer(r, config),
|
||||
PriorExecutionID: r.PathValue("id"), AuthorizedBy: actor,
|
||||
AuthorizationCode: "production_rollback_authorized", Now: config.Now().UTC(),
|
||||
}, operationID)
|
||||
switch {
|
||||
@@ -1744,7 +1746,8 @@ func retryProductionRelease(w http.ResponseWriter, r *http.Request, config Confi
|
||||
writeJSON(w, http.StatusForbidden, map[string]string{"error": "production release requests are disabled"})
|
||||
return
|
||||
}
|
||||
if !productionReleaseAuthorized(r, config.ProductionReleaseAuthorizationToken) {
|
||||
// 重排沿用原执行的授权人记录(改写它会篡改历史),因此这里只取授权结果。
|
||||
if _, releaseAuthorized := productionReleaseActor(r, config); !releaseAuthorized {
|
||||
writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "production release authorization required"})
|
||||
return
|
||||
}
|
||||
@@ -1788,6 +1791,25 @@ func productionAuthorizer(r *http.Request, config Config) string {
|
||||
return config.ProductionReleaseAuthorizerRef
|
||||
}
|
||||
|
||||
// productionReleaseActor authorises a production action and names who performed
|
||||
// it. Two sanctioned paths behind the same gates:
|
||||
// - the deployment Bearer token (ops scripts) — recorded under the configured
|
||||
// fixed authorizer ref;
|
||||
// - an authenticated ADMIN session plus the fixed confirmation phrase (the
|
||||
// page's 授权发布 / 重排 / 回滚 buttons) — recorded under that operator.
|
||||
//
|
||||
// The request gate, the backup-restore gate and the worker's execution gate stay
|
||||
// independent of this choice: relaxing "who may call" must not relax "may it run".
|
||||
func productionReleaseActor(r *http.Request, config Config) (string, bool) {
|
||||
if productionReleaseAuthorized(r, config.ProductionReleaseAuthorizationToken) {
|
||||
return config.ProductionReleaseAuthorizerRef, true
|
||||
}
|
||||
if identity, ok := sessionFrom(r.Context()); ok && identity.Role == roleAdmin {
|
||||
return identity.Username, true
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func productionReleaseAuthorized(r *http.Request, token string) bool {
|
||||
provided := r.Header.Get("Authorization")
|
||||
expected := "Bearer " + token
|
||||
|
||||
Reference in New Issue
Block a user