-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: jsonNormalisation/v3 and old fixes avoiding broken sigs
Package jsonv3 provides a normalization which is completely based on the abstract (internal) version of the component descriptor and is therefore agnostic of the final serialization format. Signatures using this algorithm can be transferred among different schema versions, as long as is able to handle the complete information using for the normalization. jsonv2 is the predecessor of this version but had internal defaulting logic that is no longer included as part of this normalization. Thus v3 should be preferred over v2. Note that between v2 and v3 differences can occur mainly if the "extra identity" field is not unique, in which case the v2 normalization opinionated on how to differentiate these items. This no longer happens in v3, meaning the component descriptor is normalized as is. v2 and v1 were adjusted to accomodate the old(but new because forgotten) legacy behavior in legacy.go. Without this, old signatures would not work
- Loading branch information
1 parent
a6e2e9c
commit 4cc3c4f
Showing
14 changed files
with
208 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Package jsonv3 provides a normalization which is completely based on the | ||
// abstract (internal) version of the component descriptor and is therefore | ||
// agnostic of the final serialization format. Signatures using this algorithm | ||
// can be transferred among different schema versions, as long as is able to | ||
// handle the complete information using for the normalization. | ||
// jsonv2 is the predecessor of this version but had internal defaulting logic | ||
// that is no longer included as part of this normalization. Thus v3 should be preferred over v2. | ||
// Note that between v2 and v3 differences can occur mainly if the "extra identity" field is not unique, | ||
// in which case the v2 normalization opinionated on how to differentiate these items. This no longer | ||
// happens in v3, meaning the component descriptor is normalized as is. | ||
package jsonv3 | ||
|
||
import ( | ||
"ocm.software/ocm/api/ocm/compdesc" | ||
"ocm.software/ocm/api/ocm/compdesc/normalizations/jsonv2" | ||
"ocm.software/ocm/api/tech/signing" | ||
"ocm.software/ocm/api/tech/signing/norm/jcs" | ||
) | ||
|
||
const Algorithm = compdesc.JsonNormalisationV3 | ||
|
||
func init() { | ||
compdesc.Normalizations.Register(Algorithm, normalization{}) | ||
} | ||
|
||
type normalization struct{} | ||
|
||
func (m normalization) Normalize(cd *compdesc.ComponentDescriptor) ([]byte, error) { | ||
data, err := signing.Normalize(jcs.Type, cd, jsonv2.CDExcludes) | ||
return data, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package legacy | ||
|
||
import ( | ||
"fmt" | ||
|
||
"ocm.software/ocm/api/ocm/compdesc" | ||
"ocm.software/ocm/api/ocm/selectors/accessors" | ||
"ocm.software/ocm/api/utils/logging" | ||
) | ||
|
||
var ( | ||
REALM = logging.DefineSubRealm("component descriptor legacy normalization defaulting", "compdesc", "normalizations", "legacy") | ||
Logger = logging.DynamicLogger(REALM) | ||
) | ||
|
||
// DefaultingOfVersionIntoExtraIdentity normalizes the extra identity of the resources. | ||
// It sets the version of the resource, reference or source as extra identity field if the combination of name+extra identity | ||
// is the same for multiple items. However, the last item in the list will not be updated as it is unique wihout this. | ||
// | ||
// TODO: To be removed once v1 + v2 are removed. | ||
// | ||
// Deprecated: This is a legacy normalization and should only be used as part of JsonNormalisationV1 and JsonNormalisationV2 | ||
// for backwards compatibility of normalization (for example used for signatures). It was needed because the original | ||
// defaulting was made part of the normalization by accident and is now no longer included by default due to | ||
// https://github.com/open-component-model/ocm/pull/1026 | ||
func DefaultingOfVersionIntoExtraIdentity(cd *compdesc.ComponentDescriptor) { | ||
resources := make([]accessors.ElementMeta, len(cd.Resources)) | ||
for i := range cd.Resources { | ||
resources[i] = &cd.Resources[i] | ||
} | ||
defaultingOfVersionIntoExtraIdentity(resources) | ||
} | ||
|
||
func defaultingOfVersionIntoExtraIdentity(meta []accessors.ElementMeta) { | ||
for i := range meta { | ||
for j := range meta { | ||
// don't match with itself and only match with the same name | ||
if meta[j].GetName() != meta[i].GetName() || i == j { | ||
continue | ||
} | ||
|
||
eid := meta[i].GetExtraIdentity() | ||
// if the extra identity is not the same, then there is not a clash | ||
if !meta[j].GetExtraIdentity().Equals(eid) { | ||
continue | ||
} | ||
|
||
eid.Set(compdesc.SystemIdentityVersion, meta[i].GetVersion()) | ||
meta[i].GetMeta().SetExtraIdentity(eid) | ||
|
||
Logger.Warn(fmt.Sprintf("resource identity duplication was normalized for backwards compatibility, "+ | ||
"to avoid this either specify a unique extra identity per item or switch to %s", compdesc.JsonNormalisationV3), | ||
"name", meta[i].GetName(), "index", i, "extra identity", meta[i].GetExtraIdentity()) | ||
break | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.