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: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ 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, variable and mapping routes until SOARCA has them

########## Docker Compose (dev) ##########
# Values used by `docker-compose.dev.yml`. Compose will substitute ${VAR} from the
Expand Down
64 changes: 22 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ Firefox 119+, Safari 17.4+). API queries refetch stale data when the window
regains focus or the connection returns.

Scrollable pages, panels, modals and code blocks share the same thin scrollbars.
Side-panel tabs stay above the scrolling content. Native editors and text areas
keep their own scrollbars, with matching theme colors.
Side-panel tabs stay above the scrolling content. JSON editors also use the shared
Radix scroll area while retaining textarea editing and vertical resizing.
On narrow windows, the playbook workspace scrolls horizontally rather than
clipping its side panels. Each panel keeps its own vertical scrolling.

## Running the Project

Expand Down Expand Up @@ -121,7 +123,6 @@ 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 temporary resource and mapping 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 @@ -173,45 +174,24 @@ flowchart TB
```
The app will be available at `http://localhost:HOST_PORT` with hot-reload enabled.

#### Mock store API

The Resources page has tabs for stored variables, read-only secrets,
authentication and targets. The current SOARCA backend does not yet serve
these APIs. 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.
- `/api/cacao/authentication-info/...` and `/api/cacao/target/...`: manage versioned CACAO objects and their field mappings.
- `/api/playbook/{id}/mapping` and `/api/playbook/{id}/resolve`: map external playbook variables to stored secrets and variables, and check whether a run can resolve them. The mock reads the playbook from SOARCA to know its external variables.

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

Deleting a variable, target or authentication that is still in use shows
instructions to remove its mappings or references first. For these deletion
conflicts (HTTP 409), the dialog also shows the API's explanation, including
blocking references when provided. Other API errors keep their generic messages.

In the visual editor's Variables tab, the database-plus button adds an external
variable backed by a stored variable or secret. The plus button adds an
external declaration without a stored source. A row's database-plus button
changes its source. Mappings follow the latest resource version unless a
version is pinned. The playbook is saved first; if saving its mapping fails,
the editor keeps the draft for a retry.

The playbook Resources tab can add stored authentication and
targets, or create playbook-only objects. Adding a stored target also adds its
stored authentication when needed. The GUI copies the CACAO objects into the
playbook, but not their mappings or secret values.
Failed stored-resource checks show an error and a retry action. Adding a target
uses an existing playbook authentication copy only when the store returns 404,
not when access is denied or the request fails.
#### Resources preview

Resources shows read-only sample variables, secret metadata, authentication and
targets in both development and production builds. A notice identifies the data
as examples, not records from SOARCA. Search, filters, version history and detail
views work without resource API requests. The samples contain no real secrets.
All Resources sample data lives in
`src/pages/main-page/store-pages/sampleResources.ts`.

The page is available when sign-in is disabled, or to signed-in users with
`playbook:read`. This does not grant any resource API permissions.

Stored-resource selection and mappings in playbooks are disabled until SOARCA
supports their APIs. Disabled stored-resource buttons explain this limitation.
Manual external variables and playbook-local authentication
and targets continue to work. Sample data cannot be attached to a playbook or
sent to an execution. The former development mock API and its environment flag
have been removed.

### Enable sign-in

Expand Down
1 change: 0 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ 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
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function App() {
}
>
<Route
path={PATHS.PLAYBOOKS.UPLOAD}
path={PATHS.PLAYBOOKS.IMPORT}
element={<PlaybookCreatePage />}
/>
<Route
Expand Down Expand Up @@ -121,7 +121,9 @@ function App() {
{RESOURCE_TABS.map(({ path, permission }) => (
<Route
key={path}
element={<PermissionGate permission={permission} />}
element={
<PermissionGate permission={permission} allowAnonymous />
}
>
<Route path={path} element={<StorePage />} />
</Route>
Expand Down
12 changes: 9 additions & 3 deletions src/auth/AuthGate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ export function AuthGate() {
return <Outlet />;
}

export function PermissionGate({ permission }: { permission: Permission }) {
const { can } = useAuth();
if (can(permission)) return <Outlet />;
export function PermissionGate({
permission,
allowAnonymous = false,
}: {
permission: Permission;
allowAnonymous?: boolean;
}) {
const { can, user } = useAuth();
if (can(permission) || (allowAnonymous && user?.anonymous)) return <Outlet />;
return (
<CenteredCardContent>
<NotificationCard $variant={ThemeVariant.Error}>
Expand Down
6 changes: 1 addition & 5 deletions src/auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 @@ -56,10 +55,7 @@ export function AuthProvider({ children }: PropsWithChildren) {
isLoggingOut,
// Only the initial check blocks; a failed background refetch keeps the cached user.
isError: session.isLoadingError,
can: (permission) =>
!!user &&
(user.permissions.includes(permission) ||
MOCKED_PERMISSIONS.includes(permission)),
can: (permission) => !!user && user.permissions.includes(permission),
logout: () => {
if (isSigningOut()) return;
setIsLoggingOut(true);
Expand Down
24 changes: 4 additions & 20 deletions src/auth/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,7 @@ export const Permissions = {

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,
Permissions.AuthenticationInfoRead,
Permissions.AuthenticationInfoWrite,
Permissions.AuthenticationInfoUse,
Permissions.TargetRead,
Permissions.TargetWrite,
Permissions.TargetUse,
Permissions.MappingRead,
Permissions.MappingWrite,
]
: [];
// Resources are sample-only until SOARCA supports their APIs.
export const STORED_RESOURCES_AVAILABLE = false;
export const STORED_RESOURCES_UNAVAILABLE_MESSAGE =
"Stored resources are preview-only and cannot be used in playbooks until SOARCA supports them.";
102 changes: 83 additions & 19 deletions src/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import React from "react";
import React, { useLayoutEffect, useRef } from "react";
import styled from "styled-components";

import { ScrollArea } from "./ScrollArea";

const EditorContainer = styled.div`
width: 100%;
margin-bottom: ${({ theme }) => theme.spacing.lg};
`;

const EditorTextarea = styled.textarea<{
const EditorFrame = styled.div<{
$hasError?: boolean;
$minHeight?: string;
$readOnly?: boolean;
$disabled?: boolean;
}>`
resize: vertical;

overflow: hidden;
display: flex;
flex-direction: column;

width: 100%;
height: ${({ $minHeight = "400px" }) => $minHeight};
min-height: ${({ $minHeight = "400px" }) => $minHeight};
padding: ${({ theme }) => theme.spacing.md};
border: 2px solid
${({ theme, $hasError }) =>
$hasError ? theme.colors.error.border : theme.colors.border.medium};
Expand All @@ -25,23 +33,56 @@ const EditorTextarea = styled.textarea<{

background-color: ${({ theme }) => theme.colors.background.secondary};

&:focus {
&:focus-within {
border-color: ${({ theme, $hasError }) =>
$hasError ? theme.colors.error.border : theme.colors.info.border};
background-color: ${({ theme }) => theme.colors.background.primary};
outline: none;
background-color: ${({ theme, $readOnly }) =>
$readOnly
? theme.colors.background.secondary
: theme.colors.background.primary};
}

&:read-only:focus {
background-color: ${({ theme }) => theme.colors.background.secondary};
}
${({ theme, $disabled }) =>
$disabled &&
`
cursor: not-allowed;
opacity: ${theme.interactions.disabledOpacity};
`}
`;

const EditorScrollArea = styled(ScrollArea)`
flex: 1;
`;

const EditorTextarea = styled.textarea`
resize: none;

overflow: hidden;
flex: 1 0 auto;

width: 100%;
min-height: 0;
padding: ${({ theme }) => theme.spacing.md};
border: none;

font: inherit;

background: transparent;
outline: none;

&:disabled {
cursor: not-allowed;
opacity: ${({ theme }) => theme.interactions.disabledOpacity};
}
`;

const fitText = (textarea: HTMLTextAreaElement) => {
// Measure the text without the flex fill, so shortening it removes overflow.
textarea.style.flex = "none";
textarea.style.height = "0px";
textarea.style.height = `${textarea.scrollHeight}px`;
textarea.style.removeProperty("flex");
};

export interface CodeEditorProps extends React.HTMLAttributes<HTMLDivElement> {
$value: string;
$onChange?: (value: string) => void;
Expand Down Expand Up @@ -85,19 +126,42 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({
$inputId,
...rest
}) => {
const ref = useRef<HTMLTextAreaElement>(null);
useLayoutEffect(() => {
const textarea = ref.current;
if (!textarea) return;
fitText(textarea);
let width = textarea.clientWidth;
const observer = new ResizeObserver(() => {
if (textarea.clientWidth === width) return;
width = textarea.clientWidth;
fitText(textarea);
});
observer.observe(textarea);
return () => observer.disconnect();
}, [$value, placeholder]);

return (
<EditorContainer {...rest}>
<EditorTextarea
id={$inputId}
value={$value}
onChange={(e) => $onChange?.(e.target.value)}
placeholder={placeholder}
disabled={disabled}
readOnly={readOnly}
aria-required={$required || undefined}
<EditorFrame
$hasError={$hasError}
$minHeight={$minHeight}
/>
$readOnly={readOnly}
$disabled={disabled}
>
<EditorScrollArea verticalOnly fillHeight>
<EditorTextarea
ref={ref}
id={$inputId}
value={$value}
onChange={(e) => $onChange?.(e.target.value)}
placeholder={placeholder}
disabled={disabled}
readOnly={readOnly}
aria-required={$required || undefined}
/>
</EditorScrollArea>
</EditorFrame>
</EditorContainer>
);
};
Expand Down
Loading
Loading