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>
This commit is contained in:
39 files changed
+3094
-31
No files matched your search
+116
-4
@@ -5,6 +5,7 @@
|
||||
* Supports both SQLite and PostgreSQL.
|
||||
*/
|
||||
|
||||
import type { SecretProviderConfig, SecretProviderType } from './secretproviders/shared';
|
||||
import {
|
||||
db,
|
||||
isPostgres,
|
||||
@@ -39,6 +40,7 @@ import {
|
||||
gitCredentials,
|
||||
gitRepositories,
|
||||
gitStacks,
|
||||
secretProviders,
|
||||
stackSources,
|
||||
vulnerabilityScans,
|
||||
auditLogs,
|
||||
@@ -69,6 +71,7 @@ import {
|
||||
type GitCredential,
|
||||
type GitRepository,
|
||||
type GitStack,
|
||||
type SecretProviderRow,
|
||||
type StackSource,
|
||||
type VulnerabilityScan,
|
||||
type AuditLog,
|
||||
@@ -102,6 +105,7 @@ export type {
|
||||
GitCredential,
|
||||
GitRepository,
|
||||
GitStack,
|
||||
SecretProviderRow,
|
||||
StackSource,
|
||||
VulnerabilityScan,
|
||||
AuditLog,
|
||||
@@ -297,6 +301,107 @@ export async function setDefaultRegistry(id: number): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// SECRET PROVIDER OPERATIONS
|
||||
// =============================================================================
|
||||
// Pluggable secret providers (1Password, Infisical, HashiCorp Vault, ...). The
|
||||
// per-provider `config` object is stored as an encrypted JSON blob; the `token`
|
||||
// or `host`/`token` fields live inside it. See src/lib/server/secretproviders.
|
||||
|
||||
/** Row without the (secret) config, safe to return to the UI / list views. */
|
||||
export interface SecretProviderSummary {
|
||||
id: number;
|
||||
type: string;
|
||||
name: string;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
/** Row with its config decrypted and parsed. Server-side use only. */
|
||||
export interface SecretProviderWithConfig extends SecretProviderSummary {
|
||||
config: SecretProviderConfig;
|
||||
}
|
||||
|
||||
export async function getSecretProviders(): Promise<SecretProviderSummary[]> {
|
||||
const results = await db.select({
|
||||
id: secretProviders.id,
|
||||
type: secretProviders.type,
|
||||
name: secretProviders.name,
|
||||
createdAt: secretProviders.createdAt,
|
||||
updatedAt: secretProviders.updatedAt
|
||||
}).from(secretProviders).orderBy(asc(secretProviders.name));
|
||||
return results;
|
||||
}
|
||||
|
||||
export async function getSecretProviderById(id: number): Promise<SecretProviderWithConfig | undefined> {
|
||||
const results = await db.select().from(secretProviders).where(eq(secretProviders.id, id));
|
||||
if (!results[0]) return undefined;
|
||||
const row = results[0];
|
||||
const decrypted = decrypt(row.config);
|
||||
const config = decrypted
|
||||
? (JSON.parse(decrypted) as SecretProviderConfig)
|
||||
: ({} as SecretProviderConfig);
|
||||
return {
|
||||
id: row.id,
|
||||
type: row.type,
|
||||
name: row.name,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
config
|
||||
};
|
||||
}
|
||||
|
||||
export async function createSecretProvider(data: {
|
||||
type: SecretProviderType;
|
||||
name: string;
|
||||
config: SecretProviderConfig;
|
||||
}): Promise<SecretProviderSummary> {
|
||||
const encrypted = encrypt(JSON.stringify(data.config));
|
||||
if (!encrypted) throw new Error('Config is required');
|
||||
const result = await db.insert(secretProviders).values({
|
||||
type: data.type,
|
||||
name: data.name,
|
||||
config: encrypted
|
||||
}).returning();
|
||||
const { config: _omit, ...safe } = result[0];
|
||||
return safe;
|
||||
}
|
||||
|
||||
export async function updateSecretProvider(
|
||||
id: number,
|
||||
data: { name?: string; type?: SecretProviderType; config?: SecretProviderConfig }
|
||||
): Promise<SecretProviderSummary | undefined> {
|
||||
const updateData: Record<string, any> = { updatedAt: new Date().toISOString() };
|
||||
if (data.name !== undefined) updateData.name = data.name;
|
||||
if (data.type !== undefined) updateData.type = data.type;
|
||||
if (data.config !== undefined) {
|
||||
const encrypted = encrypt(JSON.stringify(data.config));
|
||||
if (encrypted) updateData.config = encrypted;
|
||||
}
|
||||
await db.update(secretProviders).set(updateData).where(eq(secretProviders.id, id));
|
||||
const results = await db.select({
|
||||
id: secretProviders.id,
|
||||
type: secretProviders.type,
|
||||
name: secretProviders.name,
|
||||
createdAt: secretProviders.createdAt,
|
||||
updatedAt: secretProviders.updatedAt
|
||||
}).from(secretProviders).where(eq(secretProviders.id, id));
|
||||
return results[0];
|
||||
}
|
||||
|
||||
export async function deleteSecretProvider(id: number): Promise<SecretProviderSummary | null> {
|
||||
const rows = await db.delete(secretProviders)
|
||||
.where(eq(secretProviders.id, id))
|
||||
.returning({
|
||||
id: secretProviders.id,
|
||||
type: secretProviders.type,
|
||||
name: secretProviders.name,
|
||||
createdAt: secretProviders.createdAt,
|
||||
updatedAt: secretProviders.updatedAt
|
||||
});
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// STACK EVENT LOGGING
|
||||
// =============================================================================
|
||||
@@ -1203,6 +1308,7 @@ export interface Permissions {
|
||||
audit_logs: string[];
|
||||
activity: string[];
|
||||
schedules: string[];
|
||||
secrets: string[];
|
||||
backups: string[];
|
||||
}
|
||||
|
||||
@@ -2797,6 +2903,7 @@ export interface StackSourceData {
|
||||
gitStackId: number | null;
|
||||
composePath: string | null;
|
||||
envPath: string | null;
|
||||
secretProviderId: number | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
@@ -2904,6 +3011,7 @@ export async function upsertStackSource(data: {
|
||||
gitStackId?: number | null;
|
||||
composePath?: string | null;
|
||||
envPath?: string | null;
|
||||
secretProviderId?: number | null;
|
||||
}): Promise<StackSourceData> {
|
||||
const existing = await getStackSource(data.stackName, data.environmentId);
|
||||
|
||||
@@ -2925,7 +3033,9 @@ export async function upsertStackSource(data: {
|
||||
gitStackId: newStackId,
|
||||
composePath: data.composePath ?? null,
|
||||
envPath: data.envPath ?? null,
|
||||
updatedAt: new Date().toISOString()
|
||||
updatedAt: new Date().toISOString(),
|
||||
// Preserve existing binding when caller (like git) omits it
|
||||
...(data.secretProviderId !== undefined && { secretProviderId: data.secretProviderId })
|
||||
})
|
||||
.where(eq(stackSources.id, existing.id));
|
||||
return getStackSource(data.stackName, data.environmentId) as Promise<StackSourceData>;
|
||||
@@ -2938,7 +3048,8 @@ export async function upsertStackSource(data: {
|
||||
gitRepositoryId: data.gitRepositoryId || null,
|
||||
gitStackId: data.gitStackId || null,
|
||||
composePath: data.composePath ?? null,
|
||||
envPath: data.envPath ?? null
|
||||
envPath: data.envPath ?? null,
|
||||
secretProviderId: data.secretProviderId ?? null
|
||||
});
|
||||
return getStackSource(data.stackName, data.environmentId) as Promise<StackSourceData>;
|
||||
}
|
||||
@@ -2947,7 +3058,7 @@ export async function upsertStackSource(data: {
|
||||
export async function updateStackSource(
|
||||
stackName: string,
|
||||
environmentId: number | null,
|
||||
updates: { composePath?: string | null; envPath?: string | null }
|
||||
updates: { composePath?: string | null; envPath?: string | null; secretProviderId?: number | null }
|
||||
): Promise<boolean> {
|
||||
const existing = await getStackSource(stackName, environmentId);
|
||||
if (!existing) return false;
|
||||
@@ -2956,6 +3067,7 @@ export async function updateStackSource(
|
||||
.set({
|
||||
composePath: updates.composePath !== undefined ? updates.composePath : existing.composePath,
|
||||
envPath: updates.envPath !== undefined ? updates.envPath : existing.envPath,
|
||||
secretProviderId: updates.secretProviderId !== undefined ? updates.secretProviderId : existing.secretProviderId,
|
||||
updatedAt: new Date().toISOString()
|
||||
})
|
||||
.where(eq(stackSources.id, existing.id));
|
||||
@@ -3304,7 +3416,7 @@ export type AuditEntityType =
|
||||
| 'container' | 'image' | 'stack' | 'volume' | 'network'
|
||||
| 'user' | 'role' | 'settings' | 'environment' | 'registry' | 'git_repository' | 'git_credential'
|
||||
| 'config_set' | 'notification' | 'oidc_provider' | 'ldap_config' | 'git_stack' | 'api_token'
|
||||
| 'backup_destination' | 'backup_config';
|
||||
| 'secret_provider' | 'backup_destination' | 'backup_config';
|
||||
|
||||
export interface AuditLogData {
|
||||
id: number;
|
||||
|
||||
Reference in new issue
Block a user