Files
dockhand-upstream/src/routes/settings/+page.svelte
T
1ad36a83fb feat: Add pluggable secret providers (1Password, Infisical, HashiCorp Vault) (#1360)
* Add pluggable secret provider foundation

Introduces a provider-agnostic secret backend abstraction so stacks can
pull deploy-time secrets from 1Password, Infisical or HashiCorp Vault.

Providers implement the SecretProvider contract in secretproviders/shared.ts
and advertise which of the two resolution modes they support:

  - reference interpolation: a variable's value is an inline reference in
    the backend's own syntax (e.g. 1Password's op://vault/item/field)
  - bulk pull: every secret under a provider-defined selector, fetched as
    a flat key/value map

Adding a backend means dropping a file in secretproviders/ and registering
it in the index; no caller changes.

Four providers ship here: 1Password service account (references + bulk),
1Password Connect (references), Infisical (bulk) and HashiCorp Vault KV v2
(bulk). Provider config is persisted as an encrypted JSON blob in the new
secret_providers table, mirroring the existing notification_settings
type+config pattern, and stack_sources gains a nullable secret_provider_id.

Decrypted tokens stay in the provider modules for the duration of a call
and are never written to disk or returned to the client.

Co-authored-by: GooRoo <sergey.olendarenko@gmail.com>

* Add secret provider API routes and permissions

CRUD plus two test-connection endpoints under /api/secret-providers. The
unsaved variant validates a config posted from the provider form; the
stored variant tests a persisted provider by id.

Responses only ever carry provider summaries (id, type, name, timestamps).
The decrypted config never leaves the server.

Adds a "secrets" permission resource with view/create/edit/delete actions,
wired through the permission type, the role editor and the seeded roles,
and a secret_provider audit entity type so provider changes are logged.
Config rotations are audited as a boolean rather than a value.

* Resolve provider secrets at stack deploy time

Stacks can bind a secret provider; when one is bound, its secrets are
resolved and merged into the vars handed to docker compose.

Bulk pull is triggered by a selector variable: OP_ENVIRONMENT_ID, kept for
compatibility with the original 1Password integration, or the generic
DOCKHAND_SECRET_SELECTOR for any bulk-capable provider. The selector is
consumed by the provider and stripped before the vars reach the stack.
Values the bound provider recognises as inline references are resolved in
place, and references found only in the stack's .env file are promoted into
the secret set so they are never written back as literals.

Resolution is applied on deploy, on up, on recreate and on service update.
Explicitly configured secrets always win over bulk-pulled ones. A missing
or unsupported provider warns and leaves values untouched rather than
failing the deploy; a provider that errors mid-resolution fails it.

* Add secret provider settings UI and stack binding

A Secrets tab under settings lists configured providers and drives the
create/edit modal, which switches its fields on the selected provider type
and can test a connection before saving.

Both stack modals gain a provider selector so a stack can be bound to a
provider or left unbound. When a provider is bound, the bulk selector
variables are no longer reported as unused compose variables, since they
are consumed by the provider rather than the compose file.

---------

Co-authored-by: GooRoo <sergey.olendarenko@gmail.com>
Co-authored-by: Jarek Krochmalski <jotka@users.noreply.github.com>
2026-08-13 10:08:02 +02:00

154 lines
5.5 KiB
Svelte

<svelte:head>
<title>Settings - Dockhand</title>
</svelte:head>
<script lang="ts">
import { page } from '$app/stores';
import { goto } from '$app/navigation';
import * as Tabs from '$lib/components/ui/tabs';
import {
Settings,
Globe,
Download,
Layers,
Bell,
Crown,
Users,
Info,
GitBranch,
Tags,
KeyRound,
Archive
} from 'lucide-svelte';
import PageHeader from '$lib/components/PageHeader.svelte';
// Import tab components
import GeneralTab from './general/GeneralTab.svelte';
import EnvironmentsTab from './environments/EnvironmentsTab.svelte';
import LabelsTab from './labels/LabelsTab.svelte';
import RegistriesTab from './registries/RegistriesTab.svelte';
import GitTab from './git/GitTab.svelte';
import SecretsTab from './secrets/SecretsTab.svelte';
import ConfigSetsTab from './config-sets/ConfigSetsTab.svelte';
import NotificationsTab from './notifications/NotificationsTab.svelte';
import BackupsTab from './backups/BackupsTab.svelte';
import AuthTab from './auth/AuthTab.svelte';
import LicenseTab from './license/LicenseTab.svelte';
import AboutTab from './about/AboutTab.svelte';
// Tab state from URL
let activeTab = $derived($page.url.searchParams.get('tab') || 'general');
let editEnvId = $derived($page.url.searchParams.get('edit'));
let newEnv = $derived($page.url.searchParams.get('new') === 'true');
function handleTabChange(tab: string) {
goto(`/settings?tab=${tab}`, { replaceState: true, noScroll: true });
}
</script>
<div class="flex-1 min-h-0 flex flex-col gap-3 overflow-hidden">
<div class="shrink-0 flex flex-wrap justify-between items-center gap-3 min-h-8">
<PageHeader icon={Settings} title="Settings" showConnection={false} />
</div>
<Tabs.Root value={activeTab} onValueChange={handleTabChange} class="w-full flex-1 min-h-0 flex flex-col">
<Tabs.List class="w-full flex flex-wrap h-auto gap-1 p-1">
<Tabs.Trigger value="general" class="flex-1 flex items-center justify-center gap-1.5">
<Settings class="w-4 h-4" />
General
</Tabs.Trigger>
<Tabs.Trigger value="environments" class="flex-1 flex items-center justify-center gap-1.5">
<Globe class="w-4 h-4" />
Environments
</Tabs.Trigger>
<Tabs.Trigger value="labels" class="flex-1 flex items-center justify-center gap-1.5">
<Tags class="w-4 h-4" />
Labels
</Tabs.Trigger>
<Tabs.Trigger value="registries" class="flex-1 flex items-center justify-center gap-1.5">
<Download class="w-4 h-4" />
Registries
</Tabs.Trigger>
<Tabs.Trigger value="git" class="flex-1 flex items-center justify-center gap-1.5">
<GitBranch class="w-4 h-4" />
Git
</Tabs.Trigger>
<Tabs.Trigger value="secrets" class="flex-1 flex items-center justify-center gap-1.5">
<KeyRound class="w-4 h-4" />
Secrets
</Tabs.Trigger>
<Tabs.Trigger value="config-sets" class="flex-1 flex items-center justify-center gap-1.5">
<Layers class="w-4 h-4" />
Config sets
</Tabs.Trigger>
<Tabs.Trigger value="notifications" class="flex-1 flex items-center justify-center gap-1.5">
<Bell class="w-4 h-4" />
Notifications
</Tabs.Trigger>
<!-- BETA GATE: Backups tab hidden unless FEAT_BACKUPS_ENABLED (see features.ts) -->
{#if $page.data.backupsEnabled}
<Tabs.Trigger value="backups" class="flex-1 flex items-center justify-center gap-1.5">
<Archive class="w-4 h-4" />
Backups
</Tabs.Trigger>
{/if}
<Tabs.Trigger value="auth" class="flex-1 flex items-center justify-center gap-1.5">
<Users class="w-4 h-4" />
Authentication
</Tabs.Trigger>
<Tabs.Trigger value="license" class="flex-1 flex items-center justify-center gap-1.5">
<Crown class="w-4 h-4" />
License
</Tabs.Trigger>
<Tabs.Trigger value="about" class="flex-1 flex items-center justify-center gap-1.5">
<Info class="w-4 h-4" />
About
</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="general" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'general'}<GeneralTab />{/if}
</Tabs.Content>
<Tabs.Content value="environments" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'environments'}<EnvironmentsTab {editEnvId} {newEnv} />{/if}
</Tabs.Content>
<Tabs.Content value="labels" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'labels'}<LabelsTab />{/if}
</Tabs.Content>
<Tabs.Content value="registries" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'registries'}<RegistriesTab />{/if}
</Tabs.Content>
<Tabs.Content value="git" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'git'}<GitTab />{/if}
</Tabs.Content>
<Tabs.Content value="config-sets" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'config-sets'}<ConfigSetsTab />{/if}
</Tabs.Content>
<Tabs.Content value="notifications" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'notifications'}<NotificationsTab />{/if}
</Tabs.Content>
<Tabs.Content value="backups" class="flex-1 min-h-0 overflow-y-auto">
{#if activeTab === 'backups'}<BackupsTab />{/if}
</Tabs.Content>
<Tabs.Content value="auth" class="flex-1 min-h-0 flex flex-col">
{#if activeTab === 'auth'}<AuthTab onTabChange={handleTabChange} />{/if}
</Tabs.Content>
<Tabs.Content value="license" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'license'}<LicenseTab />{/if}
</Tabs.Content>
<Tabs.Content value="about" class="flex-1 min-h-0 overflow-y-auto pr-5">
{#if activeTab === 'about'}<AboutTab />{/if}
</Tabs.Content>
</Tabs.Root>
</div>