Tag: MCP

  • AI Agent Permission Control: 3 Axes to Stop Data Leaks

    AI Agent Permission Control: 3 Axes to Stop Data Leaks

    A common question comes up frequently in security teams: “We blocked ChatGPT, so why is internal data still leaking?” Despite deploying URL blocking, DLP regex, and employee training, leak incidents continue. When the root cause is traced, the problem is not what employees type into their browsers—it is the officially approved internal AI agent that holds broad OAuth scopes to Drive, SharePoint, and internal databases while calling LLMs. Policies that only block consumer LLM websites can no longer explain governance.

    Existing AI blocking policies all assume ‘human’ behavior. Consumer LLM domain blocking, prompt payload regex, and endpoint keyloggers are all designed to catch the moment an employee types or pastes something in the browser. Officially approved agents, however, operate through a different path. They receive tokens through OAuth flows, connect directly to company data stores via standard interfaces such as MCP, and their permissions are indistinguishable from a person accessing data individually. When full Drive read access is granted once to an agent service account, the agent can perform legitimate work like ‘contract review’ while simultaneously pulling HR evaluations and undisclosed financial data from other folders into the LLM context.

    Why blocking alone is not enough—the real leak path is ‘delegated permissions’

    To close this gap, AI agent permission governance must be redesigned around ‘agent identity’ rather than ‘human input.’ The core is ① minimum scope per agent, ② service accounts separated by work unit, ③ proxy-based token-level DLP and bidirectional logs—operating these three axes simultaneously. Enforcing only one axis lets leaks route around through another path, and organically combining minimum-privilege scope, dedicated identity, and bidirectional audit logs is what field practitioners agree creates real effectiveness.

    From the blocking policy’s perspective, there is no signal to distinguish whether the call is legitimate work traffic or a data exfiltration attempt. As a result, even the most sophisticated enterprise DLP creates a situation where incidents cannot be traced after the fact. The center of gravity in governance must shift from ‘where is it called from’ to ‘whose credentials delegated which scope.’

    Scope—Slice AI agent permissions down to the work unit

    The first area to address is the Drive, SharePoint, and RDB IAM policies. When an agent receives a task such as ‘review Company A’s contract,’ dynamic scopes should be granted so that only the folder and table mapped to that ticket are read- and writable. AWS Bedrock Agents limits the call context through IAM session policy and encrypts model invocation logging with KMS for retention. Azure AI Foundry and Google Vertex AI Agents similarly require, as a standard, managed inference endpoints with an explicit Zero Data Retention option, where data is inferred only within the customer tenant.

    # Enforcing per-agent scope via LiteLLM Proxy policy headers (Illustrative Example, not official spec)
    # In production, replace with IdP group and IAM role mapping
    curl -X POST http://litellm.internal/v1/chat/completions \
      -H "Authorization: Bearer $AGENT_TOKEN" \
      -H "X-Agent-Scope: drive:folder/CONTRACT-2026-Q4-A" \
      -H "X-JIT-TTL: 900" \
      -d '{"model":"claude-3-5-sonnet","messages":[{"role":"user","content":"Summarize the key clauses of the Company A contract"}]}'
    

    Scope should be cut not at the ‘agent ID’ level but at the ‘work ticket ID’ level. A short TTL of 15 to 30 minutes is granted, and the design ensures automatic revocation after expiration. Each time the same agent receives a new task, new temporary credentials must be issued. The pattern of granting a large OAuth scope at once and narrowing it later makes post-incident response nearly impossible. The immediate-revocation pattern covered in AI Agent Identity Separation: 5 Steps to Immediate Revocation is the starting point for this stage.

    Identity—Separate service accounts by work and integration unit

    Even when scopes are sliced finely, if it is unclear ‘whose permissions’ they are being invoked under, post-hoc traceability breaks. If the same agent handles HR, sales, and engineering integrations all together, audit logs cannot separate which data went out under whose authority. The standard pattern is to issue dedicated service accounts for agents at the IdP (Okta, Entra ID) level, and to maintain a separate workload identity for each integration and project.

    Session tokens must record the calling principal, work ticket, and expiration time, and this information flows to the LLM gateway and is automatically joined with downstream logs. Human accounts and agent accounts must follow clearly different lifecycles. Human accounts are revoked at termination, but agent accounts must have their tokens recalled as soon as a task ends. Separating identity naturally follows when applying the workload identity federation and periodic key rotation principles from the 90-day zero-trust roadmap emphasized in the MFA limits and bypass response article.

    Audit—Combine the LLM gateway with enterprise DLP

    The third axis is bidirectional logging. All outbound traffic to OpenAI, Anthropic, and Google APIs is funneled through gateways such as LiteLLM Proxy, Portkey, and Cloudflare AI Gateway for token-level inspection. Not only prompts but also responses must be retained as logs on the same gateway, so that post-hoc reproduction of “which data was sent to which external LLM in what form” is possible. Enterprise DLP solutions such as Microsoft Purview DLP, Palo Alto Networks AI Security, and Harmonic Security detect PII, customer code, and internal hostname patterns in front of this gateway.

    Gateway Deployment Key features Suitable environment
    LiteLLM Proxy Self-hosted OpenAI-compatible API, multi-model routing, token-level DLP hooks Multi-cloud, Kubernetes-friendly
    Portkey SaaS + self-hosted Observability, fallback, A/B routing, policy engine LLM workflow standardization
    Cloudflare AI Gateway SaaS DDoS protection, caching/cache invalidation, Workers integration Cloudflare ecosystem-dependent organizations
    # LiteLLM config excerpt (Illustrative Example, not official spec)
    model_list:
      - model_name: claude-3-5-sonnet
        litellm_params:
          model: bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0
          aws_region_name: ap-northeast-2
          aws_session_token: os.environ/JIT_AGENT_TOKEN
    litellm_settings:
      drop_params: true
      request_timeout: 30
      success_callback: ["prometheus", "s3"]
      failure_callback: ["slack"]
    general_settings:
      drop_params: true
      master_key: os.environ/LITELLM_MASTER_KEY
    

    Unidirectional auditing that only collects prompts without logging responses is the most common anti-pattern. Even when an actual data leak occurs, it cannot be proven after the fact that “internal data was included in the external LLM response and returned.” Response logs must also be retained, but a retention policy must be set to automatically expire and cryptographically erase after 30 to 90 days to also address GDPR and personal information protection law compliance. Both LiteLLM and Portkey can stream logs to S3, GCS, and BigQuery, so folding them directly into an existing SIEM pipeline is the way to reduce operational burden.

    Endpoint and network secondary/tertiary defense layers

    If the three axes are the first line of defense, enterprise browsers, EDR, and CASB form the secondary and tertiary defense layers. Microsoft Edge for Business, Chrome Enterprise Premium, and Prisma Access Browser classify the generative AI site category and block personal account logins. EDR solutions such as CrowdStrike and SentinelOne trigger blocks and alerts when unknown agent harnesses (AutoGPT variants, local LLM clients, etc.) are installed. SaaS CASB solutions (Microsoft Defender for Cloud Apps, Netskope) track the flow of Drive shared links into AI workflows.

    The key value of this layer is ‘visibility into bypass paths.’ Even when the agent is not an officially approved one covered by first-line controls, it catches the moment an employee installs a local LLM client on their laptop or signs up for a Shadow AI SaaS with a company email. It does not prevent leaks on its own, but it becomes the baseline that distinguishes legitimate traffic defined by first-line controls from abnormal traffic. Combined with zero-trust NAC, calls to the gateway from devices whose posture does not meet requirements can be rejected entirely, serving as a safety net for first-line controls.

    Vendor governance and legal review

    Separate from technical controls, AI vendors must be explicitly named as sub-processors in contracts, and the Zero Data Retention option must be made mandatory. Standard clauses should include a provision that inputs and outputs from LLM API calls are not used for vendor training, a 72-hour incident notification obligation, and an audit log delivery obligation. AWS Bedrock, Azure OpenAI Service, Anthropic Enterprise, and Google Vertex AI all offer explicit ZDR options, but even when calling the same model, the retention policy differs by API key type (e.g., a general API key versus an Enterprise tenant key), so operations and legal teams must review together.

    Operational limits and common anti-patterns

    Five anti-patterns frequently seen in the field are summarized below. If even one of these is missing, post-incident response is effectively impossible.

    Anti-pattern Actual impact Correct pattern
    Granting full Drive read OAuth to an agent then narrowing it later Cannot reproduce which folders were accessed post-hoc Ticket-level Just-in-Time scope
    Bypassing security review citing only work efficiency Shadow AI spreads, responsibility unclear Mandatory security team approval gate
    Business unit alone decides on AI tools No catalog, duplicate introduction Internal AI catalog + central governance
    Direct LLM API call without a proxy Loss of token-level DLP and cost visibility LLM gateway standardization
    Collecting only prompt logs Cannot prove response data leakage Request/response bidirectional logs + retention

    On the cost side, additional infrastructure costs arise from introducing the LLM gateway and managed inference endpoints. LiteLLM Proxy is at the container cost level when self-hosted, but as traffic grows, Redis and Postgres backends must also be operated. Portkey and Cloudflare AI Gateway start with SaaS pricing, but cost increases linearly for large-scale log retention. Bedrock, Foundry, and Vertex themselves also apply per-token billing, so controlling token usage through scope minimization directly equates to cost optimization. In terms of cross-team collaboration, the RACI where the security team defines only scope policy and agent developers automate it through IaC has the fewest conflicts.

    What to do right now

    • Build an inventory of AI agents operating in-house, and map the OAuth scopes each agent holds to the connected data stores.
    • Check network logs for one week to see if there is any traffic directly calling OpenAI, Anthropic, or Google APIs, and add firewall rules to force-route all of it through the LLM gateway.
    • Pilot-deploy LiteLLM Proxy or Portkey scoped to one workflow, and verify that bidirectional logs for prompts and responses are delivered to S3 or SIEM.
    • Issue dedicated service accounts for agents from the IdP, and reorganize them into groups and policies separate from existing human accounts.
    • Create a quarterly agent permission audit process, and reflect in IaC the automatic revocation of unused scopes, expired tokens, and accounts linked to departed employees.

    The essence of in-house AI security ultimately boils down to the question, “How far, under whose authority, and for how long should data be entrusted?” As the field’s concerns discussed in the original thread show, blocking policies alone can no longer explain governance. Splitting AI agent permissions across the three axes—scope, identity, and logs—and building a structure that combines at least six detailed controls (dynamic IAM, dedicated SAs, bidirectional proxy, token DLP, temporary credential revocation, storage encryption) on top of that three-axis governance is the most realistic starting point for bringing data leak incidents into a post-hoc traceable state.

    Source

    This article was written after checking the following original thread: r/AskNetsec — How do you let staff use AI without company data leaking out?

  • Local Search in 30 Seconds, 3,457 Files Indexed — How Qwen’s zg Transforms Agent Workflows

    Local Search in 30 Seconds, 3,457 Files Indexed — How Qwen’s zg Transforms Agent Workflows

    Key Takeaways

    • zg (zvec-grep) is a local-first search tool open-sourced by the Qwen team. It combines ripgrep’s precise text matching with vector search, BM25, and hybrid retrieval, letting natural-language intent navigate code and documents while narrowing down to the exact location.
    • The default embedding model is local/potion-code-16m-v2 — 16M parameters, about 32 MiB of local cache, no GPU required. Eleven on-device embedding models are bundled so users can pick the right one for each use case.
    • It indexed the entire Django repository of 3,457 files in under 30 seconds on an Apple M4 Pro. Zvec stores vector and BM25 indexes as an embedded library on the device, eliminating the need for a separate database service.

    Analysis

    Table of Contents

    The standard for local search is shifting. The figure of indexing 3,457 files of the Django repository in 30 seconds on an Apple M4 Pro highlights the limits of workflows that have long relied on ripgrep. zg (zvec-grep), open-sourced by the Qwen team, is a tool that adds semantic exploration to a local-search experience previously confined to keyword matching.

    A New Standard for Local Search: The Context Behind zg

    ripgrep is fast, but it struggles with natural-language questions like “Where is the OAuth callback handled?” zg addresses exactly that gap in local search. It adopts local/potion-code-16m-v2 as the default embedding model — 16M parameters, about 32 MiB of local cache, running on CPU alone with no GPU required. Eleven on-device embedding models are bundled, letting users choose based on the task at hand.

    The vector and BM25 index, called Zvec, is stored on the device as an embedded library. No separate database service is required. This distinction changes how the tool operates in on-premise environments and agent workflows.

    The Architecture of Hybrid Local Search

    The core idea is fusion, not a single algorithm. BM25 and vector search generate candidates, ripgrep adds exact matching, and RRF (Reciprocal Rank Fusion) produces the final ranking. The default output is a constrained preview plus a compressed ranked list, giving the next reasoning step enough context without re-reading entire result files.

    Comparing Three Local Search Approaches

    Item ripgrep alone zg hybrid Remote vector DB
    Indexed target Text only Vector + BM25 + text Vector + metadata
    Natural-language queries Not supported Supported Supported
    Local self-sufficiency Full Full Not possible (API-dependent)
    Agent integration Direct call MCP supported out of the box Requires a separate adapter
    Primary cost Disk I/O CPU embedding API call fees

    How to Plug zg into Your Agent Workflow

    The integration path for agents is MCP (Model Context Protocol). Since multiple agents share the same local index, redundant per-agent indexing never happens. The tool description also specifies search termination conditions, reducing repeated calls for the same query. What stands out for practitioners is the shift in cost structure. Given the growing number of teams adopting agent-based development, the local-search layer is becoming the next variable in cost competitiveness.

    What Two Benchmarks Reveal About Local Search

    SWE-QA-Bench tests multi-step reasoning on 20 questions across real code repositories. With zg introduced, tool calls dropped by more than half and input tokens fell by nearly half. The Judge score rose by 1.50 points.

    BrowseComp-Plus is a deep-research evaluation of 80 questions. Accuracy climbed from 98.67% to 99.00%, while input tokens dropped 37.56%, tool calls 43.52%, and agent runtime 38.58%. It is worth remembering, however, that the one-time initial index creation and remote embedding API costs were excluded from these figures.

    Practical Application Points

    • Start indexing from the repository root with `zg index .`, and add the default `.zvec/` directory to `.gitignore`.
    • Use `.zgignore` to explicitly exclude large directories such as `node_modules`, `dist`, and `venv` to reduce indexing time.
    • Launch in MCP server mode (`zg serve –mcp`) and include a stop rule in the agent system prompt, such as “after three searches, synthesize the answer candidates.”
    • Swap among the 11 embedding models based on the code/documentation/natural-language ratio. For code-heavy work, use `potion-code-16m-v2`; for Korean-language documents, prioritize a multilingual model.

    Try It Right Now

    • Clone a demo repository (e.g., requests, fastapi) and measure the runtime of `zg index .`.
    • Compare ripgrep-only results with zg hybrid results on the same query and track token usage.
    • Register the zg server in the MCP configuration file of your agent (Claude Code, Cursor, etc.).
    • Write a `.zgignore` to block noisy directories and shrink the index size.
    • Pick 5 of the 11 embedding models and record accuracy by query type (symbol search, semantic search, typo correction).

    Unverified Aspects and Remaining Challenges

    The author views the tool’s significance as lying less in raw search speed and more in the cost structure of a single agent cycle. Cutting tokens and call counts by nearly half means longer reasoning runs on the same budget. That said, the remaining validation challenges are clear: index update policy, monorepo memory footprint, and model swap cost. The original is available at Hacker News Korea’s zg (zvec-grep) — local search infrastructure beyond keywords.

    Frequently Asked Questions

    Does zg replace ripgrep?

    It does not replace it — it sits on top of it. The architecture preserves ripgrep’s exact matching for result precision while placing BM25 and vector search in front to extend candidate generation with semantic understanding.

    Can local search work without a GPU?

    Yes. The default model, local/potion-code-16m-v2, runs on CPU alone. At 16M parameters and roughly 32 MiB of local cache, indexing and search are feasible on a standard laptop.

    How much does it reduce cost when used as an agent tool?

    In the BrowseComp-Plus evaluation of 80 questions, input tokens dropped 37.56%, tool calls dropped 43.52%, and agent runtime dropped 38.58%. This is because results are returned as previews and compressed ranked lists.

    Is index refresh automatic or manual?

    Based on the published workflow, manual indexing (`zg index`) is the default. Automatic refresh based on file-change detection remains an open validation task in monorepo environments.

    Reference Source

    This article was written after verifying the following source: geeknews — zg (zvec-grep): local search infrastructure beyond keywords