Skip to content

Comments

Update agentic engine token handling to use user-provided secrets#18017

Merged
pelikhan merged 4 commits intomainfrom
copilot/update-agentic-engine-token
Feb 24, 2026
Merged

Update agentic engine token handling to use user-provided secrets#18017
pelikhan merged 4 commits intomainfrom
copilot/update-agentic-engine-token

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

When a user provides engine.env in a workflow frontmatter, the agentic engine token expression is automatically overridden with the user-supplied secret — in both the execution step and the secret validation step.

Changes Made

  • Gemini engine: Added maps.Copy(env, workflowData.EngineConfig.Env) and agent config env passthrough to gemini_engine.go's GetExecutionSteps, bringing it in line with the Copilot, Claude, and Codex engines (which already had this support).
  • Secret validation step: Modified GenerateMultiSecretValidationStep to accept engine.env overrides. When a token key (e.g. COPILOT_GITHUB_TOKEN) is overridden via engine.env, the validation step validates the user-supplied secret expression instead of the default ${{ secrets.KEY }}.
  • Tests — Gemini: Added tests verifying engine.env overrides GEMINI_API_KEY and passes through custom env vars.
  • Tests — Copilot: Added TestCopilotEngineEnvOverridesTokenExpression verifying COPILOT_GITHUB_TOKEN can be overridden via engine.env.
  • Tests — Claude: Added TestClaudeEngineEnvOverridesTokenExpression verifying ANTHROPIC_API_KEY can be overridden via engine.env.
  • Tests — Codex: Added TestCodexEngineEnvOverridesTokenExpression verifying CODEX_API_KEY can be overridden via engine.env.
  • Tests — Validation step: Added TestGenerateMultiSecretValidationStepWithEnvOverrides and TestValidationStepUsesEngineEnvOverride covering override behavior in the validation step for all 4 engines.

Example

engine:
  id: gemini  # or copilot, claude, codex
  env:
    GEMINI_API_KEY: ${{ secrets.MY_ORG_GEMINI_KEY }}

With this configuration, both the execution step and the secret validation step will use ${{ secrets.MY_ORG_GEMINI_KEY }} instead of the default ${{ secrets.GEMINI_API_KEY }}.

Testing

  • make fmt passes with no changes
  • ✅ All new and existing engine tests pass

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…rovided in Gemini engine

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Contributor

@copilot add the same support for copilot, claude, codex

@pelikhan
Copy link
Contributor

https://gh.io/copilot-coding-agent-docs add the same support for copilot, claude, codex

@pelikhan
Copy link
Contributor

@copilot add the same support for copilot, claude, codex

…dex engines

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot add the same support for copilot, claude, codex

Added tests verifying engine.env overrides the default token expression for Copilot (COPILOT_GITHUB_TOKEN), Claude (ANTHROPIC_API_KEY), and Codex (CODEX_API_KEY) in commit 65478c4. The code support already existed in all three engines — this commit adds test coverage to confirm and document that behavior.

Copilot AI changed the title [WIP] Update agentic engine token handling to use user-provided secrets Update agentic engine token handling to use user-provided secrets Feb 24, 2026
@pelikhan
Copy link
Contributor

@copilot make sure the override applies to the validation step: the overridden value is validated .

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot make sure the override applies to the validation step: the overridden value is validated .

Done in commit 133f576. GenerateMultiSecretValidationStep now accepts an envOverrides map[string]string parameter. When a key in the validation step's env: section matches an engine.env override, the user-provided expression (e.g. ${{ secrets.MY_ORG_TOKEN }}) is used instead of the default ${{ secrets.KEY }}. All 4 engine callers (copilot, claude, codex, gemini) pass the engine.env overrides to the validation step.

@pelikhan pelikhan marked this pull request as ready for review February 24, 2026 02:21
Copilot AI review requested due to automatic review settings February 24, 2026 02:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates agentic engine secret/token handling so engine.env can override default token secret expressions consistently across execution steps and the install-time secret validation step.

Changes:

  • Extend GenerateMultiSecretValidationStep to accept engine.env overrides and validate the overridden secret expression instead of the default ${{ secrets.KEY }}.
  • Add engine.env passthrough (and agent config env passthrough) to Gemini execution steps for parity with other engines.
  • Add/expand tests across engines and secret validation to cover token-expression overrides and custom env vars.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflow/agentic_engine.go Adds envOverrides support to multi-secret validation env generation.
pkg/workflow/engine_helpers.go Introduces helper to pass engine.env overrides into common install-step generation.
pkg/workflow/gemini_engine.go Copies engine.env (and agent env) into Gemini execution env; passes overrides to validation step.
pkg/workflow/copilot_engine_installation.go Passes engine.env overrides into Copilot’s secret validation step.
pkg/workflow/claude_engine.go Passes engine.env overrides into Claude’s secret validation step.
pkg/workflow/secret_validation_test.go Updates existing tests for new signature and adds override-focused validation tests.
pkg/workflow/gemini_engine_test.go Adds tests verifying Gemini token override and custom env passthrough.
pkg/workflow/copilot_engine_test.go Adds tests verifying Copilot token override and extra env vars.
pkg/workflow/claude_engine_test.go Adds tests verifying Claude token override and extra env vars.
pkg/workflow/codex_engine_test.go Adds tests verifying Codex token override and extra env vars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +273 to +288
// Set the model environment variable only when explicitly configured.
// When model is configured, use the native GEMINI_MODEL env var - the Gemini CLI reads it
// directly, avoiding the need to embed the value in the shell command (which would fail
// template injection validation for GitHub Actions expressions like ${{ inputs.model }}).
// When model is not configured, let the Gemini CLI use its built-in default model.
if modelConfigured {
geminiLog.Printf("Setting %s env var for model: %s", constants.GeminiCLIModelEnvVar, workflowData.EngineConfig.Model)
env[constants.GeminiCLIModelEnvVar] = workflowData.EngineConfig.Model
}

// Add custom environment variables from engine config.
// This allows users to override the default engine token expression (e.g.
// GEMINI_API_KEY: ${{ secrets.MY_ORG_GEMINI_KEY }}) via engine.env.
if workflowData.EngineConfig != nil && len(workflowData.EngineConfig.Env) > 0 {
maps.Copy(env, workflowData.EngineConfig.Env)
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above the GEMINI model env var says it’s only set when explicitly configured and otherwise the CLI default is used. With the new engine.env passthrough (maps.Copy(env, workflowData.EngineConfig.Env)), users can now set/override GEMINI_MODEL via engine.env even when EngineConfig.Model is empty, so the comment is no longer accurate. Please update the comment to reflect the new precedence/behavior (e.g., EngineConfig.Model sets it when provided, but engine.env can also set/override it).

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 7d5cc39 into main Feb 24, 2026
120 checks passed
@pelikhan pelikhan deleted the copilot/update-agentic-engine-token branch February 24, 2026 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants