Implementation Guide

    Blocking AI agents and coding assistants from editing GitHub Actions workflows and .gitlab-ci.yml files

    Treat pipeline definitions as a protected asset class and apply three layers. First, path-based review rules, token restrictions and protected environments in GitHub and GitLab. Second, dedicated, least-privilege agent identities and tool sets that exclude pipeline paths. Third, runtime policy enforcement on agent file-write and tool calls that can block or escalate for human approval before the edit happens. Retain evidence of every decision at each layer.

    Evidence to retain for an auditor

    • The agent identity, the user it acted for and the tool that made the call
    • The target path and the requested operation
    • The policy decision (allowed, blocked or escalated) and the policy version applied
    • For escalations, the approver, the decision and the timestamp
    • Repository configuration records: CODEOWNERS, ruleset or branch protection settings, environment approvers
    • Pull request review records for any pipeline change that was merged

    Layer one: repository platform controls in GitHub and GitLab

    Assign path ownership

    Add CODEOWNERS entries for the workflow directory, .gitlab-ci.yml and every included template or script the pipeline runs. Assign them to the platform or security team.

    Require owner review

    Use branch protection or rulesets on default and release branches to require code owner approval, block author self-approval and restrict bypass.

    Restrict token scope

    Set workflow tokens to read-only by default and grant write access per job. In GitLab, limit job token access to the projects that need it.

    Protect environments and variables

    Put required approvers on deployment environments. Expose protected variables only to protected branches and tags.

    Enforce mandatory pipeline steps

    In GitLab, use push rules and pipeline execution policies, where available in your tier, so project-level edits cannot remove required jobs.

    Test the controls

    Attempt a pipeline edit from a non-privileged agent identity and confirm each gate stops it.

    How an agent can change a pipeline definition

    A pipeline definition is ordinary code in a repository. Any process that can write to a working tree, push a branch or open a pull request can change .github/workflows/*.yml or .gitlab-ci.yml. A modified definition can alter build steps, widen token permissions, expose secrets, remove required checks or redirect a deployment target.

    The identity an agent uses sets its reach. An assistant running under a developer's personal credentials inherits everything that developer can do. A repository-integrated agent acts through whatever bot or app token it was given. Inventory the paths first, because each one needs a different control.

    NIST SP 800-204C lists, among its minimum tasks for securing the pipeline, ensuring that developers can access application code but not the pipeline code types. That text addresses human developers. Applying the same boundary to agents acting on their behalf is a sound extension, and it is the premise of this guide.

    • IDE file-write tools: An assistant edits files in the local working tree, including workflow files, and the developer commits the result.
    • CLI agents: An agent runs shell commands and file edits with the developer's shell credentials.
    • Repository-integrated agents: An agent pushes branches or opens pull requests under a bot, app or user token.
    • MCP tool servers: A server exposes file or repository operations that any connected agent can call.
    • Indirect edits: The agent leaves the YAML alone and changes a script, template or included file that the pipeline executes.

    Layer two: scope agent identities and tools

    NIST guidance for AI agents is consistent on this point: grant only the permissions needed for the role, and do not hand agents broad privileges or open-ended tools. For pipeline files, that means giving agents dedicated identities rather than developer personal tokens, using fine-grained tokens that cannot write to workflow paths, and keeping agents off protected branches. Tool sets should be allowlisted, so an MCP server that exposes arbitrary file operations is not connected by default.

    Separate the environments as well. NIST SP 800-204D describes an isolated CI/CD environment and defined roles for the actors who operate pipelines. In practice, name the roles that may change pipeline code, state whether any agent holds one, and keep elevated deployment credentials out of any context an agent can reach.

    Assume an agent can be steered. Prompt injection is a recognized attack class against generative AI systems, and NIST advises not trusting prompt instructions, metadata or artefacts from users or other agents. An agent that reads an issue, a dependency description or a file comment may be pushed toward a workflow edit. The control therefore cannot depend on the agent declining. Scoping also has gaps: it only covers identities you know about, and developer-local assistants running on personal credentials often sit outside it.

    Layer three: enforcement in the execution path

    The first two layers decide who may merge and what a credential can do. Neither makes a decision at the moment an agent calls a file-write tool. A runtime layer can. NIST SP 800-162 describes attribute-based access control as evaluating the subject, object, requested operation and environment against policy. Applied to this problem, the subject is the agent and the user behind it, the object is a path matching a pipeline definition, the operation is a write, and the environment is the target branch. The outcome is one of three: allow, block, or escalate for human approval.

    Trussed enforces policy in the execution path across agents, tools, MCP servers and coding assistants, with decisions including allow, block and escalate for human approval at the level of individual interactions and tool calls. For this use case, that means the policy is enforced at runtime, not reviewed after the fact: a write to a pipeline file can be stopped or routed to an approver before the change reaches a branch.

    Be precise about scope. This layer governs the calls that pass through it, so an assistant that bypasses the path is not covered. It does not replace CODEOWNERS or protected environments. A legitimate pipeline change approved at runtime should still meet owner review at merge. Two independent gates are the design goal.

    Three layers protecting pipeline files

    Label: Repository controls

    Description: CODEOWNERS, rulesets, protected branches, protected environments and variables.

    Label: Identity and tool scoping

    Description: Dedicated agent identities, read-only tokens by default, restricted tool sets.

    Label: Runtime enforcement

    Description: Allow, block or escalate each agent file-write or tool call before it executes.

    Label: Retained evidence

    Description: A record of what was attempted, decided and approved.

    Add a block-or-escalate decision to your pipeline protections

    See how policy enforcement on agent tool calls and file edits works alongside repository controls, and what evidence it produces.

    See How Evidence Is Produced
    Next step

    How does your AI governance program compare?

    See where your program has gaps in less than 2 minutes.