mirror of
https://github.com/openziti/ziti.git
synced 2026-10-23 20:26:05 +00:00
b4f6223ad1
* fixes openziti/ziti#4321 compare process hashes and fingerprints case-insensitively - normalizes configured hashes and signer fingerprints to lowercase unseparated hex in the PROCESS and PROCESS_MULTI stores, on load as well as on save, so values stored before this change read back normalized without a migration - replaces the PROCESS store's lowercase-only pass, PROCESS_MULTI stored its values verbatim - adds store tests for both types covering configured values and values written straight to bolt - updates the process multi patch round-trip test, the management API now returns normalized values rather than the submitted strings - removes the trailing newline from the signer fingerprint literal in the process and process-multi OIDC posture tests
126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package db
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/ziti/v2/common/posture"
|
|
"github.com/openziti/ziti/v2/controller/storage/boltz"
|
|
)
|
|
|
|
const (
|
|
FieldPostureCheckProcessMultiOsType = "osType"
|
|
FieldPostureCheckProcessMultiPath = "path"
|
|
FieldPostureCheckProcessMultiHashes = "hashes"
|
|
FieldPostureCheckProcessMultiSignerFingerprints = "signerFingerprints"
|
|
FieldPostureCheckProcessMultiProcesses = "processes"
|
|
)
|
|
|
|
type PostureCheckProcessMulti struct {
|
|
Semantic string `json:"semantic"`
|
|
Processes []*ProcessMulti `json:"processes"`
|
|
}
|
|
|
|
type ProcessMulti struct {
|
|
OsType string `json:"osType"`
|
|
Path string `json:"path"`
|
|
Hashes []string `json:"hashes"`
|
|
SignerFingerprints []string `json:"signerFingerprints"`
|
|
}
|
|
|
|
func newPostureCheckProcessMulti() PostureCheckSubType {
|
|
return &PostureCheckProcessMulti{
|
|
Semantic: "",
|
|
Processes: nil,
|
|
}
|
|
}
|
|
|
|
func (entity *PostureCheckProcessMulti) GetTypeId() string {
|
|
return PostureCheckTypeProcessMulti
|
|
}
|
|
|
|
// cleanProcessMultiValues normalizes a process's hashes and signer fingerprints to lowercase
|
|
// unseparated hex, the form they are compared in.
|
|
func cleanProcessMultiValues(proc *ProcessMulti) {
|
|
for i, hash := range proc.Hashes {
|
|
proc.Hashes[i] = posture.CleanHexString(hash)
|
|
}
|
|
|
|
for i, fingerprint := range proc.SignerFingerprints {
|
|
proc.SignerFingerprints[i] = posture.CleanHexString(fingerprint)
|
|
}
|
|
}
|
|
|
|
func (entity *PostureCheckProcessMulti) LoadValues(bucket *boltz.TypedBucket) {
|
|
entity.Semantic = bucket.GetStringOrError(FieldSemantic)
|
|
|
|
processesBucket := bucket.GetBucket(FieldPostureCheckProcessMultiProcesses)
|
|
|
|
processCursor := processesBucket.Cursor()
|
|
|
|
for key, _ := processCursor.First(); key != nil; key, _ = processCursor.Next() {
|
|
procBucket := processesBucket.GetBucket(string(key))
|
|
proc := &ProcessMulti{}
|
|
|
|
proc.Path = procBucket.GetStringOrError(FieldPostureCheckProcessMultiPath)
|
|
proc.OsType = procBucket.GetStringOrError(FieldPostureCheckProcessMultiOsType)
|
|
proc.SignerFingerprints = procBucket.GetStringList(FieldPostureCheckProcessMultiSignerFingerprints)
|
|
proc.Hashes = procBucket.GetStringList(FieldPostureCheckProcessMultiHashes)
|
|
|
|
cleanProcessMultiValues(proc)
|
|
|
|
entity.Processes = append(entity.Processes, proc)
|
|
}
|
|
}
|
|
|
|
func (entity *PostureCheckProcessMulti) SetValues(ctx *boltz.PersistContext, bucket *boltz.TypedBucket) {
|
|
bucket.SetString(FieldSemantic, entity.Semantic, ctx.FieldChecker)
|
|
|
|
processesBucket := bucket.GetOrCreateBucket(FieldPostureCheckProcessMultiProcesses)
|
|
|
|
seenKeys := map[string]struct{}{}
|
|
for _, proc := range entity.Processes {
|
|
cleanProcessMultiValues(proc)
|
|
|
|
key := proc.OsType + "-" + proc.Path
|
|
seenKeys[key] = struct{}{}
|
|
|
|
procBucket := processesBucket.GetOrCreateBucket(key)
|
|
|
|
procBucket.SetString(FieldPostureCheckProcessMultiPath, proc.Path, ctx.FieldChecker)
|
|
procBucket.SetString(FieldPostureCheckProcessMultiOsType, proc.OsType, ctx.FieldChecker)
|
|
procBucket.SetStringList(FieldPostureCheckProcessMultiHashes, proc.Hashes, ctx.FieldChecker)
|
|
procBucket.SetStringList(FieldPostureCheckProcessMultiSignerFingerprints, proc.SignerFingerprints, ctx.FieldChecker)
|
|
}
|
|
|
|
processCursor := processesBucket.Cursor()
|
|
|
|
var removeKeys [][]byte
|
|
for key, _ := processCursor.First(); key != nil; key, _ = processCursor.Next() {
|
|
if _, ok := seenKeys[string(key)]; !ok {
|
|
removeKeys = append(removeKeys, key)
|
|
}
|
|
}
|
|
|
|
for _, key := range removeKeys {
|
|
if err := processesBucket.DeleteBucket(key); err != nil {
|
|
pfxlog.Logger().Debugf("error deleting multi process key %s: %v", string(key), err)
|
|
}
|
|
|
|
}
|
|
}
|