---
# System prepended metadata

title: Approve CSR openshift

---

# Approve CSR openshift

```
#!/bin/bash

# Run the 'oc get csr' command and capture the output
csr_output=$(oc get csr)

# Extract the CSR names with pending status using awk
csr_names=($(echo "$csr_output" | awk '/Pending/ {print $1}'))

# Iterate over the CSR names
for csr_name in "${csr_names[@]}"; do
    echo "Pending CSR: $csr_name"
done

for csr_name in "${csr_names[@]}"; do
    echo "CSR: $csr_name approval"
    oc adm certificate approve $csr_name
    echo "CSR: $csr_name approved"
done

echo $(oc get csr | awk '/Pending/ {print $1}')
```

list all certs:

```
echo -e "NAMESPACE\tNAME\tEXPIRY" && oc get secrets -A -o go-template='{{range .items}}{{if eq .type "kubernetes.io/tls"}}{{.metadata.namespace}}{{" "}}{{.metadata.name}}{{" "}}{{index .data "tls.crt"}}{{"\n"}}{{end}}{{end}}' | while read namespace name cert; do echo -en "$namespace\t$name\t"; echo $cert | base64 -d | openssl x509 -noout -enddate; done | column -t
```