diff options
| author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2024-01-22 07:49:44 -0500 |
|---|---|---|
| committer | pg9182 <96569817+pg9182@users.noreply.github.com> | 2024-01-22 07:49:44 -0500 |
| commit | 7c16a136150c4509f6bb2dd6712a085d81441be3 (patch) | |
| tree | 1d57504f60b21a7e446e9723a15cf35ee60ea6bb /pkg/api | |
| parent | 178ea8367ebda95f5f275af203b96f0903bc4585 (diff) | |
| download | Atlas-7c16a136150c4509f6bb2dd6712a085d81441be3.tar.gz Atlas-7c16a136150c4509f6bb2dd6712a085d81441be3.zip | |
all: Drop support for origin username source
Diffstat (limited to 'pkg/api')
| -rw-r--r-- | pkg/api/api0/api.go | 5 | ||||
| -rw-r--r-- | pkg/api/api0/client.go | 121 | ||||
| -rw-r--r-- | pkg/api/api0/metrics.go | 16 |
3 files changed, 2 insertions, 140 deletions
diff --git a/pkg/api/api0/api.go b/pkg/api/api0/api.go index 2e3593c..355deef 100644 --- a/pkg/api/api0/api.go +++ b/pkg/api/api0/api.go @@ -30,7 +30,6 @@ import ( "github.com/r2northstar/atlas/pkg/eax" "github.com/r2northstar/atlas/pkg/metricsx" "github.com/r2northstar/atlas/pkg/nspkt" - "github.com/r2northstar/atlas/pkg/origin" "github.com/rs/zerolog/hlog" "golang.org/x/mod/semver" ) @@ -52,10 +51,6 @@ type Handler struct { // UsernameSource configures the source to use for usernames. UsernameSource UsernameSource - // OriginAuthMgr, if provided, manages Origin nucleus tokens for checking - // usernames. - OriginAuthMgr *origin.AuthMgr - // EAXClient makes requests to the EAX API. EAXClient *eax.Client diff --git a/pkg/api/api0/client.go b/pkg/api/api0/client.go index b3fd686..b718e17 100644 --- a/pkg/api/api0/client.go +++ b/pkg/api/api0/client.go @@ -13,7 +13,6 @@ import ( "github.com/r2northstar/atlas/pkg/api/api0/api0gameserver" "github.com/r2northstar/atlas/pkg/eax" - "github.com/r2northstar/atlas/pkg/origin" "github.com/r2northstar/atlas/pkg/pdata" "github.com/r2northstar/atlas/pkg/stryder" "github.com/rs/zerolog/hlog" @@ -26,22 +25,9 @@ const ( // Don't get usernames. UsernameSourceNone UsernameSource = "" - // Get the username from the Origin API. - UsernameSourceOrigin UsernameSource = "origin" - - // Get the username from the Origin API, but fall back to EAX on failure. - UsernameSourceOriginEAX UsernameSource = "origin-eax" - // Get the username from EAX. UsernameSourceEAX UsernameSource = "eax" - // Get the username from the Origin API, but also check EAX and warn if it's - // different. - UsernameSourceOriginEAXDebug UsernameSource = "origin-eax-debug" - - // Get the username from EAX, but fall back to the Origin API on failure. - UsernameSourceEAXOrigin UsernameSource = "eax-origin" - // Get the username from Stryder (available since October 2, 2023). Note // that this source only returns usernames for valid tokens. UsernameSourceStryder UsernameSource = "stryder" @@ -318,48 +304,8 @@ func (h *Handler) lookupUsername(r *http.Request, uid uint64, stryderRes []byte) switch h.UsernameSource { case UsernameSourceNone: break - case UsernameSourceOrigin: - username, _ = h.lookupUsernameOrigin(r, uid) - case UsernameSourceOriginEAX: - username, _ = h.lookupUsernameOrigin(r, uid) - if username == "" { - if eaxUsername, ok := h.lookupUsernameEAX(r, uid); ok { - username = eaxUsername - hlog.FromRequest(r).Warn(). - Uint64("uid", uid). - Str("origin_username", eaxUsername). - Msgf("failed to get username from origin, but got it from eax") - } - } - case UsernameSourceOriginEAXDebug: - username, _ = h.lookupUsernameOrigin(r, uid) - if eaxUsername, ok := h.lookupUsernameEAX(r, uid); ok { - if eaxUsername != username { - hlog.FromRequest(r).Warn(). - Uint64("uid", uid). - Str("origin_username", username). - Str("eax_username", eaxUsername). - Msgf("got username from origin and eax, but they don't match; using the origin one") - } - } else { - hlog.FromRequest(r).Warn(). - Uint64("uid", uid). - Str("origin_username", username). - Msgf("got username from origin, but failed to get username from eax") - } case UsernameSourceEAX: username, _ = h.lookupUsernameEAX(r, uid) - case UsernameSourceEAXOrigin: - username, _ = h.lookupUsernameEAX(r, uid) - if username == "" { - if originUsername, ok := h.lookupUsernameOrigin(r, uid); ok { - username = originUsername - hlog.FromRequest(r).Warn(). - Uint64("uid", uid). - Str("origin_username", originUsername). - Msgf("failed to get username from eax, but got it from origin") - } - } case UsernameSourceStryder: username, _ = h.lookupUsernameStryder(r, uid, stryderRes) case UsernameSourceStryderEAX: @@ -396,73 +342,6 @@ func (h *Handler) lookupUsername(r *http.Request, uid uint64, stryderRes []byte) return } -// lookupUsernameOrigin gets the username for uid from the Origin API, returning -// an empty string if a username does not exist for the uid, and false on error. -func (h *Handler) lookupUsernameOrigin(r *http.Request, uid uint64) (username string, ok bool) { - select { - case <-r.Context().Done(): // check if the request was canceled to avoid polluting the metrics - return - default: - } - if h.OriginAuthMgr == nil { - hlog.FromRequest(r).Error(). - Str("username_source", "origin"). - Msgf("no origin auth available for username lookup") - return - } - originStart := time.Now() - if tok, ours, err := h.OriginAuthMgr.OriginAuth(false); err == nil { - if ui, err := origin.GetUserInfo(r.Context(), tok, uid); err == nil { - if len(ui) == 1 { - username = ui[0].EAID - h.m().client_originauth_origin_username_lookup_calls_total.success.Inc() - } else { - h.m().client_originauth_origin_username_lookup_calls_total.notfound.Inc() - } - ok = true - } else if errors.Is(err, origin.ErrAuthRequired) { - if tok, ours, err := h.OriginAuthMgr.OriginAuth(true); err == nil { - if ui, err := origin.GetUserInfo(r.Context(), tok, uid); err == nil { - if len(ui) == 1 { - username = ui[0].EAID - h.m().client_originauth_origin_username_lookup_calls_total.success.Inc() - } else { - h.m().client_originauth_origin_username_lookup_calls_total.notfound.Inc() - } - ok = true - } - } else if ours { - hlog.FromRequest(r).Error(). - Err(err). - Str("username_source", "origin"). - Msgf("origin auth token refresh failure") - h.m().client_originauth_origin_username_lookup_calls_total.fail_authtok_refresh.Inc() - } - } else if !errors.Is(err, context.Canceled) { - hlog.FromRequest(r).Error(). - Err(err). - Str("username_source", "origin"). - Msgf("failed to get origin user info") - h.m().client_originauth_origin_username_lookup_calls_total.fail_other_error.Inc() - } - if username == "" && ok { - hlog.FromRequest(r).Warn(). - Err(err). - Uint64("uid", uid). - Str("username_source", "origin"). - Msgf("no origin username found for uid") - } - } else if ours { - hlog.FromRequest(r).Error(). - Err(err). - Str("username_source", "origin"). - Msgf("origin auth token refresh failure") - h.m().client_originauth_origin_username_lookup_calls_total.fail_authtok_refresh.Inc() - } - h.m().client_originauth_origin_username_lookup_duration_seconds.UpdateDuration(originStart) - return -} - // lookupUsernameEAX gets the username for uid from the EAX API, returning an // empty string if a username does not exist for the uid, and false on error. func (h *Handler) lookupUsernameEAX(r *http.Request, uid uint64) (username string, ok bool) { diff --git a/pkg/api/api0/metrics.go b/pkg/api/api0/metrics.go index 0c18d0a..5c8c462 100644 --- a/pkg/api/api0/metrics.go +++ b/pkg/api/api0/metrics.go @@ -70,15 +70,8 @@ type apiMetrics struct { fail_other_error *metrics.Counter http_method_not_allowed *metrics.Counter } - client_originauth_requests_map *metricsx.GeoCounter2 - client_originauth_stryder_auth_duration_seconds *metrics.Histogram - client_originauth_origin_username_lookup_duration_seconds *metrics.Histogram - client_originauth_origin_username_lookup_calls_total struct { - success *metrics.Counter - notfound *metrics.Counter - fail_authtok_refresh *metrics.Counter - fail_other_error *metrics.Counter - } + client_originauth_requests_map *metricsx.GeoCounter2 + client_originauth_stryder_auth_duration_seconds *metrics.Histogram client_originauth_eax_username_lookup_duration_seconds *metrics.Histogram client_originauth_eax_username_lookup_calls_total struct { success *metrics.Counter @@ -270,11 +263,6 @@ func (h *Handler) m() *apiMetrics { mo.client_originauth_requests_total.http_method_not_allowed = mo.set.NewCounter(`atlas_api0_client_originauth_requests_total{result="http_method_not_allowed"}`) mo.client_originauth_requests_map = metricsx.NewGeoCounter2(`atlas_api0_client_originauth_requests_map`) mo.client_originauth_stryder_auth_duration_seconds = mo.set.NewHistogram(`atlas_api0_client_originauth_stryder_auth_duration_seconds`) - mo.client_originauth_origin_username_lookup_duration_seconds = mo.set.NewHistogram(`atlas_api0_client_originauth_origin_username_lookup_duration_seconds`) - mo.client_originauth_origin_username_lookup_calls_total.success = mo.set.NewCounter(`atlas_api0_client_originauth_origin_username_lookup_calls_total{result="success"}`) - mo.client_originauth_origin_username_lookup_calls_total.notfound = mo.set.NewCounter(`atlas_api0_client_originauth_origin_username_lookup_calls_total{result="notfound"}`) - mo.client_originauth_origin_username_lookup_calls_total.fail_authtok_refresh = mo.set.NewCounter(`atlas_api0_client_originauth_origin_username_lookup_calls_total{result="fail_authtok_refresh"}`) - mo.client_originauth_origin_username_lookup_calls_total.fail_other_error = mo.set.NewCounter(`atlas_api0_client_originauth_origin_username_lookup_calls_total{result="fail_other_error"}`) mo.client_originauth_eax_username_lookup_duration_seconds = mo.set.NewHistogram(`atlas_api0_client_originauth_eax_username_lookup_duration_seconds`) mo.client_originauth_eax_username_lookup_calls_total.success = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="success"}`) mo.client_originauth_eax_username_lookup_calls_total.notfound = mo.set.NewCounter(`atlas_api0_client_originauth_eax_username_lookup_calls_total{result="notfound"}`) |
