Skip to main content

Provider-neutral authentication and authorization contracts for Spakky Framework

Project description

Spakky Auth

Spakky Framework를 위한 provider-neutral 인증/인가 core package입니다.

설치

pip install spakky-auth

현재 범위

spakky-auth는 인증/인가 마일스톤의 provider-neutral semantic model과 public provider contract를 소유합니다. Provider plugin과 boundary integration이 의존할 수 있는 spakky.auth import root, package metadata, workspace registration, documentation API path와 함께 다음 core 계약을 제공합니다.

  • AuthContext, AuthSubject, AuthClaim: inbound adapter가 사용자 호출 전에 ApplicationContext context value에 seed하는 인증 상태
  • CredentialCarrier: provider가 해석할 boundary-local credential 전달체
  • AuthorizationDecision, AuthorizationDecisionState, AuthorizationReasonCode: ALLOW, CHALLENGE, DENY, ERROR 판정 모델
  • AuthContextSnapshot: raw bearer token 대신 task/broker/saga 등으로 전파하는 signed snapshot envelope 계약
  • AuthCapability: authentication, policy evaluation, permission/role/scope/relation check, snapshot sign/verify, password hash/verify capability 선언
  • IAuthenticationProvider, IAuthorizationPolicyEvaluator, IPermissionChecker, IRoleChecker, IScopeChecker, IRelationChecker, IAuthContextSnapshotSigner, IAuthContextSnapshotVerifier, IPasswordHasher, IPasswordVerifier: ABC + abstractmethod 기반 public provider port
  • AuthInvocation, AuthDynamicRef, IAuthInvocationResolver: resource/action/tenant dynamic ref를 invocation에서 resolve하기 위한 provider-neutral 계약
  • AuthProviderContribution: spakky.contributions.spakky.auth feature-local contribution이 capability set을 선언하기 위한 metadata 계약
  • AuthSnapshotPropagationConfig: signed AuthContextSnapshot 전파 사용 여부를 선언하는 feature-local config
  • public_access, protected, require_scope, require_role, require_permission, require_policy, require_relation: class/function boundary에 public/protected auth metadata를 선언하는 Spakky-native decorator
  • get_effective_auth_metadata: class-level과 method-level requirement를 AND semantics로 결합하고 exact duplicate canonical requirement를 idempotent하게 deduplicate하는 metadata aggregation API
  • AuthorizationAspect, AsyncAuthorizationAspect: request-scope AuthContext를 읽어 protected metadata를 sync/async AOP로 enforcement하는 component
  • AuthCapabilityStartupValidationService: plugin load/scan 이후 service start 이전에 protected metadata와 snapshot propagation config가 요구하는 AuthCapability 제공자 count를 검증하는 startup service
  • AbstractSpakkyAuthError 기반 auth 오류 hierarchy

Provider implementation과 boundary integration은 후속 이슈에서 추가됩니다. Decorator가 없는 boundary는 allow all이며, protected/decorated boundary는 request-scope AuthContext와 provider-neutral checker port를 통해 fail closed로 처리됩니다.

Decorator Metadata & AOP Enforcement

Public boundary는 @public_access로 명시하고, 인증만 필요한 boundary는 @protected로 표시합니다. 권한 requirement는 다음 decorator로 추가합니다.

from spakky.auth import protected, require_role, require_scope


@require_role("role:admin")
class DocumentController:
    @require_scope("documents:read")
    @protected
    def read(self) -> str:
        return "ok"

Stacked requirement는 canonical AuthRequirement tuple로 aggregate되며, exact duplicate는 제거됩니다. Class-level requirement와 method-level requirement는 AND semantics로 결합됩니다. public_access와 protected requirement가 effective metadata에서 동시에 관찰되면 ConflictingAuthMetadataError가 발생합니다. OR/ANY semantics는 decorator 조합이 아니라 후속 spakky-policy named policy로 표현합니다.

AuthorizationAspectAsyncAuthorizationAspect는 메서드 인자로 AuthContext를 요구하지 않습니다. 각 inbound adapter가 ApplicationContext request/context scope에 seed한 AuthContextrequire_auth_context()로 읽고, provider-neutral checker port decision이 ALLOW가 아니면 AuthRequirementDeniedError로 실패합니다. 이 오류는 non-ALLOW AuthorizationDecisiondecision 속성에 보존하므로 inbound adapter는 원래 reason code를 CLI/HTTP/gRPC 등 transport별 응답으로 매핑할 수 있습니다.

Provider Contribution Contract

Auth provider plugin은 base plugin entry point와 별도로 spakky.contributions.spakky.auth contribution entry point를 선언하고, 해당 contribution에서 AuthProviderContribution capability set과 필요한 port 구현 Pod을 등록합니다. Core spakky-auth는 provider plugin 이름이나 provider-specific 문자열로 분기하지 않습니다. Capability count 검증과 protected boundary enforcement는 feature-local startup validation 및 AOP로 연결됩니다.

Startup Capability Validation

initialize()AuthCapabilityStartupValidationService를 등록합니다. 이 service는 load_plugins()scan()으로 등록된 Pod metadata 및 AuthProviderContribution contribution을 기준으로 service lifecycle start 전에 fail-fast validation을 수행합니다.

  • protected metadata가 하나라도 있으면 AUTHENTICATION capability 제공자가 정확히 1개 필요합니다.
  • require_permission, require_role, require_scope, require_policy, require_relation metadata는 각각 PERMISSION_CHECK, ROLE_CHECK, SCOPE_CHECK, POLICY_EVALUATION, RELATION_CHECK 제공자가 정확히 1개 필요합니다.
  • enabled AuthSnapshotPropagationConfig가 있으면 SNAPSHOT_SIGN, SNAPSHOT_VERIFY 제공자가 각각 정확히 1개 필요합니다.
  • protected usage와 enabled snapshot propagation config가 모두 없으면 provider가 없어도 startup fatal이 아닙니다.

count가 0 또는 2 이상이면 AuthStartupCapabilityValidationError가 발생하며, 각 mismatch는 auth.capability.validation.error startup diagnostic detail로 노출됩니다. 이 검증은 spakky-auth feature-local capability count 확인만 수행하며 generic contribution routing이나 provider priority/routing은 구현하지 않습니다.

Context & Snapshot Keys

AuthContextspakky.auth.context key로 ApplicationContext.set_context_value()에 저장됩니다. 편의 함수 store_auth_context()require_auth_context()는 이 key를 사용합니다.

AuthContextSnapshot 전파 key는 다음과 같습니다.

용도 Key
metadata spakky.auth.context_snapshot
header x-spakky-auth-context-snapshot

snapshot envelope는 schema version, subject, issuer, tenant, roles, scopes, selected claims, issued/expires timestamp, correlation id, delegation chain, signature material을 포함하는 canonical JSON을 unpadded base64url로 인코딩한 값입니다. 기본 clock skew는 60초입니다.

missing, invalid, expired snapshot은 기본적으로 CHALLENGE decision이며, verification provider unavailable은 ERROR decision입니다.

Plugin Entry Point

패키지는 Spakky plugin discovery를 위해 다음 entry point를 등록합니다.

[project.entry-points."spakky.plugins"]
spakky-auth = "spakky.auth.main:initialize"

현재 initialize()AuthCapabilityStartupValidationService, AuthorizationAspect, AsyncAuthorizationAspect를 등록합니다. 후속 이슈에서 boundary integration이 추가되면 같은 entry point를 통해 feature-local component를 등록합니다.

개발 검증

패키지 단위 검증은 패키지 디렉토리에서 실행합니다.

cd core/spakky-auth
uv run ruff format .
uv run ruff check .
uv run pyrefly check
uv run pytest

pytestpyproject.toml의 coverage 설정을 사용하며 src/spakky/auth/**/*.py에 대해 100% coverage를 요구합니다.

라이선스

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spakky_auth-6.6.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spakky_auth-6.6.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file spakky_auth-6.6.1.tar.gz.

File metadata

  • Download URL: spakky_auth-6.6.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spakky_auth-6.6.1.tar.gz
Algorithm Hash digest
SHA256 07fe07ae6eebb1a39043dea963d5d444f57b13db1d4e9fcc03f3bf0e67f10b25
MD5 2d1b7d52d6aff8a8ad0ebc030e740001
BLAKE2b-256 90bc6d7255a7b61ec37f4c069c34fd663f57bf51a2592479db3213a866dfb964

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_auth-6.6.1.tar.gz:

Publisher: release.yml on E5presso/spakky-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spakky_auth-6.6.1-py3-none-any.whl.

File metadata

  • Download URL: spakky_auth-6.6.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spakky_auth-6.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8938320fd6ed001e99389b2c05381803fd7d0c48867938e21911cdb0ffa76e05
MD5 171f79babce8387fd8da618d0ec16f72
BLAKE2b-256 1fe1ce678d62f0fbf617b5d5d1648de7654651dd072a9436bb8ed1cc2bdb7d76

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_auth-6.6.1-py3-none-any.whl:

Publisher: release.yml on E5presso/spakky-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page