feat: do not log secret variables (#2514)

This commit is contained in:
Valentin Maerten
2026-06-29 14:50:08 +02:00
committed by GitHub
parent c73d53f4e9
commit 6abbbcb265
21 changed files with 557 additions and 38 deletions

View File

@@ -1614,6 +1614,198 @@ tasks:
map[a:1 b:2 c:3]
```
### Secret variables
Task supports marking variables as `secret` to prevent their values from being
displayed in command logs. When a variable is marked as secret, its value will
be replaced with `*****` in the task output logs.
::: warning
**Security Notice**: This feature helps prevent accidental exposure of secrets
in logs, but is **not a substitute** for proper secret management practices.
**What this protects:**
- ✅ Secret values in console/terminal logs
- ✅ Secret values in CI/CD logs
- ✅ Accidental copy-paste of logs containing secrets
**What this does NOT protect:**
- ❌ Secrets visible in process inspection (e.g., `ps aux`)
- ❌ Secrets in shell history
- ❌ Secrets in command output (stdout/stderr)
- ❌ Secret values copied into derived (non-secret) variables
Always use proper secret management tools (HashiCorp Vault, AWS Secrets
Manager, etc.) for production environments.
:::
To mark a variable as secret, add `secret: true` to the variable definition:
```yaml
version: '3'
vars:
API_KEY:
value: 'sk-1234567890abcdef'
secret: true
tasks:
deploy:
cmds:
- curl -H "Authorization: {{.API_KEY}}" api.example.com
# Logged as: task: [deploy] curl -H "Authorization: *****" api.example.com
```
Secret variables work with all variable types:
::: code-group
```yaml [Simple Value]
version: '3'
vars:
PASSWORD:
value: 'my-secret-password'
secret: true
tasks:
connect:
cmds:
- psql -U user -p {{.PASSWORD}} mydb
# Logged as: psql -U user -p ***** mydb
```
```yaml [Shell Command]
version: '3'
vars:
DB_PASSWORD:
sh: vault read -field=password secret/db
secret: true
tasks:
migrate:
cmds:
- psql -U admin -p {{.DB_PASSWORD}} mydb
# Password from vault is masked in logs
```
```yaml [Task-Level Secret]
version: '3'
vars:
PUBLIC_URL: https://example.com
tasks:
deploy:
vars:
DEPLOY_TOKEN:
value: 'secret-token-123'
secret: true
cmds:
- echo "Deploying to {{.PUBLIC_URL}} with token {{.DEPLOY_TOKEN}}"
# Logged as: echo "Deploying to https://example.com with token *****"
```
:::
Multiple secrets in the same command are all masked:
```yaml
version: '3'
vars:
API_KEY:
value: 'api-key-123'
secret: true
PASSWORD:
value: 'password-456'
secret: true
tasks:
setup:
cmds:
- ./setup.sh --api {{.API_KEY}} --pwd {{.PASSWORD}}
# Logged as: ./setup.sh --api ***** --pwd *****
```
::: tip
**Best practices for secret variables:**
1. **Use shell commands to load secrets**, not hardcoded values:
```yaml
# ❌ BAD - Secret visible in Taskfile
vars:
API_KEY:
value: 'hardcoded-secret'
secret: true
# ✅ GOOD - Secret loaded from external source
vars:
API_KEY:
sh: vault kv get -field=api_key secret/myapp
secret: true
```
2. **Combine with environment variables:**
```yaml
vars:
API_KEY:
sh: echo $MY_API_KEY
secret: true
```
3. **Use .gitignore for secret files:**
If you use dotenv files, add them to `.gitignore`:
```yaml
dotenv: ['.env.local'] # Load from .env.local (in .gitignore)
```
:::
::: warning
**Secrets are not propagated to derived variables.** The `secret` flag only
masks the variable it is set on. A non-secret variable that references a secret
will expose the resolved value in logs:
```yaml
version: '3'
vars:
API_KEY:
value: 'secret-api-key-123'
secret: true
HEADER:
value: 'Bearer {{.API_KEY}}' # ❌ not marked as secret
tasks:
call:
cmds:
- curl -H "{{.HEADER}}" api.example.com
# Logged as: curl -H "Bearer secret-api-key-123" api.example.com (LEAK)
```
Mark every variable that carries a secret value as `secret: true`:
```yaml
vars:
HEADER:
value: 'Bearer {{.API_KEY}}'
secret: true # ✅ masked
```
:::
## Looping over values
Task allows you to loop over certain values and execute a command for each.

View File

@@ -385,6 +385,33 @@ vars:
ttl: 3600
```
### Secret Variables (`secret`)
Mark variables as secret to mask their values in command logs.
```yaml
vars:
API_KEY:
value: 'sk-1234567890abcdef'
secret: true # This variable will be masked in logs
DB_PASSWORD:
sh: vault read -field=password secret/db
secret: true # Works with dynamic variables too
```
When a variable is marked as `secret: true`, Task will replace its value with
`*****` in command logs. The actual command execution still receives the real
value.
::: info
For complete documentation on secret variables, including security
considerations and best practices, see the
[Secret variables](/docs/guide#secret-variables) section in the Guide.
:::
### Variable Ordering
Variables can reference previously defined variables:

View File

@@ -318,6 +318,13 @@
"map": {
"type": "object",
"description": "The value will be treated as a literal map type and stored in the variable"
},
"value": {
"description": "A literal value assigned to the variable. Useful together with other keys such as 'secret'"
},
"secret": {
"type": "boolean",
"description": "Marks the variable as secret. Secret values will be masked as ***** in command logs to prevent accidental exposure of sensitive information."
}
},
"additionalProperties": false