Repository navigation
Conversation
Slack's read methods accept GET with query-string arguments, and the token travels in the injected authorization header rather than as a query parameter, so the read-only method preset covers reads. Grant read-only access in the built-in profile and state that write methods such as chat.postMessage need an explicit rule or a read-write copy. Drop the incorrect claim that Slack reads require POST. Describe where the Slack error name surfaces (the provider_error_subtype field of the refresh status API, echoed in LAST_ERROR). Mirrors the follow-up on the upstream submission (ai-openshell#3730). Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Slack's read methods accept GET with query-string arguments, and the token travels in the injected authorization header rather than as a query parameter, so the read-only method preset covers reads. Grant read-only access in the built-in profile and state that write methods such as chat.postMessage need an explicit rule or a read-write copy. Drop the incorrect claim that Slack reads require POST. Describe where the Slack error name surfaces (the provider_error_subtype field of the refresh status API, echoed in LAST_ERROR). Mirrors the follow-up on the upstream submission (ai-openshell#3730). Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
|
This pull request has had no activity for 14 days and is now marked stale. |
04fe29f to
6b8aec8
Compare
|
This pull request has had no activity for 14 days and is now marked stale. |
…P 2xx RFC 6749 section 5.2 puts token endpoint errors on 4xx responses, but some issuers answer HTTP 200 with an `error` body. Slack's oauth.v2.access does this for every failure. Today such a body does not parse as a token response, so it falls into the uncertain-exchange handling: a user refresh grant parks as `oauth_refresh_exchange_uncertain` even when the issuer only said `ratelimited`, and a non-interactive grant loops on `oauth_invalid_success_response` investigation instead of reporting a configuration problem. When a 2xx body does not parse as a token response but does parse as an OAuth error response with an error name the classifier recognizes, route it through the existing error classifier before the uncertain-exchange fallback. Bodies that carry a token are handled exactly as before, and bodies with neither a token nor a recognized `error` name keep the existing fallback: a user grant parks for reauthorization because its single-use refresh token may already be spent, and a non-interactive grant reports `oauth_invalid_success_response`. Fold the Slack token endpoint error vocabulary onto the closest RFC failure codes so status consumers keep a stable vocabulary, preserving the issuer's own name as the provider error subtype in the same way the Google `invalid_rapt` and `admin_policy_enforced` cases already do. Transient Slack errors such as `ratelimited` stay retryable. The issuer table is consulted only for errors that arrived in a 2xx envelope, so RFC 6749 error responses classify exactly as before. Terminal outcomes stay gated on the grant kind: user refresh grants park for reauthorization, non-interactive grants fall back to configuration repair. Refs ai-openshell#3729 Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Add `providers/slack.yaml`, an example profile for Slack apps that have token rotation enabled. Slack issues user access tokens that expire after 43200 seconds together with a single-use refresh token, and requires the app client ID and client secret on every refresh, so the profile declares an `oauth2_refresh_token` credential against oauth.v2.access with a matching 43200-second lifetime cap, a 21600-second refresh lead, and client_id / client_secret / refresh_token material. Slack Web API methods are POST even for reads, so the endpoint uses the read-write method preset; deployers add `rules` for the methods their workloads need. Tighten `ProviderTypeProfile::adc_credential` to require the Google token endpoint in addition to the three ADC material keys, so that `--from-gcloud-adc` keeps refusing profiles whose refresh material merely has the same shape. Document the profile under how-it-works/providers. Refs ai-openshell#3729 Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Slack's read methods accept GET with query-string arguments, and the token travels in the injected authorization header rather than as a query parameter, so the read-only method preset covers reads. Grant read-only access in the example, matching the posture of the GitHub example, and state that write methods such as chat.postMessage need an explicit rule or a read-write copy. Drop the incorrect claim that Slack reads require POST from the profile header and the docs. Offer the raw-URL import form used by the sibling provider pages, using the top-level `openshell profile` commands, and describe where the Slack error name surfaces (the provider_error_subtype field of the refresh status API, echoed in LAST_ERROR). Manual rotation takes the same per-credential refresh locks as the scheduled refresh, so replace the warning that it could race the gateway with the actual cost: each rotation spends the current refresh token. Refs ai-openshell#3729 Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
6b8aec8 to
91e8e44
Compare
mrunalp
left a comment
There was a problem hiding this comment.
Reusing the OAuth refresh engine makes sense, and the store-level test covers persistence of the replacement refresh token. I’m requesting changes to the example policy, the handling of ambiguous refresh outcomes and network restrictions, and the smoke test. I’ve left the details inline.
The issue-acceptance check also needs attention. The linked issue is still labeled state:triage-needed. Issue #5561
I reviewed 91e8e44 and checked the shell expansion with a dummy value. I did not rerun the Rust suites or perform a live Slack exchange.
| - host: slack.com | ||
| port: 443 | ||
| protocol: rest | ||
| access: read-only |
There was a problem hiding this comment.
Please restrict the example to explicit HTTP methods and Slack API paths. The read-only preset allows GET across slack.com, and Slack exposes token revocation via GET with no scope requirement. A sandbox granted read access can therefore invalidate the access token used by other workloads sharing this provider. A narrow POST rule for auth.test would also let the smoke test use Slack’s documented method. Slack auth.revoke · Slack auth.test
| "request_timeout", | ||
| "service_unavailable", | ||
| "internal_error", | ||
| "fatal_error", |
There was a problem hiding this comment.
Please keep internal_error and fatal_error on the oauth_refresh_exchange_uncertain path for user grants. Slack says both errors can follow partial success. If Slack consumed the single-use refresh token before returning the error, the gateway has no replacement and this retry sends the spent token again. A test alongside ratelimited could pin the distinction between a known refusal and an uncertain exchange. Slack token endpoint errors
| openshell sandbox create --name slack-sandbox --provider my-slack | ||
| openshell sandbox exec slack-sandbox -- \ | ||
| curl -s https://slack.com/api/auth.test \ | ||
| -H "Authorization: Bearer $SLACK_USER_TOKEN" |
There was a problem hiding this comment.
The host shell expands $SLACK_USER_TOKEN before openshell sandbox exec starts. Following the setup above puts the operator’s real token in the command arguments sent to the sandbox. Please run curl through a single-quoted sh -c script so the variable expands inside the sandbox and curl uses the managed placeholder. The smoke test in providers/slack.yaml needs the same change.
| const ISSUER_UNSUPPORTED_GRANT_TYPE_ERRORS: &[&str] = &["invalid_grant_type"]; | ||
| const ISSUER_RETRYABLE_ERRORS: &[&str] = &[ | ||
| "ratelimited", | ||
| "accesslimited", |
There was a problem hiding this comment.
accesslimited means Slack restricts this method on the caller’s network. Retrying every minute from the same gateway leaves the restriction in place. Please surface this as a configuration problem. The nearby invalid_auth mapping also deserves guidance that mentions network policy, since Slack can return it when the gateway IP is disallowed and reauthorizing the user won’t fix that. Slack token endpoint errors
Slack documents that `internal_error` and `fatal_error` from oauth.v2.access can follow partial success, so the single-use refresh token may already be spent. Retrying would resend a consumed token, so a user grant now takes the uncertain-exchange path (`oauth_refresh_exchange_uncertain`, reauthorize) with the Slack name as the provider error subtype. Non-interactive grants hold no single-use material and keep retrying. `accesslimited` means Slack restricts the method on the caller's network, which retrying from the same gateway cannot fix. Report it as `oauth_access_denied` with recovery `fix_configuration` and point at the gateway's egress address. `invalid_auth` stays `oauth_invalid_grant`, but its status message now notes that Slack also returns it for a disallowed IP address. Refs ai-openshell#3729 Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Slack accepts GET on most Web API methods, including write methods and auth.revoke, which needs no scope. The read-only preset therefore let a sandbox revoke the access token shared by every workload on the provider. Replace it with an explicit list of read method paths under /api/ plus POST for auth.test, and add a test that the example keeps explicit, non-wildcard rules. Run the smoke test through a single-quoted `sh -c` script so `$SLACK_USER_TOKEN` expands inside the sandbox to the managed placeholder instead of in the operator's shell, and use POST for auth.test as Slack documents. Update the failure table for the partial-success and network-restriction classifications. Refs ai-openshell#3729 Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
Summary
Adds a Slack example provider profile whose user token is kept fresh by the gateway's
oauth2_refresh_tokenengine, and fixes how the engine reads Slack's token endpoint errors. Slack reports everyoauth.v2.accessfailure as HTTP 200 with anerrorbody. On currentmainsuch a body does not parse as a token response, so it falls into the uncertain-exchange handling: a user grant parks asoauth_refresh_exchange_uncertaineven when Slack only answeredratelimited, and a non-interactive grant loops onoauth_invalid_success_responseinvestigation instead of reporting a configuration problem.Related Issue
Fixes #5561. If maintainers prefer, the first commit (
fix(credential-issuer)) stands on its own as a localized bug fix and can be split out.Changes
fix(credential-issuer): inrefresh/minter.rsrequest_token, a 2xx body that does not parse as a token response but does parse as an OAuth error response with an error name the classifier recognizes is routed through the existing classifier before the uncertain-exchange fallback that feat(server): add operator-only provider credential retrieval #4357 added.oauth_refresh_exchange_uncertain(reauthorize) whenever a 2xx body is unusable, because the single-use refresh token may already be spent. That is the right call for a body that says nothing, but a body with a recognizederrorname is an explicit answer from the issuer. Classifying it first keeps200 {"ok":false,"error":"ratelimited"}retryable instead of forcing a reauthorization, and parksinvalid_refresh_token/token_revokedasoauth_invalid_grantwith the Slack name asprovider_error_subtypeinstead of the generic uncertain code.oauth_refresh_exchange_uncertain, and a non-interactive grant still reportsoauth_invalid_success_response. That covers both a body with noerrorfield and a body with an unknownerrorname.invalid_rapt/admin_policy_enforcedprecedent:invalid_refresh_token,token_revoked,token_expired,account_inactive,invalid_authmap tooauth_invalid_grant(parked for user grants, configuration repair for non-interactive grants, so those no longer loop on investigation);invalid_client_id,bad_client_secretmap tooauth_invalid_client;invalid_grant_typemaps tooauth_unsupported_grant_type; andratelimited,accesslimited,request_timeout,service_unavailable,internal_error,fatal_errormap tooauth_token_endpoint_retryable. Slack documentsinvalid_refresh_token, the client errors and the transient names foroauth.v2.access.token_revoked,token_expired,account_inactiveandinvalid_authare Slack's general authentication errors, included defensively.invalid_grant) use the RFC table. None of the issuer names collide with RFC names.feat(providers):providers/slack.yamlexample profile (bearerSLACK_USER_TOKEN,oauth2_refresh_tokenagainstoauth.v2.access, a 43200 smax_lifetime_secondsmatching Slack's fixed token lifetime instead of the 3600 s default cap, a 21600 s lead, andclient_id/client_secret/refresh_tokenmaterial) with the standard example header, plusdocs/how-it-works/providers/slack.mdx, a nav entry, and the example catalog list entry next tooci-genai. Also tightensProviderTypeProfile::adc_credentialto require the Google token endpoint alongside the three ADC material keys, so--from-gcloud-adcdoes not accept the Slack profile just because its material has the same shape.fix(providers): the example grants read-only access. Slack's read methods accept GET and the token travels in the injected header, so the read-only preset covers reads and keeps write methods denied until a policy allows them, matching the GitHub example. Docs use the top-levelopenshell profileimport form used by the sibling pages.Refresh serialization for single-use refresh tokens
Slack refresh tokens are single use, so two concurrent exchanges for one grant would be fatal. I checked that current
mainalready serializes them. The manual rotate RPC (CredentialRefresh::rotate→engine::refresh_provider_credential), the worker sweep (engine::refresh_states, includingrotation_requested) andensure_freshall go throughrefresh_from_snapshot_with_trigger. That function takes the per-credentialREFRESH_LOCKSmutex (keyed by provider id and credential key), then the distributedRefreshStateStore::acquireguard, then re-reads the state. A waiter whose snapshot predates a newly committed mint returns that mint and does not exchange again. A state left inrefresh_in_progress/refresh_committingis refused rather than re-exchanged.refresh_in_progressis persisted before the issuer is contacted. This PR needs no extra locking. The Slack docs say that a manual rotation does not race the scheduled refresh but does spend the current refresh token.Out of scope on purpose:
openshell-core/src/oauth.rs(extension token-grant / RFC 8693 exchange) has the same status-only success check and is untouched.Testing
Run on this branch (rebased on
mainat 0bf8035):cargo test -p openshell-credential-issuer: 72 passed (71 lib + 1 trait contract). New tests: issuer error names map by grant kind; client/transient errors keep RFC failure codes; issuer names on a 400 stay unrecognized (4xx behaviour unchanged);200 ratelimitedis retryable for both grant kinds (not uncertain);200 invalid_refresh_tokenparks a user grant asoauth_invalid_grantwith the subtype, and200 token_revokedsends a non-interactive grant to configuration repair; a 200 RFCinvalid_grantuses the RFC table; an unrecognized 200 body (noerror, or an unknownerrorname) still takes the feat(server): add operator-only provider credential retrieval #4357 uncertain path for user grants andoauth_invalid_success_responsefor non-interactive grants.cargo test -p openshell-server --features prebuilt-z3 --lib provider: 431 passed (--lib profile: 147 passed). New store-level tests: a 200 error body parks the state asreauthorization_requiredwith subtypeinvalid_refresh_token; a 200 body with neither token nor error parks a user grant asoauth_refresh_exchange_uncertain; a Slack-shaped success body mints with a 12 h lifetime and persists the rotated refresh token. Example catalog list updated.cargo test -p openshell-providers: 144 passed (newslack_profile_declares_rotating_user_token; the example catalog validates with the new file).cargo test -p openshell-cli adc: the--from-gcloud-adctests pass with the tightened detection.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,scripts/update_license_headers.py --check(1521 files) andmarkdownlint-cli2(168 files, 0 issues) are clean.reauthorization_requiredwith subtypeinvalid_refresh_token.Checklist