0

For security reasons, I need to renew the password field of a Secret in Openshift every 30 days, so my idea is to create a cronjob and execute a ocp command to remove the password field from that Secret, so after this, the password field is autogenerated with a new password. So I'm trying to edit a field from a Secret using the patch command but without success. This is what the help command shows regarding patch: patch help

and I tried the patch command like this:

oc patch secret test-secret -p '{"data":{"password":}}'

or

oc patch secret test-secret -p $'data:\n password: '

but I see this kind of errors:

Error from server (BadRequest): json: cannot unmarshal string into Go value of type map[string]interface {}
Error from server (NotFound): secrets "password:" not found
Error from server (NotFound): secrets "'" not found

Does anyone knows how to use the patch command to update the field of a ocp Secret?

Thanks!

Alvaro
  • 57
  • 1
  • 1
  • 7

1 Answers1

1
oc patch secret test-secret -p '{"data":{"password": ""}}'  
  • empty double quotes in place value for password will work.
Nataraj Medayhal
  • 980
  • 1
  • 2
  • 12
  • I tried that but this error is shown: error: unable to parse "'{data:{password:": yaml: found unexpected end of stream. – Alvaro Jun 29 '22 at 14:11
  • Trust the password field is there in the secret which you want patch. Also the one which you had pasted in latest one is not proper – Nataraj Medayhal Jun 29 '22 at 15:11
  • My problem was that I was using cmder to enter the ocp commands, after using git bash then the command works, thanks! – Alvaro Jun 29 '22 at 18:28