feat(access): edit org, workspace and object policies from the dashboard; refuse owner lockout
This commit is contained in:
1 parent
d53c20d209
commit
72f1f30f78
20 files changed
+626
-75
No files matched your search
@@ -140,6 +140,11 @@ async function request<T = unknown>(
|
||||
export const api = {
|
||||
health: <T = unknown>() => request<T>("/health/detailed"),
|
||||
services: <T = unknown>() => request<T>("/api/services"),
|
||||
policies: <T = unknown>() => request<T>("/api/access/policies"),
|
||||
putPolicy: (policy: unknown) =>
|
||||
request<{ version: number }>("/api/access/policies", { method: "PUT", body: policy }),
|
||||
deletePolicy: (policy: unknown) =>
|
||||
request<void>("/api/access/policies", { method: "DELETE", body: policy, parse: false }),
|
||||
summary: <T = unknown>() => request<T>("/api/summary"),
|
||||
tasks: <T = unknown>() => request<T>("/api/tasks"),
|
||||
taskMeta: <T = unknown>() => request<T>("/api/task-meta"),
|
||||
|
||||
@@ -43,6 +43,7 @@ const settings: NavSpec = {
|
||||
"/settings/channels",
|
||||
"/settings/repositories",
|
||||
"/settings/identities",
|
||||
"/settings/access-policies",
|
||||
"/settings/tools",
|
||||
"/settings/extensions",
|
||||
"/settings/plugins",
|
||||
|
||||
@@ -16,6 +16,7 @@ import PluginsPage from "@/settings/PluginsPage.vue";
|
||||
import ContainerRuntimePage from "@/settings/ContainerRuntimePage.vue";
|
||||
import SystemAdvancedPage from "@/settings/SystemAdvancedPage.vue";
|
||||
import SystemIdentitiesPage from "@/settings/SystemIdentitiesPage.vue";
|
||||
import AccessPoliciesPage from "@/settings/AccessPoliciesPage.vue";
|
||||
import SystemAppearancePage from "@/settings/SystemAppearancePage.vue";
|
||||
import SystemModelsPage from "@/settings/SystemModelsPage.vue";
|
||||
import SystemReposPage from "@/settings/SystemReposPage.vue";
|
||||
@@ -188,6 +189,18 @@ const routes = [
|
||||
section: "settings",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/settings/access-policies",
|
||||
name: "access-policies",
|
||||
component: AccessPoliciesPage,
|
||||
meta: {
|
||||
navPath: "/settings",
|
||||
settings: true,
|
||||
label: "Access policies",
|
||||
description: "Who may do what, written as Cedar policies.",
|
||||
section: "settings",
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/settings/channels",
|
||||
name: "channels",
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { api } from "@/lib/api";
|
||||
|
||||
type Level = "org" | "workspace" | "object";
|
||||
|
||||
interface Policy {
|
||||
id: string;
|
||||
level: Level;
|
||||
org_id?: string;
|
||||
workspace_id?: string;
|
||||
object_kind?: string;
|
||||
object_id?: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const policies = ref<Policy[]>([]);
|
||||
const shipped = ref<string[]>([]);
|
||||
const error = ref<string | null>(null);
|
||||
const saving = ref(false);
|
||||
|
||||
const blank = (): Policy => ({ id: "", level: "org", text: "" });
|
||||
const draft = ref<Policy>(blank());
|
||||
const editing = ref(false);
|
||||
|
||||
const scope = (p: Policy) =>
|
||||
p.level === "workspace"
|
||||
? p.workspace_id
|
||||
: p.level === "object"
|
||||
? `${p.object_kind}/${p.object_id}`
|
||||
: "";
|
||||
|
||||
const canSave = computed(
|
||||
() =>
|
||||
draft.value.id.trim() !== "" &&
|
||||
draft.value.text.trim() !== "" &&
|
||||
(draft.value.level !== "workspace" || !!draft.value.workspace_id) &&
|
||||
(draft.value.level !== "object" ||
|
||||
(!!draft.value.object_kind && !!draft.value.object_id)),
|
||||
);
|
||||
|
||||
async function load(): Promise<void> {
|
||||
try {
|
||||
const response = await api.policies<{ policies: Policy[]; shipped: string[] }>();
|
||||
policies.value = response.policies;
|
||||
shipped.value = response.shipped;
|
||||
error.value = null;
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message;
|
||||
}
|
||||
}
|
||||
|
||||
function edit(p: Policy): void {
|
||||
draft.value = { ...p };
|
||||
editing.value = true;
|
||||
}
|
||||
|
||||
async function save(): Promise<void> {
|
||||
saving.value = true;
|
||||
try {
|
||||
await api.putPolicy(draft.value);
|
||||
draft.value = blank();
|
||||
editing.value = false;
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(p: Policy): Promise<void> {
|
||||
try {
|
||||
await api.deletePolicy(p);
|
||||
await load();
|
||||
} catch (err) {
|
||||
error.value = (err as Error).message;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Access policies" />
|
||||
|
||||
<p v-if="error" class="mb-4 text-sm text-destructive">{{ error }}</p>
|
||||
|
||||
<Card class="mb-4">
|
||||
<CardHeader>
|
||||
<CardTitle>Policies</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<div
|
||||
v-for="p in policies"
|
||||
:key="`${p.level}/${scope(p)}/${p.id}`"
|
||||
class="flex items-start justify-between gap-4 border-b pb-3 last:border-0"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<span class="font-mono font-medium">{{ p.id }}</span>
|
||||
<Badge variant="default">{{ p.level }}</Badge>
|
||||
<span v-if="scope(p)" class="font-mono text-fg-muted">{{ scope(p) }}</span>
|
||||
<Badge v-if="shipped.includes(p.id)" variant="ok">shipped</Badge>
|
||||
</div>
|
||||
<pre class="mt-1 overflow-x-auto text-xs text-fg-muted">{{ p.text }}</pre>
|
||||
</div>
|
||||
<div class="flex shrink-0 gap-2">
|
||||
<Button size="sm" variant="outline" @click="edit(p)">Edit</Button>
|
||||
<Button size="sm" variant="outline" @click="remove(p)">Delete</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button v-if="!editing" class="self-start" @click="editing = true">New policy</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card v-if="editing">
|
||||
<CardHeader>
|
||||
<CardTitle>{{ draft.id ? draft.id : "New policy" }}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-3">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Input v-model="draft.id" placeholder="policy id" class="w-56" />
|
||||
<Select v-model="draft.level">
|
||||
<SelectTrigger class="w-40"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="org">org</SelectItem>
|
||||
<SelectItem value="workspace">workspace</SelectItem>
|
||||
<SelectItem value="object">object</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-if="draft.level === 'workspace'"
|
||||
v-model="draft.workspace_id"
|
||||
placeholder="workspace id"
|
||||
class="w-48"
|
||||
/>
|
||||
<template v-if="draft.level === 'object'">
|
||||
<Input v-model="draft.object_kind" placeholder="kind (secret, source...)" class="w-48" />
|
||||
<Input v-model="draft.object_id" placeholder="object id" class="w-48" />
|
||||
</template>
|
||||
</div>
|
||||
<Textarea
|
||||
v-model="draft.text"
|
||||
class="min-h-40 font-mono text-xs"
|
||||
placeholder='permit(principal, action == Archie::Action::"read", resource);'
|
||||
/>
|
||||
<div class="flex gap-2">
|
||||
<Button :disabled="!canSave || saving" @click="save">Save</Button>
|
||||
<Button variant="outline" @click="(editing = false), (draft = blank())">Cancel</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user