Merge pull request #13192 from cli/wm/no-alias-telemetry

Do not send telemetry for aliases
This commit is contained in:
William Martin 2026-04-17 14:40:22 +02:00 committed by GitHub
commit 451d399eac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 10 deletions

View file

@ -0,0 +1,18 @@
# Aliases should not leak their user-defined names via telemetry, but the
# resolved inner command should still record normally — its path is a core
# gh command and conveys no user-authored identifier.
env GH_PRIVATE_ENABLE_TELEMETRY=1
env GH_TELEMETRY=log
env GH_TELEMETRY_SAMPLE_RATE=100
# Create a regular (non-shell) alias that resolves to an existing command.
exec gh alias set secret-project-alias version
# Invoking the alias must not produce any event carrying the alias name.
exec gh secret-project-alias
! stderr 'secret-project-alias'
# The resolved inner command still records telemetry as normal.
stderr 'Telemetry payload:'
stderr '"command": "gh version"'

View file

@ -10,6 +10,7 @@ import (
"github.com/cli/cli/v2/internal/run"
"github.com/cli/cli/v2/internal/text"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/findsh"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
@ -17,7 +18,7 @@ import (
)
func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: aliasName,
Short: fmt.Sprintf("Shell alias for %q", text.Truncate(80, aliasValue)),
RunE: func(c *cobra.Command, args []string) error {
@ -39,16 +40,19 @@ func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *co
}
return nil
},
GroupID: "alias",
Annotations: map[string]string{
"skipAuthCheck": "true",
},
GroupID: "alias",
DisableFlagParsing: true,
}
cmdutil.DisableAuthCheck(cmd)
// Aliases are user-defined names and must not be reported as telemetry
// dimensions, since the name itself may be sensitive (e.g. project or
// organization names).
cmdutil.DisableTelemetry(cmd)
return cmd
}
func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: aliasName,
Short: fmt.Sprintf("Alias for %q", text.Truncate(80, aliasValue)),
RunE: func(c *cobra.Command, args []string) error {
@ -60,12 +64,15 @@ func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.C
root.SetArgs(expandedArgs)
return root.Execute()
},
GroupID: "alias",
Annotations: map[string]string{
"skipAuthCheck": "true",
},
GroupID: "alias",
DisableFlagParsing: true,
}
cmdutil.DisableAuthCheck(cmd)
// Aliases are user-defined names and must not be reported as telemetry
// dimensions, since the name itself may be sensitive (e.g. project or
// organization names).
cmdutil.DisableTelemetry(cmd)
return cmd
}
// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.