Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .specify/feature.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"feature_directory": "specs/041-agent-turn-indicators"
"feature_directory": "specs/042-audit-access-holes"
}
10 changes: 5 additions & 5 deletions admin/slices/setup/api/data/repositories/api/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ export class FilesService {
}

/**
* List files for an agent. Each node says whether it is text or binary and whether it can be edited in place.
* List files for an agent. Each node says whether it is text or binary and whether it can be edited in place. Files that hold stored secrets (data/secrets/, data/channels/, data/channels.json, browser-state/) are write-only and never listed; reading, writing or deleting one answers 403.
*/
public static fileControllerList<ThrowOnError extends boolean = false>(
options: Options<FileControllerListData, ThrowOnError>,
Expand Down Expand Up @@ -1721,7 +1721,7 @@ export class FilesService {
}

/**
* Download a ZIP archive of the agent’s entire S3 prefix (files, skills, runtime state). Used as a safety net before destructive actions.
* Download a ZIP archive of the agent’s entire S3 prefix (files, skills, runtime state). Used as a safety net before destructive actions. Stored secrets are write-only and not exported; when any were left out the archive holds SECRET_STORES_NOT_EXPORTED.txt.
*/
public static exportAgentFiles<ThrowOnError extends boolean = false>(
options: Options<ExportAgentFilesData, ThrowOnError>,
Expand Down Expand Up @@ -1777,7 +1777,7 @@ export class FilesService {
}

/**
* Stream the raw stored file for an open link. 401 when the token is invalid, expired or minted for another agent; 404 (plain text) when the file is gone.
* Stream the raw stored file for an open link. 401 when the token is invalid, expired or minted for another agent; 404 (plain text) when the file is gone; 403 for a file that holds stored secrets, which are write-only.
*/
public static readAgentFileRaw<ThrowOnError extends boolean = false>(
options: Options<ReadAgentFileRawData, ThrowOnError>,
Expand Down Expand Up @@ -3149,7 +3149,7 @@ export class UsersService {
}

/**
* Create a user (admin sets the password)
* Create a user (admin sets the password). An Admin whose agent access is limited creates an account limited the same way: it gets a copy of the creator’s lists, and only the Owner can widen it (`agentAccess` says what it reaches).
*/
public static userControllerCreate<ThrowOnError extends boolean = false>(
options: Options<UserControllerCreateData, ThrowOnError>,
Expand Down Expand Up @@ -4528,7 +4528,7 @@ export class UpgradeService {

export class McpOauthService {
/**
* Begin an OAuth connect for an agent. Returns the authorization URL the agent sends the user in chat.
* Begin an OAuth connect for an agent. Returns the authorization URL the agent sends the user in chat. On the Ranch assistant only the Owner connects anything: a subject that is not the Owner, and the agent-wide connection, answer 403.
*/
public static startMcpOauth<ThrowOnError extends boolean = false>(
options: Options<StartMcpOauthData, ThrowOnError>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ import {
const props = defineProps<{ userId: string; name: string }>();

const store = useAssistantAccessStore();
const auth = useAuthStore();
const userStore = useUserStore();

/**
* The editor is an Admin limited to some agents (RANCH-8, FR-018): an
* ability they tick works only on agents they can see. Read from the
* viewer's own row in the user store; until it is in, nothing is said, and
* the API applies the rule either way.
*/
const grantCeilingNote = computed(
() => !!account.value?.editable && userStore.isLimitedAdmin(auth.user),
);

const loadError = ref<string | null>(null);
const saveError = ref<string | null>(null);
Expand All @@ -49,7 +61,12 @@ async function load() {
: messageOf(err, 'The assistant setting could not be read.');
}
}
onMounted(load);
onMounted(() => {
void load();
if (auth.user?.role === 'Admin') {
void userStore.fetchById(auth.user.id).catch(() => undefined);
}
});
watch(() => props.userId, load);

const account = computed(() => store.accountOf(props.userId));
Expand Down Expand Up @@ -178,6 +195,10 @@ async function onAdvancedSave(choice: {
</template>
</p>

<AccessNote v-if="grantCeilingNote" data-grant-ceiling-note>
Abilities you tick here work only on agents you can see.
</AccessNote>

<p
v-if="saveError"
class="text-sm text-destructive"
Expand All @@ -197,6 +218,7 @@ async function onAdvancedSave(choice: {
:on="account.pick?.on ?? []"
:fresh="account.pick?.new ?? []"
:ceiling="account.ceiling"
:grant-ceiling-note="grantCeilingNote"
:saving="saving"
:error="advancedError"
@save="onAdvancedSave"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const props = defineProps<{
fresh?: readonly string[];
/** For an Admin editing a User: the names they may hand out. */
ceiling?: readonly string[] | null;
/**
* The editor is an Admin limited to some agents (RANCH-8): what they tick
* works only on agents they can see, and the sheet says so.
*/
grantCeilingNote?: boolean;
saving?: boolean;
error?: string | null;
/**
Expand Down Expand Up @@ -214,6 +219,9 @@ function save() {
Area by area. Nothing here gives more than the role can do in the
console.
</SheetDescription>
<AccessNote v-if="grantCeilingNote" class="pt-1" data-grant-ceiling-note>
Abilities you tick here work only on agents you can see.
</AccessNote>
</SheetHeader>

<div class="flex shrink-0 flex-col gap-3 border-b px-4 py-3">
Expand Down
14 changes: 14 additions & 0 deletions admin/slices/user/user/components/user/create/Provider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
import type { ICreateUserData } from '#user/domain/user.types';

const userStore = useUserStore();
const auth = useAuthStore();
const submitting = ref(false);

// The viewer's own row says whether their agent access is limited (RANCH-8):
// a limited Admin's new account reaches only what the Admin reaches, and the
// form says so before Create. Until the row is in, nothing is said; the API
// applies the rule either way.
const ceilingWarning = computed(() => userStore.isLimitedAdmin(auth.user));

onMounted(() => {
if (auth.user?.role === 'Admin') {
void userStore.fetchById(auth.user.id).catch(() => undefined);
}
});

async function onSubmit(values: ICreateUserData) {
submitting.value = true;
const created = await userStore.create(values);
Expand All @@ -27,6 +40,7 @@ function onCancel() {

<UserItemForm
:submitting="submitting"
:ceiling-warning="ceilingWarning"
@submit="onSubmit"
@cancel="onCancel"
/>
Expand Down
20 changes: 19 additions & 1 deletion admin/slices/user/user/components/user/item/Form.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { IconAlertTriangle } from '@tabler/icons-vue';
import {
ASSIGNABLE_USER_ROLES,
UserRoleTypes,
Expand All @@ -16,8 +17,10 @@ const props = withDefaults(
submitting?: boolean;
cardTitle?: string;
cardDescription?: string;
// Create only: the viewer is an Admin limited to some agents (RANCH-8).
ceilingWarning?: boolean;
}>(),
{ mode: 'create', showRole: true, roleLocked: false },
{ mode: 'create', showRole: true, roleLocked: false, ceilingWarning: false },
);

const emit = defineEmits<{
Expand Down Expand Up @@ -133,6 +136,21 @@ function onSubmit() {
</CardContent>
</Card>

<!--
Read before the click, not explained after it (RANCH-8, FR-005a): a
limited Admin's new account reaches only what the Admin reaches. Kept
directly above the buttons so it stays in view at 390 px.
-->
<div
v-if="mode === 'create' && ceilingWarning"
class="-mb-3 flex items-start gap-2 rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs text-amber-900 dark:text-amber-200"
role="status"
data-user-ceiling-warning
>
<IconAlertTriangle class="mt-0.5 size-4 shrink-0" aria-hidden="true" />
<p>This account will reach only the agents you can see. Only the Owner can give it more.</p>
</div>

<div class="flex items-center gap-3">
<Button type="submit" :disabled="submitting">
{{
Expand Down
11 changes: 11 additions & 0 deletions admin/slices/user/user/stores/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
UserRoleTypes,
UserService,
} from '#user/domain';
import { isLimitedAdmin as limitedAdmin } from '#user/utils/viewer';

const getService = createServiceGetter<UserService>('$userService');

Expand All @@ -30,6 +31,15 @@ export const useUserStore = defineStore('user', () => {
return users.value.find((u) => u.id === id);
}

// Whether this viewer is an Admin whose own agent access is limited
// (RANCH-8), read from the viewer's own row: the same record every user
// screen renders (docs/state.md). Reactive inside a computed.
function isLimitedAdmin(
viewer: { id: string; role: UserRoleTypes | string } | null | undefined,
): boolean {
return limitedAdmin(viewer, viewer ? byId(viewer.id) : undefined);
}

// Full records only (anything the API returned for one account): replaces
// the row in place so the list keeps its order, appends when the id is new.
// The access mark travels on the /users routes only, so a record that does
Expand Down Expand Up @@ -119,6 +129,7 @@ export const useUserStore = defineStore('user', () => {
return {
users,
byId,
isLimitedAdmin,
upsert,
patch,
resetForAccount,
Expand Down
31 changes: 31 additions & 0 deletions admin/slices/user/user/utils/viewer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, expect, test } from 'bun:test';
import { AgentAccessKindTypes } from '../domain/user.types';
import { isLimitedAdmin } from './viewer';

const row = (kind: AgentAccessKindTypes | null) => ({
agentAccess: kind === null ? null : { kind, needsReview: false },
});
const admin = { id: 'u-admin', role: 'Admin' };

describe('isLimitedAdmin (RANCH-8)', () => {
test('an Admin limited to some agents, to none, or with denied agents', () => {
expect(isLimitedAdmin(admin, row(AgentAccessKindTypes.Only))).toBe(true);
expect(isLimitedAdmin(admin, row(AgentAccessKindTypes.None))).toBe(true);
expect(isLimitedAdmin(admin, row(AgentAccessKindTypes.AllExcept))).toBe(true);
});

test('not an Admin with no lists', () => {
expect(isLimitedAdmin(admin, row(AgentAccessKindTypes.All))).toBe(false);
});

test('not the Owner or a User, whatever their row says', () => {
expect(isLimitedAdmin({ id: 'o', role: 'Owner' }, row(AgentAccessKindTypes.Only))).toBe(false);
expect(isLimitedAdmin({ id: 'u', role: 'User' }, row(AgentAccessKindTypes.Only))).toBe(false);
});

test('nothing is said while the viewer or their row is not known', () => {
expect(isLimitedAdmin(null, row(AgentAccessKindTypes.Only))).toBe(false);
expect(isLimitedAdmin(admin, undefined)).toBe(false);
expect(isLimitedAdmin(admin, row(null))).toBe(false);
});
});
17 changes: 17 additions & 0 deletions admin/slices/user/user/utils/viewer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { IUserData } from '../domain/user.types';

/**
* Whether the person looking is an Admin whose own agent access is limited
* (RANCH-8): an account they create reaches only the agents they see, and an
* ability they tick for somebody works only there. Read from the viewer's
* own row; false while that row is not known, which only leaves a note out:
* the API applies the rule whatever the page shows.
*/
export function isLimitedAdmin(
viewer: { id: string; role: string } | null | undefined,
row: Pick<IUserData, 'agentAccess'> | null | undefined,
): boolean {
if (!viewer || viewer.role !== 'Admin') return false;
const kind = row?.agentAccess?.kind;
return kind !== undefined && kind !== 'all';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- RANCH-8: close the access-control holes found by the security audit.
--
-- 1. Who ticked the custom assistant pick in force (FR-014). The best record
-- of who made each existing pick is its last writer, so grants made by
-- limited Admins before this release follow the Admin's ceiling at once
-- (spec Assumptions; the release note says so).
-- 2. Who started a tool-server sign-in, and through which door (FR-021): the
-- callback re-checks it with today's role and reach.
-- 3. Every pending sign-in state is dropped. Each lives ten minutes
-- (STATE_TTL_MS) and those started before this release name no starter,
-- so none could be re-checked; a person mid-sign-in starts again.

-- AlterTable
ALTER TABLE "AssistantAccountAccess" ADD COLUMN "grantedById" TEXT;

-- Backfill
UPDATE "AssistantAccountAccess" SET "grantedById" = "updatedById" WHERE "level" = 'custom';

-- AlterTable
ALTER TABLE "McpOauthState" ADD COLUMN "startedById" TEXT,
ADD COLUMN "startedVia" TEXT NOT NULL DEFAULT 'runtime';

-- Pending states cannot be re-checked
DELETE FROM "McpOauthState";
Loading
Loading