Repository navigation
fix(auth): preserve security requirement alternatives - #191
Merged
Merged
Conversation
Keep OpenAPI and Swagger security requirements as OR-of-AND entries instead of flattening them. Generated specs carry each scheme's type, scheme, location, parameter, and scopes; the catalog exposes them as auth.requirements; an empty entry makes the operation public. Before sending, the runtime checks the resolved request (stored credential plus header and query parameters) and fails with not_authenticated when no entry is satisfied. Closes #122 Signed-off-by: samzong <samzong.lu@gmail.com>
Contributor
Merging this PR will not alter performance
|
samzong
marked this pull request as ready for review
October 3, 2026 19:01
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Closes #122.
type,scheme,in,param,scopes) come fromsecurityDefinitions/components.securitySchemes; Swaggerbasicmaps tohttpbasic.{}makes the operation public, so it runs without a stored host.auth.requirementslists every alternative;auth.scopesstays the sorted union. Workflow entries keeprequired/scopesonly.not_authenticated(exit 4) witherror.detaillisting accepted alternatives from spec metadata only. Undefined/unknown schemes, mutual TLS, custom authenticators, and dry-run are not checked. An API key stored for theAuthorizationheader satisfieshttp/oauth2/openIdConnectschemes.requirementsand the satisfaction rules.examples/richapi:Users_Listaccepts bearer or API key; newAudit_Exportrequires bearer and a tenant key.Verification
make check— passed.go test -race ./pkg/runtime/... ./internal/codegen/...— passed.TestSecurityRequirements_BeforeSendcovers OR alternatives (bearer, API key), AND combinations, anonymous alternatives without a host, workflow steps, header/query parameters supplying schemes, and an API key inAuthorization; error output never contains credential values.examples/richapi:lathe codegen -cache fixtures, build,__lathe verify --json→ok: true;commands --json→catalog_schema_version26 withauth.requirements.users listsent withAuthorization,audit exportexit 4 with no request; API key login →users listsent withX-API-Key,audit exportexit 4.Not verified: real OAuth device login end to end (unit-level: it stores a bearer credential); a live service with cookie API keys.
Compatibility
runtime.SchemaVersion19 andruntime.CatalogSchemaVersion26; regenerate downstream CLIs.Checklist
internal/generated/,.cache/, and ad-hocskills/<cli-name>/directories is not committed.