Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/mutation/mutants.json
Original file line number Diff line number Diff line change
Expand Up @@ -5658,5 +5658,77 @@
],
"run": "^(TestReentrantResolutionFailureHookReturns|TestReentrantResolutionFailureHookReturnsWhenMemoryFull)$",
"why": "the failure is published on the in-flight resolution before OnResolutionFailure runs"
},
{
"id": "server-ciba-inbox-skips-only-notfound",
"file": "server/backchannel_inbox.go",
"old": "return errors.Is(serverErr, storage.ErrBackchannelAuthenticationNotFound)",
"new": "return serverErr != nil",
"module": "root",
"packages": [
"./server"
],
"run": "^TestListBackchannelInteractionsReportsARefusedLookup$",
"why": "the CIBA inbox listing reports a lookup refused other than as not found, rather than skipping it"
},
{
"id": "server-ciba-inbox-skips-notfound",
"file": "server/backchannel_inbox.go",
"old": "return errors.Is(serverErr, storage.ErrBackchannelAuthenticationNotFound)",
"new": "return serverErr == nil",
"module": "root",
"packages": [
"./server"
],
"run": "^TestListBackchannelInteractionsSkipsAGoneRequest$",
"why": "the CIBA inbox listing leaves out an entry whose request the store says is gone"
},
{
"id": "server-ciba-inbox-skips-deregistered-client",
"file": "server/backchannel_inbox.go",
"old": "\tcase ErrorUnauthorizedClient:\n\t\treturn true",
"new": "\tcase ErrorUnauthorizedClient:\n\t\treturn false",
"module": "root",
"packages": [
"./server"
],
"run": "^TestBackchannelInboxSkipsADeregisteredClient$",
"why": "the CIBA inbox listing leaves out a request whose client is no longer registered"
},
{
"id": "server-ciba-deny-clears-notfound",
"file": "server/backchannel_inbox.go",
"old": "errors.Is(failure, storage.ErrBackchannelAuthenticationNotFound)",
"new": "failure == nil",
"module": "root",
"packages": [
"./server"
],
"run": "^(TestStaleBackchannelEntry|TestDenyBackchannelInteractionsClearsAGoneRequest)$",
"why": "DenyBackchannelInteractions passes over and clears a request the store says is gone"
},
{
"id": "memstore-ciba-lookup-wraps-notfound",
"file": "storage/memstore/backchannel_authentication_store.go",
"old": "fmt.Errorf(\"memstore: look up backchannel authentication: %w\", storage.ErrBackchannelAuthenticationNotFound)",
"new": "fmt.Errorf(\"memstore: look up backchannel authentication: %v\", storage.ErrBackchannelAuthenticationNotFound)",
"module": "root",
"packages": [
"./storage/memstore"
],
"run": "^TestBackchannelAuthenticationStoreReportsAnUnknownHandle$",
"why": "memstore wraps ErrBackchannelAuthenticationNotFound for a lookup of an unknown handle"
},
{
"id": "memstore-ciba-decide-wraps-notfound",
"file": "storage/memstore/backchannel_authentication_store.go",
"old": "fmt.Errorf(\"memstore: decide backchannel authentication: %w\", storage.ErrBackchannelAuthenticationNotFound)",
"new": "fmt.Errorf(\"memstore: decide backchannel authentication: %v\", storage.ErrBackchannelAuthenticationNotFound)",
"module": "root",
"packages": [
"./storage/memstore"
],
"run": "^TestBackchannelAuthenticationStoreRefusesDecisionOnUnknownHandle$",
"why": "memstore wraps ErrBackchannelAuthenticationNotFound for a decision on an unknown handle"
}
]
37 changes: 37 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,43 @@ that expire mid-resolution.
little lifetime for how long its endpoints take to answer: ask the
superior or RP to issue them for longer.

### A store of your own should report an unknown CIBA handle as not found (server, storage)

**Affects:** a deployment with `Dependencies.BackchannelInbox` set that
calls `Server.ListBackchannelInteractions` or
`Server.DenyBackchannelInteractions`, with a
`storage.BackchannelAuthenticationStore` of its own. `memstore` and
`sqlstore` (from the release that wraps it) need nothing.

**Why:** the listing left out every inbox entry whose request lookup
the store refused with anything but an outage, taking each for a
request that is gone. A store that refuses a lookup for another reason
with a plain error, or a request record the server can't read as its
own, was therefore hidden from the operator, and an account closure
could look finished while such an entry remained. A store now says a
request is gone by wrapping the new
`storage.ErrBackchannelAuthenticationNotFound`, and only such an entry
(or one whose client is no longer registered) is left out; any other is
reported. `DenyBackchannelInteractions` also passes over, and takes out
of the inbox, a request the store says is gone when it comes to deny
it.

**What fails:** with a store that doesn't wrap it, an inbox entry whose
request the store no longer holds is no longer left out silently:
`ListBackchannelInteractions` still returns every other request, but
with an error for that entry, and `DenyBackchannelInteractions` reports
it in its error, until the entry expires. `LookupBackchannelInteraction`
and `CompleteBackchannelAuthentication` answer an unknown handle as
before.

**What to change:** in `LookupBackchannelAuthentication`, and
`DecideBackchannelAuthentication`, wrap the sentinel for a handle the
store doesn't hold, and for nothing else (not an outage, not a request
already decided):
`fmt.Errorf("...: %w", storage.ErrBackchannelAuthenticationNotFound)`.
`storage.TestBackchannelAuthenticationStoreContract` checks it once you
do.

## v0.85.0

### Codes, refresh tokens and `auth_req_id`s are stored under digests covering the issuer (server, storage)
Expand Down
21 changes: 14 additions & 7 deletions docs/guides/ciba.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,16 @@ server. A request leaves the inbox once decided, or when it expires.
Each request listed costs store reads, so pass the listing your
request's context: once it ends, the listing reads no more and fails
with the context's error, rather than returning part of the inbox. An
entry it can't read, one whose record won't decode or whose request a
store couldn't answer for, doesn't hide the rest: it returns what it
could read with an error for each entry it couldn't, so treat any error
as a possibly incomplete list.
entry whose request is gone is left out: the backchannel store says so
by wrapping `storage.ErrBackchannelAuthenticationNotFound`, as `memstore`
does, and `sqlstore` from the release that wraps it, or its client is
no longer registered. An entry it can't read, one whose record won't
decode or whose request a store couldn't answer for or refused any
other way, doesn't hide the rest: it returns what it could read with an
error for each entry it couldn't, so treat any error as a possibly
incomplete list. With a store that doesn't wrap the sentinel, an entry
left behind for a request the store no longer holds is reported this
way until it expires.

The resolver also binds the request to that user: an `Authorize` for
anyone else is a failed authentication (`access_denied`). That matters
Expand All @@ -236,9 +242,10 @@ requests pending. To empty an inbox for good, have
`BackchannelSubjects` stop resolving the user's hints first, then call
it again until `ListBackchannelInteractions` lists nothing. A request
already decided (one left listed because its removal from the inbox
failed) or expired is passed over and its entry removed; any other
refusal is reported in the error and the request stays listed. A
store says a request was already decided by wrapping
failed), expired, or gone from the store since it was listed is passed
over and its entry removed; any other refusal, or an entry the listing
couldn't read, is reported in the error and stays listed. A store says
a request was already decided by wrapping
`storage.ErrBackchannelAuthenticationAlreadyDecided`, as `memstore`
does, and `sqlstore` from the release that wraps it: with a store that
doesn't, such an entry is reported each time until it expires.
Expand Down
7 changes: 5 additions & 2 deletions server/backchannel_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,11 @@ func (s *Server) backchannelInteraction(client storage.RegisteredClient, params
// decided or has expired (BackchannelAuthenticationStore's lookup doesn't
// say); CompleteBackchannelAuthentication is what enforces both, so a
// stale lookup can at most show a request that can no longer be
// completed. An unknown handle is an ErrorInvalidRequest *Error, and a
// request whose client is no longer registered ErrorUnauthorizedClient;
// completed. An unknown handle is an ErrorInvalidRequest *Error, which
// wraps the store's error (so errors.Is finds
// storage.ErrBackchannelAuthenticationNotFound with a store that wraps
// it), and a request whose client is no longer registered
// ErrorUnauthorizedClient;
// a store or client repository that couldn't answer is
// ErrorServerError.
func (s *Server) LookupBackchannelInteraction(ctx context.Context, handle BackchannelAuthenticationHandle) (BackchannelInteractionRequest, error) {
Expand Down
86 changes: 62 additions & 24 deletions server/backchannel_inbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,20 @@ func (s *Server) checkPendingBackchannelRequests(ctx context.Context, clientID f
// ListBackchannelInteractions reads no more of them and fails with
// ctx's error, rather than returning part of the inbox.
//
// An entry it can't read (a record that won't decode, or a request the
// backchannel or client store couldn't answer for) doesn't hide the
// others: it returns every request it could read, with an error joining
// one for each entry it couldn't. So a non-nil error, with or without
// requests, means the list may be incomplete; when every request must
// be accounted for, as when closing an account, treat it as a failure.
// An entry whose request is gone is left out: one the backchannel store
// says it holds no such request for, by wrapping
// storage.ErrBackchannelAuthenticationNotFound, or one whose client is
// no longer registered. An entry it can't read otherwise (a record that
// won't decode, a request the backchannel or client store couldn't
// answer for, or a lookup the backchannel store refused with an error
// that doesn't wrap the sentinel) doesn't hide the others: it returns
// every request it could read, with an error joining one for each entry
// it couldn't. So a non-nil error, with or without requests, means the
// list may be incomplete; when every request must be accounted for, as
// when closing an account, treat it as a failure. (With a store that
// doesn't wrap the sentinel, an entry left behind for a request the
// store no longer holds is reported this way each time, until the
// entry expires.)
//
// ListBackchannelInteractions doesn't check who is asking: the
// application must make sure the user is subject, as it does before
Expand All @@ -264,7 +272,8 @@ func (s *Server) ListBackchannelInteractions(ctx context.Context, subject Subjec

// listBackchannelInteractions returns the requests awaiting subject,
// and, separately, the entries it couldn't read (an undecodable record,
// or a request the backchannel store couldn't answer for) joined into
// or a request the backchannel store couldn't answer for or refused
// other than as gone) joined into
// unreadable, so one bad entry doesn't hide the others from
// DenyBackchannelInteractions. err is for a listing that failed as a
// whole, ctx ending before it finished among them.
Expand Down Expand Up @@ -306,9 +315,10 @@ func (s *Server) listBackchannelInteractions(ctx context.Context, subject Subjec

// pendingBackchannelInteraction rebuilds entry's request, reporting
// false for one that isn't a live request of subject's at this server:
// written by another issuer, expired, gone from the backchannel store,
// from a client no longer registered, or bound to another subject than
// the one it's filed under.
// written by another issuer, expired, gone from the backchannel store
// (goneBackchannelRequest), from a client no longer registered, or bound
// to another subject than the one it's filed under. Any other failure to
// read the request is an error.
func (s *Server) pendingBackchannelInteraction(ctx context.Context, subject SubjectID, entry storage.BackchannelInboxEntry) (PendingBackchannelInteraction, bool, error) {
var record backchannelInboxRecord
if err := decodeRecord(entry.Record, &record.Version, &record); err != nil {
Expand All @@ -323,8 +333,7 @@ func (s *Server) pendingBackchannelInteraction(ctx context.Context, subject Subj
}
interaction, resolved, err := s.lookupBackchannelInteraction(ctx, handle)
if err != nil {
var serverErr *Error
if errors.As(err, &serverErr) && (serverErr.Code() == ErrorInvalidRequest || serverErr.Code() == ErrorUnauthorizedClient) {
if goneBackchannelRequest(err) {
return PendingBackchannelInteraction{}, false, nil
}
return PendingBackchannelInteraction{}, false, err
Expand All @@ -337,6 +346,28 @@ func (s *Server) pendingBackchannelInteraction(ctx context.Context, subject Subj
return PendingBackchannelInteraction{ID: backchannelInboxID(entry.HandleHash), Handle: handle, Interaction: interaction, ExpiresAt: entry.ExpiresAt}, true, nil
}

// goneBackchannelRequest reports whether err, lookupBackchannelInteraction's
// refusal of a listed request, means the request is no longer one to
// list: the store says it holds no such request
// (storage.ErrBackchannelAuthenticationNotFound), or its client is no
// longer registered. Any other invalid_request, a refusal the store
// reported as a plain error or a request record the server can't read
// as its own, is an entry the listing couldn't read, not a request
// gone.
func goneBackchannelRequest(err error) bool {
var serverErr *Error
if !errors.As(err, &serverErr) {
return false
}
switch serverErr.Code() {
case ErrorUnauthorizedClient:
return true
case ErrorInvalidRequest:
return errors.Is(serverErr, storage.ErrBackchannelAuthenticationNotFound)
}
return false
}

// inboxWriteTimeout bounds each inbox write that doesn't end with its
// caller's context, storeBackchannelRequest's filing and
// unfileBackchannelRequest's removal: long enough for a store waiting on
Expand Down Expand Up @@ -373,16 +404,20 @@ func (s *Server) unfileBackchannelRequest(ctx context.Context, handleHash [32]by
// gets access_denied, a ping client is notified, and it leaves the
// inbox. One already decided, by another call or instance, or by an
// earlier call whose removal from the inbox failed, is passed over, not
// counted, and taken out of the inbox; so is one that has expired. A
// request counts as already decided only when the store says so by
// wrapping storage.ErrBackchannelAuthenticationAlreadyDecided: any other
// counted, and taken out of the inbox; so is one that has expired, and
// one gone from the store since it was listed. A request counts as
// already decided only when the store says so by wrapping
// storage.ErrBackchannelAuthenticationAlreadyDecided, and as gone only
// when it wraps storage.ErrBackchannelAuthenticationNotFound: any other
// refusal, such as a store outage the store reports as a plain error,
// is a failure for that request, which stays listed. Any failure, or an
// entry it can't read, doesn't stop it: it denies every other request,
// then returns how many it denied with every failure joined. What failed
// is still listed, so calling it again finishes the job. (With a store
// that doesn't wrap the sentinel, an entry left behind for a decided
// request is reported each time, until the request expires.) If ctx ends
// entry the listing couldn't read (see ListBackchannelInteractions),
// doesn't stop it: it denies every other request, then returns how many
// it denied with every failure joined; an entry it couldn't read isn't
// counted, and stays in the inbox. What failed is still listed, so
// calling it again finishes the job. (With a store that doesn't wrap
// the sentinels, an entry left behind for a decided or gone request is
// reported each time, until it expires.) If ctx ends
// before the requests are all listed, it denies none of them and returns
// ctx's error.
//
Expand Down Expand Up @@ -432,15 +467,18 @@ func (s *Server) DenyBackchannelInteractions(ctx context.Context, subject Subjec
// staleBackchannelEntry reports whether failure, recordBackchannelDecision's
// refusal of a listed request, means the request's inbox entry is stale:
// the request has expired, which the server decides itself, or the store
// says it was already decided (storage.ErrBackchannelAuthenticationAlreadyDecided).
// Any other invalid_request may be a store outage reported as a plain
// error, so the entry is kept for the request still awaiting a decision.
// says it was already decided (storage.ErrBackchannelAuthenticationAlreadyDecided)
// or holds no such request any more
// (storage.ErrBackchannelAuthenticationNotFound). Any other
// invalid_request may be a store outage reported as a plain error, so
// the entry is kept for the request still awaiting a decision.
func staleBackchannelEntry(failure *Error) bool {
switch failure.Code() {
case ErrorExpiredToken:
return true
case ErrorInvalidRequest:
return errors.Is(failure, storage.ErrBackchannelAuthenticationAlreadyDecided)
return errors.Is(failure, storage.ErrBackchannelAuthenticationAlreadyDecided) ||
errors.Is(failure, storage.ErrBackchannelAuthenticationNotFound)
}
return false
}
Loading
Loading