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
@@ -0,0 +1,87 @@
|
||||
namespace DodoSSH.Client.Storage.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// The Spelunks this device is signed in to: one sign-in per Spelunk, sealed whole, and gone with the cache.
|
||||
/// </summary>
|
||||
public sealed class SpelunkSignInStoreTests
|
||||
{
|
||||
private const string Spelunk = "https://api.spelunk.example.com";
|
||||
|
||||
private static CancellationToken Token => TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public async Task ASignInRoundTrips_AndIsFoundByItsSpelunk()
|
||||
{
|
||||
using var harness = await CacheHarness.CreateAsync();
|
||||
var store = Store(harness);
|
||||
|
||||
(await store.FindAsync(Spelunk, Token)).ShouldBeNull("nothing is signed in yet");
|
||||
|
||||
var signIn = SignIn(Spelunk, "spelunkapp_one");
|
||||
await store.SaveAsync(signIn, Token);
|
||||
|
||||
(await store.FindAsync(Spelunk, Token)).ShouldBe(signIn);
|
||||
(await store.FindAsync("https://spelunk.elsewhere.example", Token)).ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SigningInAgainToTheSameSpelunk_Replaces_AndOthersStay()
|
||||
{
|
||||
using var harness = await CacheHarness.CreateAsync();
|
||||
var store = Store(harness);
|
||||
|
||||
await store.SaveAsync(SignIn(Spelunk, "spelunkapp_old"), Token);
|
||||
await store.SaveAsync(SignIn("https://spelunk.elsewhere.example", "spelunkapp_other"), Token);
|
||||
await store.SaveAsync(SignIn(Spelunk, "spelunkapp_new"), Token);
|
||||
|
||||
var all = await store.ListAsync(Token);
|
||||
all.Count.ShouldBe(2);
|
||||
(await store.FindAsync(Spelunk, Token)).ShouldNotBeNull().Token.ShouldBe("spelunkapp_new");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ForgettingOne_LeavesTheOthers_AndForgettingAll_LeavesNone()
|
||||
{
|
||||
using var harness = await CacheHarness.CreateAsync();
|
||||
var store = Store(harness);
|
||||
|
||||
await store.SaveAsync(SignIn(Spelunk, "spelunkapp_one"), Token);
|
||||
await store.SaveAsync(SignIn("https://spelunk.elsewhere.example", "spelunkapp_two"), Token);
|
||||
|
||||
await store.ForgetAsync(Spelunk, Token);
|
||||
(await store.ListAsync(Token)).ShouldHaveSingleItem().ApiBase.ShouldBe("https://spelunk.elsewhere.example");
|
||||
|
||||
await store.ForgetAllAsync(Token);
|
||||
(await store.ListAsync(Token)).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AnotherUsersCacheKey_OpensNothing()
|
||||
{
|
||||
using var owner = await CacheHarness.CreateAsync();
|
||||
using var stranger = await CacheHarness.CreateAsync();
|
||||
|
||||
await Store(owner).SaveAsync(SignIn(Spelunk, "spelunkapp_one"), Token);
|
||||
|
||||
(await new SpelunkSignInStore(owner.Factory, stranger.Protector, TimeProvider.System).ListAsync(Token))
|
||||
.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResettingTheCache_SignsThisDeviceOutOfEverySpelunk()
|
||||
{
|
||||
// What signing out of DodoSSH does on disk, whatever reached Spelunk before it.
|
||||
using var harness = await CacheHarness.CreateAsync();
|
||||
|
||||
await Store(harness).SaveAsync(SignIn(Spelunk, "spelunkapp_one"), Token);
|
||||
await harness.Factory.ResetAsync(Token);
|
||||
|
||||
(await Store(harness).ListAsync(Token)).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
private static SpelunkSignInStore Store(CacheHarness harness) =>
|
||||
new(harness.Factory, harness.Protector, TimeProvider.System);
|
||||
|
||||
private static SpelunkSignInRecord SignIn(string apiBase, string token) =>
|
||||
new(apiBase, token, Guid.CreateVersion7(), "ops@example.com", "Ops", DateTimeOffset.FromUnixTimeSeconds(1_790_000_000));
|
||||
}
|
||||
Reference in new issue
Block a user