Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to access encrypted key value using reference (ref)

Hello,

I could not able to access the encrypted key value map using a variable. Below is the code I am using in the policy. Any help is appreciated.

NOT WORKING (Encrypted Key Value Map):

<Get assignTo="private.privKey">
<Key>
	<Parameter ref="privKey.variable"/>
</Key>
</Get>

privKey.variable is a custom variable which holds the key name (privKey).

privKey is the Key name and Value of the key is encrypted.


WORKING (NON Encrypted Key Value Map):

<Get assignTo="private.privKey">
<Key>
	<Parameter ref="privKey.variable"/>
</Key>
</Get>


WORKING (Encrypted Key Value Map):

<Get assignTo="private.privKey">
<Key>
	<Parameter>privKey</Parameter>
</Key>
</Get>


But the same code is working if the value is not encrypted.


Thank you!

Solved Solved
0 4 281
1 ACCEPTED SOLUTION

It's hard for me to know what's wrong, looking only at the fragments you are showing. Those look correct, as far as they go. But there are many other details, and if any of those other details are not correct, then you may see the behavior you do not understand, or behavior you are not expecting.

In particular,

  • if you use KVM Get or Put, using a large cache lifetime, then a KVM Get may retrieve the cached value, even if you have updated the value via the administrative UI or API.
  • if you use the incorrect mapName attribute.
  • if your key variable is not exactly as you expect.

My advice to you is to check through all the details carefully.

I've put together an example API proxy in case it helps. attached here. It does PUT and GET with fixed and variable (referenced) keys. It works as you would expect. (It depends on an encrypted KVM map named "secrets" in your environment)

apiproxy-kvm-try-20210419-174111.zip

example run:

$ curl -i -X POST $endpoint/kvm-try/fixed-key -d value=your-choice-here
HTTP/1.1 204 No Content
Date: Tue, 20 Apr 2021 00:38:29 GMT
Connection: keep-alive
apiproxy: kvm-try r5



$ curl -i -X GET $endpoint/kvm-try/key-variable
HTTP/1.1 200 OK
Date: Tue, 20 Apr 2021 00:38:36 GMT
Content-Type: text/plain
Content-Length: 16
Connection: keep-alive
apiproxy: kvm-try r5


your-choice-here


$ curl -i -X GET $endpoint/kvm-try/fixed-key
HTTP/1.1 200 OK
Date: Tue, 20 Apr 2021 00:38:41 GMT
Content-Type: text/plain
Content-Length: 16
Connection: keep-alive
apiproxy: kvm-try r5


your-choice-here


View solution in original post

4 REPLIES 4