Repository navigation
feat(authzen): report data freshness and a decision id in evaluation responses #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leifj
wants to merge
8
commits into
main
Choose a base branch
from
feat/221-trust-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e302715
feat(authzen): report data freshness and a decision id in evaluation …
leifj 2df8fe1
fix(authzen): address review of freshness reporting
leifj 7455395
fix(authzen): never overstate freshness; cut duplicated reporter code
leifj af1629e
fix(authzen): unknown freshness for failed pointers and expired caches
leifj 3eabba0
fix(authzen): freshness unknown for failed/circuit-skipped denials; T…
leifj c5bcda1
fix(registry): carry registry failures through all/best_match and com…
leifj 5a7cd8a
fix(registry): nil composite child is incomplete; trim duplicated code
leifj 8c2cc5f
refactor(registry): move strategy dispatch and trust-data attach out …
leifj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,45 @@ | ||
| package etsi | ||
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/sirosfoundation/g119612/pkg/etsi119612" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func tslWithNextUpdate(dt string) *etsi119612.TSL { | ||
| tsl := &etsi119612.TSL{} | ||
| tsl.StatusList.TslSchemeInformation = &etsi119612.TSLSchemeInformationType{} | ||
| if dt != "" { | ||
| tsl.StatusList.TslSchemeInformation.TslNextUpdate = &etsi119612.NextUpdateType{DateTime: dt} | ||
| } | ||
| return tsl | ||
| } | ||
|
|
||
| func TestFreshness(t *testing.T) { | ||
| loaded := time.Date(2026, 10, 19, 12, 0, 0, 0, time.UTC) | ||
|
|
||
| r := &TSLRegistry{loadedAt: loaded, tsls: []*etsi119612.TSL{ | ||
| tslWithNextUpdate("2026-11-01T00:00:00Z"), | ||
| tslWithNextUpdate("2026-10-26T00:00:00Z"), | ||
| tslWithNextUpdate(""), | ||
| nil, | ||
| }} | ||
| f := r.Freshness() | ||
| assert.True(t, f.AsOf.Equal(loaded)) | ||
| assert.True(t, f.NextUpdate.IsZero(), "one undated TSL makes the registry's NextUpdate unknown") | ||
|
|
||
| r = &TSLRegistry{loadedAt: loaded, tsls: []*etsi119612.TSL{ | ||
| tslWithNextUpdate("2026-11-01T00:00:00Z"), | ||
| tslWithNextUpdate("2026-10-26T00:00:00Z"), | ||
| nil, | ||
| }} | ||
| assert.True(t, r.Freshness().NextUpdate.Equal(time.Date(2026, 10, 26, 0, 0, 0, 0, time.UTC)), | ||
| "the registry is only as fresh as its soonest-expiring TSL") | ||
|
|
||
| r = &TSLRegistry{loadedAt: loaded, tsls: []*etsi119612.TSL{tslWithNextUpdate("not a date"), tslWithNextUpdate("2026-10-26T00:00:00Z")}} | ||
| assert.True(t, r.Freshness().NextUpdate.IsZero(), "an unparseable date is unknown") | ||
|
|
||
| assert.True(t, (&TSLRegistry{loadedAt: loaded}).Freshness().NextUpdate.IsZero(), "no TSLs: no bound") | ||
| } |
This file contains hidden or 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 hidden or 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,120 @@ | ||
| package registry | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/sirosfoundation/go-trust/pkg/authzen" | ||
| ) | ||
|
|
||
| // Freshness describes how current a registry's data is. A zero field means | ||
| // unknown or not applicable. | ||
| type Freshness struct { | ||
| // AsOf is when the data was last loaded. | ||
| AsOf time.Time | ||
| // NextUpdate is when the source says it will next be replaced. | ||
| NextUpdate time.Time | ||
| } | ||
|
|
||
| // FreshnessReporter is implemented by registries that know how fresh their data | ||
| // is. It is optional: a registry without it is reported with no as_of and no | ||
| // next_update, which a caller must read as "unknown". | ||
| type FreshnessReporter interface { | ||
| Freshness() Freshness | ||
| } | ||
|
|
||
| // ParseSourceTime parses a timestamp from a trust-data source (ETSI | ||
| // dateTime, VICAL/RICAL tdate). An empty or unparseable value yields the zero | ||
| // time, i.e. "unknown": freshness must never be invented. | ||
| func ParseSourceTime(s string) time.Time { | ||
| if s == "" { | ||
| return time.Time{} | ||
| } | ||
| for _, layout := range []string{time.RFC3339Nano, time.RFC3339, "2006-01-02T15:04:05", "2006-01-02"} { | ||
| if t, err := time.Parse(layout, s); err == nil { | ||
| return t.UTC() | ||
| } | ||
| } | ||
| return time.Time{} | ||
| } | ||
|
|
||
| // EarliestKnown returns the earliest of the times, or the zero time (unknown) | ||
| // when there are none or any of them is unknown. A registry that holds several | ||
| // lists can decide from any of them, so it is only as fresh as its | ||
| // soonest-expiring list, and unknown if any list is. | ||
| func EarliestKnown(times ...time.Time) time.Time { | ||
| var earliest time.Time | ||
| for _, t := range times { | ||
| if t.IsZero() { | ||
| return time.Time{} | ||
| } | ||
| if earliest.IsZero() || t.Before(earliest) { | ||
| earliest = t | ||
| } | ||
| } | ||
| return earliest | ||
| } | ||
|
|
||
| // collectTrustData appends one TrustData entry per leaf registry under reg. | ||
| // A composite contributes its children, not itself. | ||
| func collectTrustData(reg TrustRegistry, out []authzen.TrustData) []authzen.TrustData { | ||
| if c, ok := reg.(*CompositeRegistry); ok { | ||
| for _, child := range c.registries { | ||
| out = collectTrustData(child, out) | ||
| } | ||
| return out | ||
| } | ||
| td := authzen.TrustData{Registry: reg.Info().Name} | ||
| if fr, ok := reg.(FreshnessReporter); ok { | ||
| f := fr.Freshness() | ||
| if !f.AsOf.IsZero() { | ||
| td.AsOf = f.AsOf.UTC().Format(time.RFC3339) | ||
| } | ||
| if !f.NextUpdate.IsZero() { | ||
| td.NextUpdate = f.NextUpdate.UTC().Format(time.RFC3339) | ||
| } | ||
| } | ||
| return append(out, td) | ||
| } | ||
|
|
||
| // trustDataSnapshot returns the current freshness of every registry in regs. | ||
| func trustDataSnapshot(regs []TrustRegistry) []authzen.TrustData { | ||
| var data []authzen.TrustData | ||
| for _, r := range regs { | ||
| data = collectTrustData(r, data) | ||
| } | ||
| return data | ||
| } | ||
|
|
||
| // attachTrustData returns a copy of resp whose context carries the freshness of | ||
| // every registry that could have contributed to the decision. The copy matters: | ||
| // registries may hand back a response they also keep. | ||
| // | ||
| // before and after are snapshots taken around the evaluation. A registry may | ||
| // reload while it is being evaluated, and its freshness is read outside its own | ||
| // lock, so an entry is only reported when both snapshots agree; otherwise the | ||
| // data the decision used cannot be told apart from the data now loaded, and the | ||
| // entry carries no as_of or next_update (unknown). | ||
| // | ||
| // The set is the policy-filtered applicable registries, not only those that | ||
| // answered first. For a first-match allow that can name a registry that was not | ||
| // reached, which only makes the reported bound earlier, never later. | ||
| func attachTrustData(resp *authzen.EvaluationResponse, before, after []authzen.TrustData) *authzen.EvaluationResponse { | ||
| if resp == nil || len(after) == 0 { | ||
| return resp | ||
| } | ||
| data := make([]authzen.TrustData, len(after)) | ||
| for i, a := range after { | ||
| data[i] = a | ||
| if len(before) != len(after) || before[i] != a { | ||
| data[i] = authzen.TrustData{Registry: a.Registry} | ||
| } | ||
| } | ||
| out := *resp | ||
| var ctx authzen.EvaluationResponseContext | ||
| if resp.Context != nil { | ||
| ctx = *resp.Context | ||
| } | ||
| ctx.TrustData = data | ||
| out.Context = &ctx | ||
| return &out | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.