@@ -32,10 +32,12 @@ import (
3232 "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
3333 "k8s.io/kubernetes/pkg/client/restclient"
3434
35+ "k8s.io/helm/pkg/helm"
3536 "k8s.io/helm/pkg/helm/helmpath"
3637 "k8s.io/helm/pkg/helm/portforwarder"
3738 "k8s.io/helm/pkg/kube"
3839 "k8s.io/helm/pkg/tiller/environment"
40+ "k8s.io/helm/pkg/tlsutil"
3941)
4042
4143const (
@@ -95,6 +97,11 @@ func newRootCmd(out io.Writer) *cobra.Command {
9597 Short : "The Helm package manager for Kubernetes." ,
9698 Long : globalUsage ,
9799 SilenceUsage : true ,
100+ PersistentPreRun : func (cmd * cobra.Command , args []string ) {
101+ tlsCaCertFile = os .ExpandEnv (tlsCaCertFile )
102+ tlsCertFile = os .ExpandEnv (tlsCertFile )
103+ tlsKeyFile = os .ExpandEnv (tlsKeyFile )
104+ },
98105 PersistentPostRun : func (cmd * cobra.Command , args []string ) {
99106 teardown ()
100107 },
@@ -120,21 +127,21 @@ func newRootCmd(out io.Writer) *cobra.Command {
120127 newVerifyCmd (out ),
121128
122129 // release commands
123- newDeleteCmd (nil , out ),
124- newGetCmd (nil , out ),
125- newHistoryCmd (nil , out ),
126- newInstallCmd (nil , out ),
127- newListCmd (nil , out ),
128- newRollbackCmd (nil , out ),
129- newStatusCmd (nil , out ),
130- newUpgradeCmd (nil , out ),
130+ addFlagsTLS ( newDeleteCmd (nil , out ) ),
131+ addFlagsTLS ( newGetCmd (nil , out ) ),
132+ addFlagsTLS ( newHistoryCmd (nil , out ) ),
133+ addFlagsTLS ( newInstallCmd (nil , out ) ),
134+ addFlagsTLS ( newListCmd (nil , out ) ),
135+ addFlagsTLS ( newRollbackCmd (nil , out ) ),
136+ addFlagsTLS ( newStatusCmd (nil , out ) ),
137+ addFlagsTLS ( newUpgradeCmd (nil , out ) ),
131138
132139 newCompletionCmd (out ),
133140 newHomeCmd (out ),
134141 newInitCmd (out ),
135- newResetCmd (nil , out ),
136- newVersionCmd (nil , out ),
137- newReleaseTestCmd (nil , out ),
142+ addFlagsTLS ( newResetCmd (nil , out ) ),
143+ addFlagsTLS ( newVersionCmd (nil , out ) ),
144+ addFlagsTLS ( newReleaseTestCmd (nil , out ) ),
138145
139146 // Hidden documentation generator command: 'helm docs'
140147 newDocsCmd (out ),
@@ -229,7 +236,9 @@ func defaultHelmHome() string {
229236}
230237
231238func homePath () string {
232- return os .ExpandEnv (helmHome )
239+ s := os .ExpandEnv (helmHome )
240+ os .Setenv (homeEnvVar , s )
241+ return s
233242}
234243
235244func defaultHelmHost () string {
@@ -262,3 +271,49 @@ func getKubeClient(context string) (*restclient.Config, *internalclientset.Clien
262271func getKubeCmd (context string ) * kube.Client {
263272 return kube .New (kube .GetConfig (context ))
264273}
274+
275+ // ensureHelmClient returns a new helm client impl. if h is not nil.
276+ func ensureHelmClient (h helm.Interface ) helm.Interface {
277+ if h != nil {
278+ return h
279+ }
280+ return newClient ()
281+ }
282+
283+ func newClient () helm.Interface {
284+ options := []helm.Option {helm .Host (tillerHost )}
285+
286+ if tlsVerify || tlsEnable {
287+ tlsopts := tlsutil.Options {KeyFile : tlsKeyFile , CertFile : tlsCertFile , InsecureSkipVerify : true }
288+ if tlsVerify {
289+ tlsopts .CaCertFile = tlsCaCertFile
290+ tlsopts .InsecureSkipVerify = false
291+ }
292+ tlscfg , err := tlsutil .ClientConfig (tlsopts )
293+ if err != nil {
294+ fmt .Fprintln (os .Stderr , err )
295+ os .Exit (2 )
296+ }
297+ options = append (options , helm .WithTLS (tlscfg ))
298+ }
299+ return helm .NewClient (options ... )
300+ }
301+
302+ // addFlagsTLS adds the flags for supporting client side TLS to the
303+ // helm command (only those that invoke communicate to Tiller.)
304+ func addFlagsTLS (cmd * cobra.Command ) * cobra.Command {
305+ // defaults
306+ var (
307+ tlsCaCertDefault = "$HELM_HOME/ca.pem"
308+ tlsCertDefault = "$HELM_HOME/cert.pem"
309+ tlsKeyDefault = "$HELM_HOME/key.pem"
310+ )
311+
312+ // add flags
313+ cmd .Flags ().StringVar (& tlsCaCertFile , "tls-ca-cert" , tlsCaCertDefault , "path to TLS CA certificate file" )
314+ cmd .Flags ().StringVar (& tlsCertFile , "tls-cert" , tlsCertDefault , "path to TLS certificate file" )
315+ cmd .Flags ().StringVar (& tlsKeyFile , "tls-key" , tlsKeyDefault , "path to TLS key file" )
316+ cmd .Flags ().BoolVar (& tlsVerify , "tls-verify" , false , "enable TLS for request and verify remote" )
317+ cmd .Flags ().BoolVar (& tlsEnable , "tls" , false , "enable TLS for request" )
318+ return cmd
319+ }
0 commit comments