Chapter 33Lesson 03~330 minutes

GitLab Duo and Agentic DevSecOps: AI Features, Security Remediation, Governance, and Usage Controls: Configuration, Design Choices, and Tradeoffs

Design AI adoption controls that choose deterministic automation or AI assistance deliberately, centralize minimum guardrails, bound data exposure and tool authority, and control verification and credit cost.

Design TradeoffsCreditsData GovernanceLeast PrivilegeSLO

Learning objectives

  • Choose deterministic automation, non-agentic assistance, or agentic execution according to uncertainty, consequence, and verification cost.
  • Design a default tool-governance matrix that is least-privilege, human-reviewable, and stricter for background execution.
  • Separate organization-wide minimum policy from project-specific narrowing without allowing local teams to weaken central controls.
  • Make data-processing, model/provider, privacy, prompt-caching, logging, and external MCP decisions explicit architecture choices.
  • Budget GitLab Credits and verification effort together instead of optimizing only for model usage or developer speed.
Availability and governance baseline — verified 2026-08-22 against GitLab 19.3. Policy examples are product-agnostic fixtures mapped to current GitLab concepts. Current group/project governance capabilities, feature status, and Free/Premium/Ultimate availability must be rechecked before implementation. Some newer controls—including AI audit reporting and MCP governance—can be beta or feature-flagged in the 19.3 line.

1. Choose AI only where uncertainty is worth the verification burden

A deterministic script is often superior when the transformation is fully specified and correctness can be encoded directly. AI adds value when the task needs interpretation across incomplete or heterogeneous context: explaining a failure, triaging findings, generating a candidate migration, reviewing cross-file changes, or proposing a remediation. Agentic execution adds value only when the saved coordination effort exceeds the additional authorization and verification burden.

Task Preferred default Why
Format generated files Deterministic formatter Exact rule, cheap to verify, no model uncertainty
Bump a pinned version with known API Deterministic automation + tests Mutation is predictable and repeatable
Explain an unfamiliar stack trace Non-agentic assistance Interpretive value; no write needed
Propose fix for complex vulnerability AI proposal + human/security review Useful synthesis, but correctness/security require evidence
Implement issue across many files Agentic flow in branch Coordination benefit, but requires tool governance + MR verification
Delete project / production data Human-governed procedure Consequence is too high for open-ended agent autonomy

2. “Always allow / ask / deny” should encode consequence, not convenience

Start from the default risk of the capability rather than how often it is used. Reads can leak sensitive information, so “read” is not automatically harmless. Writes can alter future CI execution, permissions, or release content. Deletes can irreversibly remove evidence or data. External MCP tools add another trust boundary because their server, credentials, network, and data processing are outside core GitLab.

Tool class Web / interactive default Runner/background default Rationale
Read approved repository metadata Allow Allow if data class permits Low mutation risk; still control sensitive scopes
Read vulnerability/customer-private data Ask or deny Deny unless explicitly approved Data exposure can be consequential without mutation
Write source on feature branch Ask Allow only in explicitly approved flow Interactive reviewer can inspect intent; background needs preauthorization
Edit CI/security policy Ask / often deny Deny Changes execution/security boundary
Create MR Ask Allow only if workflow contract requires Reversible object but can create noisy/untrusted proposals
Delete branch/tag/package/resource Ask or deny Deny Destructive; background approval cannot be interactive
External MCP tool Deny by default Deny by default Third-party code/data/credential boundary

3. Central policy sets the floor; projects may narrow for local risk

GitLab’s current governance model lets a top-level group define rules and projects apply equal or stricter rules. This is the correct inheritance direction for a platform team: central policy should encode non-negotiable data, deletion, external-tool, and high-impact write constraints. A payment project can narrow a generic read tool; it should not be able to convert a centrally denied delete capability into automatic allow.

Governance inheritance
flowchart TD
  O[Top-level governance baseline] --> P1[Project A override: same or stricter]
  O --> P2[Project B override: same or stricter]
  O --> P3[Project C: inherit baseline]
  P1 --> S1[Agent session]
  P2 --> S2[Agent session]
  P3 --> S3[Agent session]
  S1 --> V[Normal GitLab RBAC + MR/CI/security controls]
  S2 --> V
  S3 --> V

Keep the distinction from ordinary GitLab membership: a project Maintainer’s ability to change project settings does not imply the project may weaken an organization’s AI governance baseline.

4. Data policy must be written before prompt policy

Prompt-writing guidance such as “don’t paste secrets” is useful but insufficient. Context can be gathered automatically from files, issues, merge requests, vulnerabilities, tool results, or chat history. A mature policy classifies data first, then decides which AI features/models/providers may receive each class.

Data class Default AI policy Additional control
Public open-source Allowed with normal review Still block credentials/test secrets accidentally present
Internal source Approved providers/features only Repository/namespace allowlist; retention review
Customer/confidential data Deny by default Legal/privacy/security approval for specific use case
Secrets / credentials Never send intentionally Secret detection, redaction, incident response if exposed
Security findings Restricted approved workflows Verify explicit enablement/data-sharing behavior
Production logs Sanitize/minimize first Stable pseudonyms; remove tokens/PII; retention policy

5. Model/provider and prompt-caching choices are supply-chain decisions

GitLab can route different Duo features to different supported models/providers, and Self-Managed deployments can have additional self-hosting choices. The right architecture question is not “Which model is smartest?” but “Which model/provider is approved for this data, what is its support status, what retention/caching behavior applies, and what happens when it is unavailable or changed?”

Prompt caching can improve latency but temporarily stores prompt material in the model-provider path according to the current feature/provider behavior. Optional expanded usage logging can retain richer trace material. Self-hosted model architectures shift infrastructure, observability, patching, capacity, and data-residency responsibility back to the operator.

Do not infer privacy from deployment location alone. Self-Managed GitLab can still call externally hosted model services; conversely, self-hosted models can reduce external data transfer but increase your operational responsibilities.

6. Agentic flows reintroduce the Runner trust model

Flows launched from the GitLab UI can execute through CI/CD runners. That means Chapter 14’s runner lessons still apply: executor isolation, network reachability, tags, container images, host mounts, privileged mode, secrets, and persistence are security boundaries. Agentic convenience does not make a privileged persistent runner safe for untrusted work.

Current GitLab flow execution documentation describes runner requirements and a gitlab--duo tag for applicable self-managed runners. It also describes execution-environment sandbox options that can require privileged container mode. Privileged mode is itself a strong host-risk signal; use isolated/ephemeral infrastructure and current hardening guidance rather than treating “sandbox” as a magic word.

Production pattern: keep flow runners separate from deployment runners and from runners carrying production secrets. Constrain network egress and use short-lived/federated credentials where external services are required.

7. Optimize total workflow cost: credits + compute + review + incident risk

AI usage cost is only one term. A cheap model action that creates a 600-line speculative patch can cost more reviewer time than a smaller, more expensive action. A background flow can also consume runner compute. An incorrect security remediation can create incident cost. Therefore measure outcome-normalized cost: accepted useful changes, review time, retry rate, escaped defects, and credit/compute consumption.

WORKFLOW COST MODEL (conceptual)
total_cost = ai_usage
           + runner_compute
           + human_review_time
           + failed_retry_time
           + security/reliability_risk

Useful metric examples:
- credits per accepted MR (not per generated response)
- median review minutes for AI-authored vs human-authored MRs
- % AI proposals rejected for scope/correctness/security
- rollback / escaped-defect rate
- runner minutes per completed flow

8. Worked design: choose a policy for four teams

Team / task AI mode Tool policy Data / execution guardrail Why
Docs team on public repo Agentic branch + MR Read allow; writes ask Public data; disposable branch Low data sensitivity, easy diff verification
Payments source refactor Non-agentic proposal first Sensitive reads ask; writes ask/deny Approved provider; no customer data; strict MR High code sensitivity and verification burden
Security vulnerability remediation AI proposal + security review Vuln read restricted; writes ask Synthetic/staging or approved security-data path Finding context is sensitive; fix must be scanner/test verified
Production cleanup Deterministic runbook / human Delete deny for agent Change-management + backup/audit Consequence outweighs agentic benefit

9. Keep governance decisions reviewable even when product settings are UI-driven

Store a human-readable policy record in the platform repository or governance documentation even if GitLab settings are configured in the UI. The record explains intent, owner, exception process, and evidence expectations. Do not store credentials or export private prompt content just to make the policy “complete.”

version: 1
policy_owner: platform-security
scope: top-level-group
principles:
  - synthetic-or-approved-data-only
  - least-privilege-tools
  - human-approval-for-consequential-writes
  - deny-destructive-background-actions
  - independent-verification-before-merge
  - usage-budget-with-graceful-fallback
exceptions:
  require:
    - named_owner
    - expiration
    - data_classification
    - rollback_plan
    - audit_evidence

Knowledge check

When is deterministic automation preferable to an AI agent?

Why can read tools deserve Ask or Deny?

What inheritance direction should central and project tool policies use?

Why should a flow runner be separated from production deployment runners?

Why is credits-per-response a weak success metric?

10. Lesson summary and bridge

  • Use deterministic automation for deterministic problems; add AI where interpretation is valuable and verifiable.
  • Governance modes should encode data sensitivity and consequence, with stricter defaults for unattended/background execution.
  • Central policy establishes a non-weakenable floor; project teams adapt by narrowing access.
  • Data classification, provider/retention/caching choices, Runner isolation, and external MCP boundaries are part of the AI threat model.
  • Optimize total workflow outcome and risk, not only model credits or raw generation speed.

Next, you will diagnose the ways these controls fail in practice: over-broad tools, prompt/data leakage, feature drift, approval mismatch, missing runners, and plausible but unsafe remediation.

Primary sources and version notes

These lessons were finalized against current official GitLab documentation on 2026-08-22 with GitLab 19.3 as the release baseline. GitLab Duo and the Agent Platform are unusually version-volatile: feature maturity, model selection, credits, availability, governance behavior, UI placement, and data-processing details can change between releases. Re-check the documentation for the exact offering, subscription, add-on, and GitLab version you use. The policy YAML is documentation, not a GitLab product configuration schema. Agent Platform governance configuration and inheritance must be implemented through the current supported GitLab interfaces for your release.

Next lesson

Diagnostics, Failure Modes, Security, and Performance

Diagnose unsafe authority, data exposure, feature drift, credit failures, runner mismatch, and plausible but incorrect remediation.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.