Skip to content

Commit fb9b2e1

Browse files
committed
BREAKING: Made --api-key enable TLS by default
1 parent 15f42ae commit fb9b2e1

5 files changed

Lines changed: 46 additions & 12 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
go run ./temporalcli/internal/cmd/gen-commands
5757
git diff --exit-code
5858
59-
- name: Test cloud
59+
- name: Test cloud mTLS
6060
if: ${{ matrix.cloudTestTarget && env.HAS_SECRETS == 'true' }}
6161
env:
6262
TEMPORAL_ADDRESS: ${{ vars.TEMPORAL_CLIENT_NAMESPACE }}.tmprl.cloud:7233
@@ -70,3 +70,20 @@ jobs:
7070
printf '%s\n' "$TEMPORAL_TLS_CERT_CONTENT" >> client.crt
7171
printf '%s\n' "$TEMPORAL_TLS_KEY_CONTENT" >> client.key
7272
go run ./cmd/temporal workflow list --limit 2
73+
74+
- name: Test cloud API key env var
75+
if: ${{ matrix.cloudTestTarget && env.HAS_SECRETS == 'true' }}
76+
env:
77+
TEMPORAL_ADDRESS: ${{ vars.TEMPORAL_CLIENT_NAMESPACE }}.tmprl.cloud:7233
78+
TEMPORAL_NAMESPACE: ${{ vars.TEMPORAL_CLIENT_NAMESPACE }}
79+
TEMPORAL_API_KEY: ${{ secrets.TEMPORAL_CLIENT_CLOUD_API_KEY }}
80+
shell: bash
81+
run: go run ./cmd/temporal workflow list --limit 2
82+
83+
- name: Test cloud API key arg
84+
if: ${{ matrix.cloudTestTarget && env.HAS_SECRETS == 'true' }}
85+
env:
86+
TEMPORAL_ADDRESS: ${{ vars.TEMPORAL_CLIENT_NAMESPACE }}.tmprl.cloud:7233
87+
TEMPORAL_NAMESPACE: ${{ vars.TEMPORAL_CLIENT_NAMESPACE }}
88+
shell: bash
89+
run: go run ./cmd/temporal workflow list --limit 2 --api-key ${{ secrets.TEMPORAL_CLIENT_CLOUD_API_KEY }}

temporalcli/client.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,10 @@ func (c *ClientOptions) dialClient(cctx *CommandContext) (client.Client, error)
139139
clientProfile.TLS.DisableHostVerification = c.TlsDisableHostVerification
140140
}
141141
}
142-
// In the past, the presence of API key CLI arg did not imply TLS like it
143-
// does with envconfig. Therefore if there is a user-provided API key and
144-
// TLS is not present, explicitly disable it so API key presence doesn't
145-
// enable it in ToClientOptions below.
146-
// TODO(cretz): Or do we want to break compatibility to have TLS defaulted
147-
// for all API keys?
148-
if c.ApiKey != "" && clientProfile.TLS == nil {
142+
143+
// If TLS is explicitly disabled, we turn it off. Otherwise it may be
144+
// implicitly enabled if API key or any other TLS setting is set.
145+
if cctx.CurrentCommand.Flags().Changed("tls") && !c.Tls {
149146
clientProfile.TLS = &envconfig.ClientConfigTLS{Disabled: true}
150147
}
151148

temporalcli/commands.config_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,24 @@ func TestConfig_Set(t *testing.T) {
372372
},
373373
all)
374374
}
375+
376+
func (s *SharedServerSuite) TestAPIKey_DefaultsTLS() {
377+
// A workflow list with an API key should fail because TLS is enabled by
378+
// default when --api-key is present
379+
res := s.Execute(
380+
"workflow", "count",
381+
"--address", s.Address(),
382+
"--api-key", "does-not-matter",
383+
)
384+
s.ErrorContains(res.Err, "tls")
385+
386+
// But it should succeed with TLS explicitly disabled
387+
res = s.Execute(
388+
"workflow", "count",
389+
"--address", s.Address(),
390+
"--api-key", "does-not-matter",
391+
"--tls=false",
392+
)
393+
s.NoError(res.Err)
394+
s.Contains(res.Stdout.String(), "Total")
395+
}

temporalcli/commands.gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (v *ClientOptions) buildFlags(cctx *CommandContext, f *pflag.FlagSet) {
4040
f.StringVarP(&v.Namespace, "namespace", "n", "default", "Temporal Service Namespace.")
4141
f.StringVar(&v.ApiKey, "api-key", "", "API key for request.")
4242
f.StringArrayVar(&v.GrpcMeta, "grpc-meta", nil, "HTTP headers for requests. Format as a `KEY=VALUE` pair. May be passed multiple times to set multiple headers. Can also be made available via environment variable as `TEMPORAL_GRPC_META_[name]`.")
43-
f.BoolVar(&v.Tls, "tls", false, "Enable base TLS encryption. Does not have additional options like mTLS or client certs. Unlike some other options, if this is present and set explicitly to false, it can still be overridden by config file or environment variables.")
43+
f.BoolVar(&v.Tls, "tls", false, "Enable base TLS encryption. Does not have additional options like mTLS or client certs. This is defaulted to true if api-key or any other TLS options are present. Use --tls=false to explicitly disable.")
4444
f.StringVar(&v.TlsCertPath, "tls-cert-path", "", "Path to x509 certificate. Can't be used with --tls-cert-data.")
4545
f.StringVar(&v.TlsCertData, "tls-cert-data", "", "Data for x509 certificate. Can't be used with --tls-cert-path.")
4646
f.StringVar(&v.TlsKeyPath, "tls-key-path", "", "Path to x509 private key. Can't be used with --tls-key-data.")

temporalcli/commandsgen/commands.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,9 +4026,8 @@ option-sets:
40264026
type: bool
40274027
description: |
40284028
Enable base TLS encryption. Does not have additional options like mTLS
4029-
or client certs. Unlike some other options, if this is present and set
4030-
explicitly to false, it can still be overridden by config file or
4031-
environment variables.
4029+
or client certs. This is defaulted to true if api-key or any other TLS
4030+
options are present. Use --tls=false to explicitly disable.
40324031
implied-env: TEMPORAL_TLS
40334032
- name: tls-cert-path
40344033
type: string

0 commit comments

Comments
 (0)