Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ VITE_HTTPS_CERT_FILE= # required when VITE_ENABLE_HTTPS=true
VITE_HTTPS_KEY_FILE= # required when VITE_ENABLE_HTTPS=true
VITE_VERIFY_SSL=false # set true to verify the backend TLS certificate
VITE_USE_POLLING=false # set true when the filesystem does not emit file events reliably
VITE_MOCK_STORE_API=false # set true to serve mock secret and variable routes until SOARCA has them

########## Docker Compose (dev) ##########
# Values used by `docker-compose.dev.yml`. Compose will substitute ${VAR} from the
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ flowchart TB
- `VITE_HTTPS_CERT_FILE` - Path to the TLS certificate used by Vite
- `VITE_HTTPS_KEY_FILE` - Path to the TLS certificate key used by Vite
- `VITE_VERIFY_SSL` - Set to `true` to verify the backend certificate when Vite proxies API requests
- `VITE_MOCK_STORE_API` - Set to `true` for the Resources page's temporary secret and variable endpoints (see [Mock store API](#mock-store-api))
- `DOCKER_HOST_PORT` - The port of the host machine that is mapped to the `VITE_SERVER_PORT` of the Vite dev server running in the container. This is only relevant when running the Development Container.
- `HOST_PORT` - is the same of the `VITE_SERVER_PORT` if run locally or `DOCKER_HOST_PORT` if running the Development Container.

Expand Down Expand Up @@ -172,6 +173,24 @@ flowchart TB
```
The app will be available at `http://localhost:HOST_PORT` with hot-reload enabled.

#### Mock store API

The Resources page groups global variables and read-only secrets into two tabs.
SOARCA does not serve this API yet. Set `VITE_MOCK_STORE_API=true` to let the
development server answer these routes with in-memory seed data:

- `/api/secret/...`: read-only metadata and version history. Secret values are never returned.
- `/api/variable/...`: create, edit, delete and restore global variable versions.

All other `/api` requests still go to SOARCA. The flag also grants
`secret:read`, `variable:read` and `variable:write` to signed-in users because
SOARCA does not issue those permissions yet. The flag defaults to off, and the
mock is not served by preview or production builds. Data resets on server restart.

Playbook mappings, resolution and changes to execution inputs are not included
yet. How global, external and step variables work together still needs planning.
Existing playbook inputs keep their behavior.

### Enable sign-in

The GUI reads its login providers from `/auth-config.json`, a file you deploy
Expand Down
1 change: 1 addition & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:
- VITE_HTTPS_CERT_FILE=${VITE_HTTPS_CERT_FILE:-/app/certs/server.crt}
- VITE_HTTPS_KEY_FILE=${VITE_HTTPS_KEY_FILE:-/app/certs/server.key}
- VITE_VERIFY_SSL=${VITE_VERIFY_SSL:-false}
- VITE_MOCK_STORE_API=${VITE_MOCK_STORE_API:-false}
- VITE_IS_DOCKER=true
volumes:
- .:/app
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@radix-ui/react-scroll-area": "^1.4.0",
"@tabler/icons-react": "^3.49.0",
"@tanstack/react-query": "^5.108.4",
"@tanstack/react-table": "^8.21.3",
"@xyflow/react": "^12.12.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
10 changes: 10 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { PlaybookCreatePage } from "./pages/main-page/playbooks-page/PlaybookCre
import { PlaybookJsonEditPage } from "./pages/main-page/playbooks-page/PlaybookJsonEditPage";
import { PlaybooksPage } from "./pages/main-page/playbooks-page/PlaybooksPage";
import { PlaybookDetailPage } from "./pages/main-page/playbooks-page/playbook-detail-page/PlaybookDetailPage";
import { StorePage } from "./pages/main-page/store-pages/StorePage";
import { RESOURCE_TABS } from "./pages/main-page/store-pages/utils";
import { PATHS } from "./utils";

// The visual editor pulls in React Flow, so it is only loaded when opened.
Expand Down Expand Up @@ -116,6 +118,14 @@ function App() {
element={withSuspense(<PlaybookVisualEditPage />)}
/>
</Route>
{RESOURCE_TABS.map(({ path, permission }) => (
<Route
key={path}
element={<PermissionGate permission={permission} />}
>
<Route path={path} element={<StorePage />} />
</Route>
))}
</Route>
</Route>
<Route path="*" element={<Navigate to={PATHS.NOT_FOUND} replace />} />
Expand Down
64 changes: 64 additions & 0 deletions src/api/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type {
NewStoredVariable,
SecretBackend,
SecretMetadata,
SecretVersion,
StoredVariable,
StoredVariableVersion,
} from "@/types";
import {
deleteToApi,
fetchFromApi,
HttpMutationMethod,
mutationToApi,
} from "./utils";

const segment = (value: string) => encodeURIComponent(value);

export const getSecretBackend = () =>
fetchFromApi<SecretBackend>(`/api/secret/backend`);

export const getSecrets = () => fetchFromApi<SecretMetadata[]>(`/api/secret/`);

export const getSecretVersions = (secret: string) =>
fetchFromApi<SecretVersion[]>(`/api/secret/${segment(secret)}/versions`);

export const getVariables = () =>
fetchFromApi<StoredVariable[]>(`/api/variable/`);

export const getVariableVersions = (variable: string) =>
fetchFromApi<StoredVariableVersion[]>(
`/api/variable/${segment(variable)}/versions`,
);

export const createVariable = (variable: NewStoredVariable) =>
mutationToApi<StoredVariable>(
HttpMutationMethod.POST,
`/api/variable/`,
variable,
);

/** Writes a new version. `version` is the one the user saw; a stale one gives 409. */
export const updateVariableValue = (
variable: string,
version: number,
value: string,
) =>
mutationToApi<StoredVariable>(
HttpMutationMethod.PUT,
`/api/variable/${segment(variable)}`,
{ version, value },
);

export const updateVariableDescription = (
variable: string,
description: string,
) =>
mutationToApi<StoredVariable>(
HttpMutationMethod.PATCH,
`/api/variable/${segment(variable)}`,
{ description },
);

export const deleteVariable = (variable: string) =>
deleteToApi(`/api/variable/${segment(variable)}`);
28 changes: 28 additions & 0 deletions src/api/storeQueries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { queryOptions } from "@tanstack/react-query";

import {
getSecretBackend,
getSecrets,
getSecretVersions,
getVariables,
getVariableVersions,
} from "./store";

/** Every component that reads the store uses these, so keys and caching match. */
export const storeQueries = {
secretBackend: () =>
queryOptions({ queryKey: ["secret-backend"], queryFn: getSecretBackend }),
secrets: () => queryOptions({ queryKey: ["secrets"], queryFn: getSecrets }),
secretVersions: (secret: string) =>
queryOptions({
queryKey: ["secret", secret, "versions"],
queryFn: () => getSecretVersions(secret),
}),
variables: () =>
queryOptions({ queryKey: ["variables"], queryFn: getVariables }),
variableVersions: (variable: string) =>
queryOptions({
queryKey: ["variable", variable, "versions"],
queryFn: () => getVariableVersions(variable),
}),
};
6 changes: 5 additions & 1 deletion src/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import toast from "react-hot-toast";
import { redirectToLogin } from "@/api/utils";
import { AuthContext } from "@/auth/AuthContext";
import { beginSignOut, isSigningOut, resetSigningOut } from "@/auth/oidc";
import { MOCKED_PERMISSIONS } from "@/auth/permissions";
import { loadSession } from "@/auth/session";

export function AuthProvider({ children }: PropsWithChildren) {
Expand Down Expand Up @@ -50,7 +51,10 @@ export function AuthProvider({ children }: PropsWithChildren) {
isLoading: session.isLoading,
// Only the initial check blocks; a failed background refetch keeps the cached user.
isError: session.isLoadingError,
can: (permission) => user?.permissions.includes(permission) ?? false,
can: (permission) =>
!!user &&
(user.permissions.includes(permission) ||
MOCKED_PERMISSIONS.includes(permission)),
logout: () => {
if (isSigningOut()) return;
void beginSignOut().then(
Expand Down
16 changes: 16 additions & 0 deletions src/auth/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ export const Permissions = {
PlaybookRead: "playbook:read",
PlaybookWrite: "playbook:write",
PlaybookExecute: "playbook:execute",
SecretRead: "secret:read",
VariableRead: "variable:read",
VariableWrite: "variable:write",
} as const;

export type Permission = (typeof Permissions)[keyof typeof Permissions];

// SOARCA does not issue the store permissions yet. While the mock store API
// answers those routes, the GUI grants them to every signed-in user.
export const MOCKED_PERMISSIONS: readonly Permission[] =
import.meta.env.DEV &&
import.meta.env.MODE !== "test" &&
import.meta.env.VITE_MOCK_STORE_API === "true"
? [
Permissions.SecretRead,
Permissions.VariableRead,
Permissions.VariableWrite,
]
: [];
18 changes: 18 additions & 0 deletions src/cacaoResources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** CACAO 2.0 variable-type-ov values. */
export const VARIABLE_TYPES = [
"bool",
"dictionary",
"float",
"hexstring",
"integer",
"ipv4-addr",
"ipv6-addr",
"long",
"mac-addr",
"hash",
"md5-hash",
"sha256-hash",
"string",
"uri",
"uuid",
] as const;
1 change: 0 additions & 1 deletion src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const Frame = styled(ScrollArea)<{ $maxHeight?: string }>`
const Pre = styled.pre<{ $copyable?: boolean }>`
counter-reset: line;

margin: 0;
padding: ${({ theme }) => theme.spacing.sm} 0;
padding-right: ${({ $copyable }) => ($copyable ? "2.5rem" : 0)};

Expand Down
4 changes: 0 additions & 4 deletions src/components/Containers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,4 @@ export const HeaderActions = styled.div`
width: 15rem;
max-width: 100%;
}

> select {
width: 9rem;
}
`;
6 changes: 3 additions & 3 deletions src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from "react";
import toast from "react-hot-toast";

import { formatErrorForToast } from "@/api/utils";
import { Button } from "./Button";
import { Button, type ButtonProps } from "./Button";
import Icon from "./Icon";

export interface CopyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
export interface CopyButtonProps extends ButtonProps {
$value: string;
}

Expand All @@ -25,7 +25,7 @@ export const CopyButton: React.FC<CopyButtonProps> = ({
}) => {
const handleClick = async (e: React.MouseEvent) => {
e.stopPropagation();
if (disabled || !$value) return;
if (disabled) return;

try {
await navigator.clipboard.writeText($value);
Expand Down
Loading
Loading