-
Notifications
You must be signed in to change notification settings - Fork 0
AuthSessionBroker: Make SessionMap optional and implement Name-based routing for AuthSessionName #153
Description
Problem Statement
Using authentication sessions with IdLE is currently confusing for users and error-prone in simple scenarios:
- Steps only request an auth session from
AuthSessionBrokerwhenWith.AuthSessionNameis set, effectively makingAuthSessionNamea hidden trigger rather than a routing key. AuthSessionNameis not meaningfully mapped toSessionMapentries (routing currently relies onAuthSessionOptionssuch asRole, if present, or falls back toDefaultAuthSession).- In common “single credential” scenarios, users should not be forced to define a
SessionMapat all;DefaultAuthSessionshould be sufficient. - This leads to confusing behavior (e.g., plan execution runs without the intended credential unless
AuthSessionNameis set) and makes first-time workflows unnecessarily hard.
Goal: Make auth session usage intuitive, deterministic, and ergonomic while remaining backward compatible.
Proposed Solution
1) Make SessionMap optional
Update New-IdleAuthSession / broker configuration so SessionMap can be omitted or empty.
- Allow:
-SessionMap $nullor no-SessionMapparameter. - Validation rules:
- If
SessionMapis empty/null andDefaultAuthSessionis not set: fail fast with a clear error. - If
DefaultAuthSessionis set:SessionMapis optional.
- If
2) Implement meaningful AuthSessionName routing (AuthSessionName-based mapping)
Extend session mapping keys to support AuthSessionName-based routing and make AuthSessionName a real selector:
-
Avoid generic key names like
Namein mapping keys; prefer explicitAuthSessionNameto reduce ambiguity. -
Allow
SessionMapkeys to includeAuthSessionNameand optional selectors (e.g.,AuthSessionRolevia existing keyRole):- Example key:
@{ AuthSessionName = 'AD'; Role = 'ADAdm' }# Role is the existing key; semantically this is the AuthSessionRole
- Example key:
Matching rules (deterministic):
- If
AuthSessionNameandAuthSessionOptionsare provided:- Match entries where
key.AuthSessionName == AuthSessionNameand all key/value pairs fromAuthSessionOptionsmatch.
- Match entries where
- If only
AuthSessionNameis provided:- Match entries where
key.AuthSessionName == AuthSessionName. - If multiple matches exist: fail fast with a clear ambiguity error (include which selectors are available).
- Match entries where
- If no match is found:
- Fall back to
DefaultAuthSessionif set.
- Fall back to
- If no match and no default:
- Fail fast with actionable error.
Backward compatibility:
- Existing
SessionMapkeys that do not includeAuthSessionNamemust continue to work. - If
AuthSessionNameis set but mappings are AuthSessionRole-only (legacy keys using onlyRole), use the existing behavior (Options-only match → default fallback).
3) Improve Step ergonomics (no “hidden trigger”)
Steps should not require With.AuthSessionName merely to use credentials if a broker with a default session exists.
Proposed behavior:
- If a step/provider supports auth sessions and an
AuthSessionBrokeris available:- If
With.AuthSessionNameis missing but the broker hasDefaultAuthSession, the step should still acquire the default session. With.AuthSessionNamebecomes optional and is only needed for selecting non-default sessions.
- If
4) Documentation + examples
Update documentation to clearly describe:
- When to use
DefaultAuthSessionvsSessionMap - How
AuthSessionNameandAuthSessionOptionsare used for routing - Common patterns:
- Single credential (no SessionMap)
- Multiple roles (ADAdm/ADRead)
- Multiple systems (AD/EXO) + roles
Alternatives Considered
-
Keep current behavior and only document the “AuthSessionName as trigger” requirement.
- Rejected: confusing user experience and easy to misconfigure.
-
Make
AuthSessionNamemandatory everywhere.- Rejected: adds unnecessary verbosity and does not solve routing semantics.
-
Introduce provider-specific auth routing (per provider).
- Rejected: should remain a core cross-provider capability.
Impact
-
Does this affect existing workflows?
- Intended to be backward compatible:
- Existing
SessionMapRole-only usage continues to work. - Workflows that currently set
AuthSessionNamekeep working.
- Existing
- Behavioral improvement: workflows may start using
DefaultAuthSessioneven ifAuthSessionNamewas omitted (desired ergonomic fix).
- Intended to be backward compatible:
-
Any backward compatibility concerns?
- Low risk if implemented with conservative matching and clear errors for ambiguous AuthSessionName-only matches.
- Add unit tests to lock in legacy behavior for Role-only maps.
Additional Context
Example: Single credential (no SessionMap)
$authSession = New-IdleAuthSession -AuthSessionType 'Credential' -DefaultAuthSession $admADWorkflow step (no auth fields required):
With = @{
IdentityKey = 'foo.bar'
Attributes = @{ Path = 'OU=...' }
}Example: AuthSessionName + AuthSessionRole routing
$authSession = New-IdleAuthSession -AuthSessionType 'Credential' -DefaultAuthSession $defaultCred -SessionMap @{
@{ AuthSessionName = 'AD'; Role = 'ADAdm' } = $admAD
@{ AuthSessionName = 'EXO'; Role = 'EXOAdm' } = $exoAdm
}Workflow:
With = @{
AuthSessionName = 'AD'
AuthSessionOptions = @{ Role = 'ADAdm' }
}Acceptance Criteria
SessionMapis optional whenDefaultAuthSessionis provided; clear error when neither is available.- AuthSessionName-based routing works:
- Exact match:
AuthSessionName+AuthSessionOptions - AuthSessionName-only match (unique) works; ambiguity produces a clear error.
- Exact match:
- Steps use
DefaultAuthSessioneven whenAuthSessionNameis not set (when broker is present). - Backward compatibility tests for Role-only maps.
- Documentation updated with patterns and examples.