Public Access
Spelunk: sign each device in through the browser instead of keeping Spelunk API keys in the vault
A Spelunk API key reaches one organisation, so a server elsewhere - oc-linux in Orange Climate - was refused before it reached the agent. Each device now signs in to a Spelunk once, under Settings -> Security -> Spelunk or from a Spelunk host's editor: the OAuth authorization code flow with PKCE for a native app (RFC 8252), with Spelunk as the authorization server. The browser opens Spelunk's /api/app-sign-in/authorize with a loopback redirect (the app's own scheme on Android), the person signs in there however they normally do and allows "DodoSSH on <device>", and the code is redeemed at /api/app-sign-in/token for an app session token. That token opens terminals in every organisation its person is in, with the role they have on each server at the time; tunnel tickets send no organisation. The sign-in stays on the device: sealed in the local cache under the LocalCacheKey (AAD resource type 18, bound to its row), never synced, wiped with the cache, and only ever sent to the Spelunk it came from. A 401 from Spelunk forgets it; SIGN OUT ends it there and here, and so does signing out of DodoSSH. Before every Spelunk connection DodoSSH asks its own identity provider whether its sign-in still stands (a forced refresh, at most once a minute), and an account it refuses is signed out of DodoSSH and of every Spelunk on the device. A route names no key any more: Spelunk hosts are written at host schema 11, which an older build shows read-only and asks to be updated for, and a payload that still names a key credential decodes with the id skipped. The SpelunkKey item type is gone: SyncEntityType 14, ChangeEntityType 14 and AAD type 17 are retired, the server drops spelunk_key and its change-log rows, and the client cache drops its cached items, outbox entries and conflicts of that type. A link still never starts a sign-in: from a Spelunk this device is not signed in to it opens the editor, which offers to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
902761d37b
commit
ef365f462e
62 files changed
+4327
-1945
No files matched your search
@@ -40,6 +40,7 @@ internal sealed class RefreshingAccessTokenProvider(
|
||||
{
|
||||
private readonly SemaphoreSlim gate = new(1, 1);
|
||||
private TokenSet tokens = initial;
|
||||
private DateTimeOffset lastRefreshedAt = DateTimeOffset.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// The refresh token this provider currently holds, or null when none was granted.
|
||||
@@ -82,6 +83,7 @@ internal sealed class RefreshingAccessTokenProvider(
|
||||
.ConfigureAwait(false);
|
||||
|
||||
Volatile.Write(ref tokens, refreshed);
|
||||
lastRefreshedAt = clock.GetUtcNow();
|
||||
|
||||
return refreshed.AccessToken;
|
||||
}
|
||||
@@ -91,6 +93,44 @@ internal sealed class RefreshingAccessTokenProvider(
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refreshes now, whatever the expiry says, unless that was done within <paramref name="within"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The refresh grant is the one question the identity provider answers about whether a sign-in still
|
||||
/// stands: a disabled account, a revoked session or a removed user gets <c>invalid_grant</c> here, where
|
||||
/// an access token already issued would go on being accepted until it expired. Under the same lock as the
|
||||
/// ordinary refresh, so the two cannot spend one rotating refresh token twice.
|
||||
/// </remarks>
|
||||
/// <exception cref="OidcException">The provider refused, or could not be asked.</exception>
|
||||
internal async Task RefreshNowAsync(TimeSpan within, CancellationToken cancellationToken)
|
||||
{
|
||||
await gate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
var now = clock.GetUtcNow();
|
||||
if (now - lastRefreshedAt < within)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var current = Volatile.Read(ref tokens);
|
||||
if (current.RefreshToken is null)
|
||||
{
|
||||
throw new OidcException("This sign-in has no refresh token, so it cannot be checked. Sign in again.", "invalid_grant");
|
||||
}
|
||||
|
||||
var refreshed = await oidc.RefreshAsync(current.RefreshToken, cancellationToken).ConfigureAwait(false);
|
||||
Volatile.Write(ref tokens, refreshed);
|
||||
lastRefreshedAt = now;
|
||||
}
|
||||
finally
|
||||
{
|
||||
gate.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose() => gate.Dispose();
|
||||
}
|
||||
|
||||
@@ -161,6 +201,19 @@ public interface IVaultServer : IDisposable
|
||||
/// </remarks>
|
||||
IVaultEventStream Events { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Asks the identity provider, now, whether this sign-in still stands — at most once a minute.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For what must not go on working for a person the account has lost: connecting through Spelunk asks
|
||||
/// before every tunnel, so a removed or disabled account stops it within a minute rather than when an
|
||||
/// access token happens to expire. A stand-in server answers yes, which is why this has a body.
|
||||
/// </remarks>
|
||||
/// <exception cref="DodoSSH.Client.Auth.OidcException">
|
||||
/// The provider refused (<c>invalid_grant</c>), or could not be asked.
|
||||
/// </exception>
|
||||
Task VerifySignInAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Reaches a host through the server, for a host set to connect that way.
|
||||
/// </summary>
|
||||
@@ -261,6 +314,10 @@ public sealed class ServerConnection : IVaultServer
|
||||
/// <inheritdoc />
|
||||
public IAccountApi Account => Api;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task VerifySignInAsync(CancellationToken cancellationToken) =>
|
||||
tokens.RefreshNowAsync(TimeSpan.FromMinutes(1), cancellationToken);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ISyncApi Sync => Api;
|
||||
|
||||
|
||||
Reference in new issue
Block a user