77 "context"
88 "encoding/json"
99 "fmt"
10+ "strings"
1011 "time"
1112
1213 porterv1 "get.porter.sh/operator/api/v1"
@@ -38,8 +39,8 @@ var _ = Describe("Porter using default secrets plugin config", func() {
3839 installationName := fmt .Sprintf ("default-plugin-%v" , randId )
3940 ns := createTestNamespace (context .Background ())
4041 ctx := context .Background ()
41- createSecret (ns , secrets .SecretDataKey , "password" , "test" )
42- credSet := NewCredSet ("test" , "insecureValue" , "password" )
42+ createSecret (ns , secrets .SecretDataKey , "cred- password" , "test" )
43+ credSet := NewCredSet ("test" , "insecureValue" , "cred- password" )
4344 agentAction := createCredentialSetAgentAction (ns , credSet )
4445 pollAA := func () bool { return agentActionPoll (agentAction ) }
4546 Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
@@ -64,8 +65,8 @@ var _ = Describe("Porter using default secrets plugin config", func() {
6465 installationName := fmt .Sprintf ("default-plugin-%v" , randId )
6566 installationNs := createTestNamespace (ctx )
6667 secretsNs := createTestNamespace (ctx )
67- createSecret (secretsNs , secrets .SecretDataKey , "password" , "test" )
68- credSet := NewCredSet ("test" , "insecureValue" , "password" )
68+ createSecret (secretsNs , secrets .SecretDataKey , "cred- password" , "test" )
69+ credSet := NewCredSet ("test" , "insecureValue" , "cred- password" )
6970 agentAction := createCredentialSetAgentAction (installationNs , credSet )
7071 pollAA := func () bool { return agentActionPoll (agentAction ) }
7172 Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
@@ -89,8 +90,8 @@ var _ = Describe("Porter using default secrets plugin config", func() {
8990 ctx := context .Background ()
9091 installationName := fmt .Sprintf ("default-plugin-%v" , randId )
9192 installationNs := createTestNamespace (ctx )
92- createSecret (installationNs , "invalidKey" , "password" , "test" )
93- credSet := NewCredSet ("test" , "insecureValue" , "password" )
93+ createSecret (installationNs , "invalidKey" , "cred- password" , "test" )
94+ credSet := NewCredSet ("test" , "insecureValue" , "cred- password" )
9495 agentAction := createCredentialSetAgentAction (installationNs , credSet )
9596 pollAA := func () bool { return agentActionPoll (agentAction ) }
9697 Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
@@ -119,13 +120,13 @@ var _ = Describe("Porter using a secrets plugin config that doesn't specify the
119120 defaultSecretsCfgName := "kubernetes-secrets"
120121 ns := createTestNamespace (context .Background ())
121122 ctx := context .Background ()
122- createSecret (ns , secrets .SecretDataKey , "password" , "test" )
123+ createSecret (ns , secrets .SecretDataKey , "cred- password" , "test" )
123124 porterCfg := NewPorterConfig (ns )
124125 k8sSecretsCfg := NewSecretsPluginConfig (defaultSecretsCfgName , nil )
125126 SetPorterConfigSecrets (porterCfg , k8sSecretsCfg )
126127 porterCfg .Spec .DefaultSecrets = pointer .String (defaultSecretsCfgName )
127128 Expect (k8sClient .Create (context .Background (), porterCfg )).Should (Succeed ())
128- credSet := NewCredSet ("test" , "insecureValue" , "password" )
129+ credSet := NewCredSet ("test" , "insecureValue" , "cred- password" )
129130 agentAction := createCredentialSetAgentAction (ns , credSet )
130131 pollAA := func () bool { return agentActionPoll (agentAction ) }
131132 Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
@@ -158,15 +159,15 @@ var _ = Describe("Porter using secrets plugin configured using same namespace as
158159 installationName := fmt .Sprintf ("porter-hello-%v" , randId )
159160 ns := createTestNamespace (context .Background ())
160161 ctx := context .Background ()
161- createSecret (ns , secrets .SecretDataKey , "password" , "test" )
162+ createSecret (ns , secrets .SecretDataKey , "cred- password" , "test" )
162163 defaultSecretsCfgName := "kubernetes-secrets"
163164 porterCfg := NewPorterConfig (ns )
164165 secretsNamespaceCfg := & SecretsConfig {Namespace : ns }
165166 k8sSecretsCfg := NewSecretsPluginConfig (defaultSecretsCfgName , secretsNamespaceCfg )
166167 SetPorterConfigSecrets (porterCfg , k8sSecretsCfg )
167168 porterCfg .Spec .DefaultSecrets = pointer .String (defaultSecretsCfgName )
168169 Expect (k8sClient .Create (context .Background (), porterCfg )).Should (Succeed ())
169- credSet := NewCredSet ("test" , "insecureValue" , "password" )
170+ credSet := NewCredSet ("test" , "insecureValue" , "cred- password" )
170171 agentAction := createCredentialSetAgentAction (ns , credSet )
171172 pollAA := func () bool { return agentActionPoll (agentAction ) }
172173 Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
@@ -184,6 +185,53 @@ var _ = Describe("Porter using secrets plugin configured using same namespace as
184185 validateInstallStatus (inst , porterv1 .PhaseSucceeded )
185186 })
186187 })
188+
189+ When ("applying an Installation with a sensitive parameter in the Installation namespace" , func () {
190+ It ("successfully installs" , func () {
191+ By ("storing secrets in the kubernetes secret" )
192+ randId := uuid .New ()
193+ installationName := fmt .Sprintf ("porter-hello-secret-%v" , randId )
194+ ns := createTestNamespace (context .Background ())
195+ ctx := context .Background ()
196+ createSecret (ns , secrets .SecretDataKey , "cred-test" , "test" )
197+ defaultSecretsCfgName := "kubernetes-secrets"
198+ porterCfg := NewPorterConfig (ns )
199+ secretsNamespaceCfg := & SecretsConfig {Namespace : ns }
200+ k8sSecretsCfg := NewSecretsPluginConfig (defaultSecretsCfgName , secretsNamespaceCfg )
201+ SetPorterConfigSecrets (porterCfg , k8sSecretsCfg )
202+ porterCfg .Spec .DefaultSecrets = pointer .String (defaultSecretsCfgName )
203+ Expect (k8sClient .Create (context .Background (), porterCfg )).Should (Succeed ())
204+ credSet := NewCredSet ("test" , "insecureValue" , "cred-test" )
205+ agentAction := createCredentialSetAgentAction (ns , credSet )
206+ pollAA := func () bool { return agentActionPoll (agentAction ) }
207+ Eventually (pollAA , time .Second * 120 , time .Second * 3 ).Should (BeTrue ())
208+ inst := NewInstallation (installationName , ns )
209+ inst .Spec .Parameters = runtime.RawExtension {Raw : []byte ("{\" delay\" : \" 1\" , \" exitStatus\" : \" 0\" , \" password\" : \" super-secret\" }" )}
210+ Expect (k8sClient .Create (ctx , inst )).Should (Succeed ())
211+
212+ // Wait for the job to be created
213+ installations := waitForInstallationStarted (ctx , ns , installationName )
214+ installation := installations .Items [0 ]
215+
216+ // Validate that the job succeeded
217+ installation = waitForInstallationFinished (ctx , installation )
218+
219+ // Validate that the installation status was updated
220+ validateInstallStatus (inst , porterv1 .PhaseSucceeded )
221+ secretList := & corev1.SecretList {}
222+ Expect (k8sClient .List (ctx , secretList , client .InNamespace (ns ))).Should (Succeed ())
223+ var found bool
224+ for _ , s := range secretList .Items {
225+ if ! strings .Contains (s .ObjectMeta .Name , "password" ) {
226+ continue
227+ }
228+ if value , ok := s .Data [secrets .SecretDataKey ]; ok {
229+ found = string (value ) == "super-secret"
230+ }
231+ }
232+ Expect (found ).Should (BeTrue ())
233+ })
234+ })
187235})
188236
189237var _ = Describe ("Porter k8s secrets plugin configured using a different namespace than the Installation resource" , func () {
@@ -195,7 +243,7 @@ var _ = Describe("Porter k8s secrets plugin configured using a different namespa
195243 installNamespace := createTestNamespace (context .Background ())
196244 secretNamespace := createTestNamespace (context .Background ())
197245 ctx := context .Background ()
198- var defaultSecretsCfgName , secretName , secretValue , credSetName = "kubernetes-secrets" , "password" , "test" , "test"
246+ var defaultSecretsCfgName , secretName , secretValue , credSetName = "kubernetes-secrets" , "cred- password" , "test" , "test"
199247 createSecret (secretNamespace , secrets .SecretDataKey , secretName , secretValue )
200248 porterCfg := NewPorterConfig (installNamespace )
201249 secretsNamespaceCfg := & SecretsConfig {Namespace : secretNamespace }
@@ -256,8 +304,8 @@ func NewInstallation(installationName, installationNamespace string) *porterv1.I
256304 Name : installationName ,
257305 Namespace : installationNamespace ,
258306 Bundle : porterv1.OCIReferenceParts {
259- Repository : "ghcr.io/bdegeeter/porter- test-me " ,
260- Version : "0.2 .0" ,
307+ Repository : "ghcr.io/getporter/ test/kubernetes-plugin " ,
308+ Version : "0.1 .0" ,
261309 },
262310 Parameters : runtime.RawExtension {Raw : []byte ("{\" delay\" : \" 1\" , \" exitStatus\" : \" 0\" }" )},
263311 CredentialSets : []string {"test" },
0 commit comments