Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on

Understanding oc extract vs. base64 --decode OpenShift

Navigating through OpenShift's command line? It's crucial to differentiate between oc extract and base64 --decode.
Lets use following secrets as an example,

oc get secret/htpasswd-fp844 -n openshift-config -o yaml
apiVersion: v1
data:
  htpasswd: YWRtaW46JDJ5JDA1JEJWTFlFOGhIOHJQZVhJWmxhTEtHLy5SZFJ2VzF6NFBXV0RicmZIRVFFN21TdEszekdzbGRtCmRlbW8xOiQyeSQwNSREd2hqMUJEZmllM2xaVlA2M3A1Mi9PeERzRnlrci9Jd2ViVnY5NzRNcy9EMmtNT2lOcnlhMgpkZW1vMzokMnkkMDUkb3F1dDB5VlNXQVRkU1NTWmVVOUxnT0czbUtaZi9lQWMzanRXdFdHS1ZhclpXQXd3aXpuQnUKZGVtbzU6JDJ5JDA1JENSR2ZKMmhiZkI4UzRBQ1FlMkU3Ty5QeWdSOGF3QTExSHlOSnVzOUdiVTRsWm9KOUFTU3Y2Cg==
kind: Secret
metadata:
  creationTimestamp: "2023-12-28T16:58:15Z"
  name: htpasswd-fp844
  namespace: openshift-config
  resourceVersion: "109355"
  uid: f1e48a7a-2d3e-4724-89a3-1e67127e7a98
type: Opaque
Enter fullscreen mode Exit fullscreen mode

πŸ” oc extract - Your go-to in OpenShift for pulling secrets or config maps straight from the cluster. It seamlessly decodes the content, making your life easier when dealing with TLS certificates, SSH keys, or configuration files. Think of it as the OpenShift whisperer for your hidden data!
Example,

oc extract secret/htpasswd-fp844 -n openshift-config --to=-
# htpasswd
admin:$2y$05$BVLYE8hH8rPeXIZlaLKG/.RdRvW1z4PWWDbrfHEQE7mStK3zGsldm
demo1:$2y$05$Dwhj1BDfie3lZVP63p52/OxDsFykr/IwebVv974Ms/D2kMOiNrya2
demo3:$2y$05$oqut0yVSWATdSSSZeU9LgOG3mKZf/eAc3jtWtWGKVarZWAwwiznBu
demo5:$2y$05$CRGfJ2hbfB8S4ACQe2E7O.PygR8awA11HyNJus9GbU4lZoJ9ASSv6
Enter fullscreen mode Exit fullscreen mode

Or if you simple do this,

oc extract secret/htpasswd-fp844 -n openshift-config
Enter fullscreen mode Exit fullscreen mode

It will create a file htpasswd with actual decoded content

πŸ’» base64 --decode - This general-purpose Unix command is your handy decoder ring. It's not specific to OpenShift but super useful when you have base64 encoded strings from any source, needing a quick reveal. You have to basically copy the output from secrets and decode it as follows,

$ echo "YWRtaW46JDJ5JDA1JEJWTFlFOGhIOHJQZVhJWmxhTEtHLy5SZFJ2VzF6NFBXV0RicmZIRVFFN21TdEszekdzbGRtCmRlbW8xOiQyeSQwNSREd2hqMUJEZmllM2xaVlA2M3A1Mi9PeERzRnlrci9Jd2ViVnY5NzRNcy9EMmtNT2lOcnlhMgpkZW1vMzokMnkkMDUkb3F1dDB5VlNXQVRkU1NTWmVVOUxnT0czbUtaZi9lQWMzanRXdFdHS1ZhclpXQXd3aXpuQnUKZGVtbzU6JDJ5JDA1JENSR2ZKMmhiZkI4UzRBQ1FlMkU3Ty5QeWdSOGF3QTExSHlOSnVzOUdiVTRsWm9KOUFTU3Y2Cg==" |base64 --decode

admin:$2y$05$BVLYE8hH8rPeXIZlaLKG/.RdRvW1z4PWWDbrfHEQE7mStK3zGsldm
demo1:$2y$05$Dwhj1BDfie3lZVP63p52/OxDsFykr/IwebVv974Ms/D2kMOiNrya2
demo3:$2y$05$oqut0yVSWATdSSSZeU9LgOG3mKZf/eAc3jtWtWGKVarZWAwwiznBu
demo5:$2y$05$CRGfJ2hbfB8S4ACQe2E7O.PygR8awA11HyNJus9GbU4lZoJ9ASSv6
Enter fullscreen mode Exit fullscreen mode

πŸ€” Main Differences? oc extract directly interacts with your cluster, while base64 --decode is more of a standalone decoder. Use oc extract for OpenShift-specific tasks, and base64 --decode for general decoding needs.

Top comments (0)