Skip to content

Comments

feat: add custom headers to taskrc and cli flags#2700

Open
ldgriswold wants to merge 1 commit intogo-task:mainfrom
ldgriswold:feat/auth-headers
Open

feat: add custom headers to taskrc and cli flags#2700
ldgriswold wants to merge 1 commit intogo-task:mainfrom
ldgriswold:feat/auth-headers

Conversation

@ldgriswold
Copy link

Issue Link: #1317

This PR adds support for custom HTTP headers when fetching remote Taskfiles, enabling authentication with services like GitHub,
GitLab, and other platforms without exposing credentials in URLs.

Features

Configuration via .taskrc.yml:

remote:
  headers:
    raw.githubusercontent.com:
      Authorization: "Bearer {{.GITHUB_TOKEN}}"
    gitlab.com:
      PRIVATE-TOKEN: "{{.GITLAB_TOKEN}}"

CLI Flag Support:

task --header "raw.githubusercontent.com:Authorization=Bearer token" mytask

Key Capabilities:

  • Custom header names (e.g., GitLab's PRIVATE-TOKEN)
  • Environment variable expansion using {{.VAR}} syntax
  • Host-specific header matching (exact hostname including port)
  • CLI flags override config file settings
  • Config file merging (local > home > XDG)

Security

Built-in Protections:

  • Forbidden headers blocked: Host, Content-Length, Transfer-Encoding, Trailer, Connection, Upgrade, Location, Set-Cookie
  • Control character validation prevents HTTP header injection
  • Headers only sent to exact hostname matches
  • Warning messages logged when headers are skipped

Implementation Details

  • Headers threaded through both root node and Reader (follows TLS cert pattern)
  • Environment variable expansion uses env.GetEnviron() for full env access
  • Merge semantics handle nested maps from multiple config sources

Testing

  • 183 lines of config parsing tests in taskrc/taskrc_test.go
  • 238 lines of integration tests in task_test.go covering:
    • Config file parsing
    • Environment variable expansion
    • CLI flag usage
    • Host-specific matching
    • Forbidden header blocking
    • Control character validation

All tests passing.

Documentation

Updated website/src/docs/experiments/remote-taskfiles.md with:

  • Configuration examples
  • CLI flag usage
  • Security best practices
  • Multiple authentication scenarios"

@ldgriswold ldgriswold force-pushed the feat/auth-headers branch 3 times, most recently from bc7f272 to 1c09550 Compare February 20, 2026 20:34
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.

1 participant