feat: import prepared Catalog bindings through authenticated services
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -32,6 +33,32 @@ type Report struct {
|
||||
func NewReport() Report {
|
||||
return Report{SchemaVersion: 1, Scope: "application-documents", Issues: []Issue{}, Warnings: []string{}, DeferredChecks: []string{"release-assets", "external-connectivity", "catalog-import", "runtime-readiness"}}
|
||||
}
|
||||
|
||||
// Validate the prepared administrative login offline; execution still uses the normal login API.
|
||||
func CheckBootstrapAuthentication(installation config.Installation, path string, report *Report) {
|
||||
data, err := safeio.ReadCanonicalPrivateRegular(path, 1<<20)
|
||||
var doc struct {
|
||||
Authentication struct {
|
||||
Username string `yaml:"username"`
|
||||
PasswordFile string `yaml:"passwordFile"`
|
||||
} `yaml:"authentication"`
|
||||
}
|
||||
valid := err == nil && yaml.Unmarshal(data, &doc) == nil && doc.Authentication.Username != ""
|
||||
password, passwordErr := safeio.ReadCanonicalPrivateRegular(doc.Authentication.PasswordFile, 4096)
|
||||
auth, users, authErr := authconfig.Load(installation.AuthenticationDirectory())
|
||||
matched := false
|
||||
if valid && passwordErr == nil && authErr == nil && auth.Mode == "local" {
|
||||
for _, user := range users.Users {
|
||||
if strings.EqualFold(user.Username, doc.Authentication.Username) && user.Enabled && slices.Contains(user.Roles, authconfig.RoleAdmin) {
|
||||
matched = authconfig.VerifyPassword([]byte(strings.TrimSpace(string(password))), user.PasswordHash)
|
||||
}
|
||||
}
|
||||
}
|
||||
clear(password)
|
||||
if !matched {
|
||||
report.Add("database-bootstrap.yaml", "authentication", "bootstrap_authentication_invalid", "Prepare an enabled local administrator username and its protected passwordFile before setup; both must match the authentication documents.")
|
||||
}
|
||||
}
|
||||
func (r *Report) Add(document, field, code, correction string) {
|
||||
r.OK = false
|
||||
r.Issues = append(r.Issues, Issue{document, field, code, correction})
|
||||
|
||||
Reference in New Issue
Block a user