Repository navigation
Feat: credential and auth model (tokens, proxy, delagation) - #30
Draft
Alexander-Auer wants to merge 36 commits into
Draft
Alexander-Auer wants to merge 36 commits into
Alexander-Auer wants to merge 36 commits into
Conversation
… have them link to each other
…ede into feat/core-contract
…a consumer should choose to use it or not
* feat: Models the core contract needs * Feat: Protocols and Exceptions added for the core contract * Feat: Private protocols for the BatchBackend * feat: a fake backend to run unit tests against * fix: some code cleanup in the helper functions * feat: setup for the unit test suite * chore: style fix * chore: styling, unit test fixture * chore: single letter var `h` refering to hanlde changed to `handle` * fix: unused parameter in `test_injected_failure_is_reported_per_job()` removed * feat: Models the core contract needs * Feat: Protocols and Exceptions added for the core contract * Feat: Private protocols for the BatchBackend * feat: a fake backend to run unit tests against * fix: some code cleanup in the helper functions * feat: setup for the unit test suite * chore: style fix * chore: styling, unit test fixture * chore: single letter var `h` refering to hanlde changed to `handle` * fix: unused parameter in `test_injected_failure_is_reported_per_job()` removed * fix: made the OutputSpec optional as it is not suppoerted by all and a consumer should choose to use it or not --------- Co-authored-by: alexander <alexander.auer@cern.ch>
…d of a hash of the full object
Add BackendConfig, one flat public model a consumer uses to describe any backend (kind, transport, scheduler, endpoint, host, ...). It is resolved internally into the settings of exactly one backend family, so a field that does not apply to the chosen kind is refused by name instead of ignored. Add the registry: registry.backend(config) builds the backend a configuration describes, from closed name -> "module:Class" tables. Entries are imported lazily and every built object is checked against its protocol, so a broken entry fails at resolution with a RegistryError. Part of DIRACGrid#18. Co-authored-by: alexander <alexander.auer@cern.ch>
Cover every field against every backend kind, every fake-backend operation against every job state, and the remaining registry and model paths. Add pytest-cov with branch coverage, measured in subprocesses too. Co-authored-by: alexander <alexander.auer@cern.ch>
Add intercede.auth (IC-ADR-003): typed, immutable credentials with secret fields, CredentialSet, CredentialRequirements, the CredentialProvider protocol and a StaticCredentials provider. Backend settings compute their requirements from the configured auth mode, the registry takes the consumer's provider and passes it to the parts that authenticate, and an internal freshness check asks the provider again only when credentials are missing or about to expire. Provider failures are whole-operation AuthenticationErrors. registry.backend() now requires the credential provider. Part of DIRACGrid#17. Co-authored-by: alexander <alexander.auer@cern.ch>
This branch has not been deployed
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.
feat: credential models and provider-based supply
Part of #17.
Important
**Depends on #29 . Merge after #29 ** (PR 4 of 4; the full order is listed in #27).
Until #TESTS is merged, this diff also shows the earlier PRs. This PR's own change is one commit:
0338aa2Implements IC-ADR-003: typed credentials, requirements computed by the backend, and supply through a provider the consumer owns.
intercede.auth(public)Credential,BearerToken,X509Proxy,SSHPrivateKey,SSHPassword.SecretStrorSecretBytes, so it never appears inrepr,stror JSON.expires_atmust carry a timezone, since it is compared with the current time.CredentialSet: built asCredentialSet([token, proxy]), with at most one credential per kind.get(BearerToken)is typed asBearerToken | None. Plain dicts are refused:{"value": ...}would fit both a token and a password, and guessing the kind of a secret is never right.CredentialRequirements:resource, thekindsneeded together, and per-operationscopes. Only concrete credential kinds are accepted, and there must be at least one.CredentialProvider: a@runtime_checkableprotocol withasync get(requirements), and an async context manager that the consumer opens and closes.StaticCredentials: the trivial provider of ADR-003 §8 (b), for standalone use, tests and the integration stacks. Each backend receives only the kinds it asked for.From configuration to requirements (internal)
The settings of each backend compute their requirements from the
authmode already present inBackendConfig:resourcearc/htcondor-ce,auth = ["token"](default)BearerTokenauth = ["token", "proxy"]BearerToken+X509Proxybatch+ssh,auth = ["key"](default) /["password"]SSHPrivateKey/SSHPassworduser@host:portbatch+ssh,auth = ["agent"], orbatch+localAs ADR-003 §2 requires, the requirements are never a public attribute of a backend.
The registry passes the provider on
registry.backend(config, credentials)now takes the consumer's provider. Anything that is not a provider raisesConfigurationError, and the configuration is still validated first.from_settings(settings, credentials). Schedulers do not, since they only build commands.Freshness (internal,
_backends/credentials.py)is_stale()is true when there is no set yet, a required kind is missing, or a required credential expires within the margin (DEFAULT_MARGIN = 5 minutes). Kinds the backend did not ask for are ignored.refresh_if_stale()keeps a fresh set without calling the provider, and otherwise asks once.Every way a provider can fail becomes an
AuthenticationError, a whole-operation failure and never a per-job one:CredentialSet;Typed errors from the provider and task cancellation pass through unchanged.
No backend calls this yet. The first real ARC or SSH backend calls
refresh_if_stale()before each operation.Breaking change
registry.backend(config)→registry.backend(config, credentials). Nothing has been released yet.Open points for review
CloudSettingshas no requirements yet, because ADR-003 defines no credential type for cloud API keys.resourceformat:user@host:portwas chosen so that a provider can tell several users on the same host apart.Tests
tests/unit/test_auth.py: every credential kind, expiry,CredentialSet,CredentialRequirements, the provider protocol,StaticCredentials, and the public APItests/unit/test_credentials.py: the margin boundaries and every provider failuretests/unit/test_config.py: requirements for every auth modetests/unit/test_registry.py: the provider check, which parts receive it, and that building never asks it643 tests pass on Python 3.11 and 3.13, with 100% line and branch coverage, and pre-commit passes.