1 parent
9dc861d560
commit
fd475cd88d
54 files changed
+987
-91
No files matched your search
@@ -254,6 +254,21 @@ func (m *ConfigManager) Status() ConfigStatus {
|
||||
}
|
||||
|
||||
func (m *ConfigManager) Validate(ctx context.Context, req ValidateRequest) (*ValidationResult, error) {
|
||||
return m.validate(ctx, req, nil)
|
||||
}
|
||||
|
||||
// ValidateAuthorized 对外部请求使用与保存一致的授权;内部校验不暴露为 HTTP 入口。
|
||||
func (m *ConfigManager) ValidateAuthorized(ctx context.Context, req ValidateRequest, actor AuditActor) (*ValidationResult, error) {
|
||||
if m == nil {
|
||||
return nil, ErrManagerStorage
|
||||
}
|
||||
if err := m.authorize(ctx, actor, ConfigOperationUpdate, req.Section); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m.validate(ctx, req, &actor)
|
||||
}
|
||||
|
||||
func (m *ConfigManager) validate(ctx context.Context, req ValidateRequest, actor *AuditActor) (*ValidationResult, error) {
|
||||
if err := contextError(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -273,6 +288,11 @@ func (m *ConfigManager) Validate(ctx context.Context, req ValidateRequest) (*Val
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if actor != nil && req.Section == SectionPlugins {
|
||||
if err := AuthorizePluginChanges(*actor, current, candidate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.Section == SectionSSL {
|
||||
if _, err := prepareCustomSSLPaths(m.loader.root, &candidate); err != nil {
|
||||
issue, ok := SSLValidationIssue(err)
|
||||
@@ -317,6 +337,11 @@ func (m *ConfigManager) Update(ctx context.Context, req UpdateRequest) (*UpdateR
|
||||
return nil, err
|
||||
}
|
||||
var sslMaterial *customSSLMaterial
|
||||
if req.Section == SectionPlugins {
|
||||
if err := AuthorizePluginChanges(req.Actor, current, candidate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.Section == SectionSSL {
|
||||
sslMaterial, err = prepareCustomSSLPaths(m.loader.root, &candidate)
|
||||
if err != nil {
|
||||
@@ -406,6 +431,12 @@ func (m *ConfigManager) apply(ctx context.Context, generation uint64, actor Audi
|
||||
if err := m.authorize(ctx, actor, ConfigOperationUpdate, pending.Section); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 暂存后角色可能变化,应用时必须重新检查程序与权限边界。
|
||||
if pending.Section == SectionPlugins {
|
||||
if err := AuthorizePluginChanges(actor, current, candidate); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
if generation != candidate.Generation || candidate.Generation != current.Generation+1 {
|
||||
return nil, ErrGenerationConflict
|
||||
|
||||
Reference in new issue
Block a user