<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Palo Alto Networks | Breek Een Been</title>
    <link>https://blog.breekeenbeen.nl/tag/palo-alto-networks/</link>
      <atom:link href="https://blog.breekeenbeen.nl/tag/palo-alto-networks/index.xml" rel="self" type="application/rss+xml" />
    <description>Palo Alto Networks</description>
    <generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>Rob Maas</copyright><lastBuildDate>Sat, 25 Mar 2023 13:03:12 +0100</lastBuildDate>
    <image>
      <url>https://blog.breekeenbeen.nl/images/icon_hue0c3a5851739ca8a2afc787728ee763e_182872_512x512_fill_lanczos_center_3.png</url>
      <title>Palo Alto Networks</title>
      <link>https://blog.breekeenbeen.nl/tag/palo-alto-networks/</link>
    </image>
    
    <item>
      <title>Automate Export certificates and keys from Kubernetes and import in Palo Alto Networks</title>
      <link>https://blog.breekeenbeen.nl/post/automate-export-of-certificates-from-k8s-and-import-in-palo-alto-networks/</link>
      <pubDate>Sat, 25 Mar 2023 13:03:12 +0100</pubDate>
      <guid>https://blog.breekeenbeen.nl/post/automate-export-of-certificates-from-k8s-and-import-in-palo-alto-networks/</guid>
      <description>&lt;p&gt;In my precious post I explained how to export certificates and keys from Kubernetes and how to set a password on the key file for import in Palo Alto Networks (by hand). Since I&amp;rsquo;ve several services running on Kubernetes, all with there own certificate and key. I wanted to automate this process. This is good practice, especially since the certificates are relatively short lived, which means I need to renew the certificates on the firewall at least every 90 days. The first step I did was creating a bash script that would take care of this.&lt;/p&gt;
&lt;p&gt;I know I&amp;rsquo;ve hardcoded the passphrase on the certificate key, for this temporarily solution this is fine. I can delete all &lt;code&gt;crt&lt;/code&gt; and &lt;code&gt;key&lt;/code&gt; files after the import.&lt;/p&gt;
&lt;p&gt;Next step is of course to see if I can automate this when a certificate is renewed. The &lt;code&gt;watch&lt;/code&gt; command could help with this.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-bash&#34;&gt;#!/bin/bash
#
# Description: Get all certificates from all namespaces and import them into the Palo Alto Networks firewall
# Uses: awk, kubectl, openssl

FW_HOST=&amp;quot;1.2.3.4&amp;quot;
API_KEY=&amp;quot;VERYSECRETAPIKEY&amp;quot;

while read ns cert
do 
    echo &amp;quot;retrieving: $ns $cert&amp;quot;
    # Get the certificate and key from the secret
    kubectl get secrets -n $ns $cert -o json | jq -r &#39;.data.&amp;quot;tls.crt&amp;quot;&#39; | base64 -d &amp;gt; $cert.crt
    kubectl get secrets -n $ns $cert -o json | jq -r &#39;.data.&amp;quot;tls.key&amp;quot;&#39; | base64 -d &amp;gt; $cert.key
    # Set the password for the key - This is required for the import on the Palo Alto Networks firewall
    openssl rsa -aes256 -in $cert.key -out $cert.key -passout &amp;quot;pass:P@ssw0rd!&amp;quot; 
    # Import the certificate and key into the Palo Alto Networks firewall
    curl -k -X POST -F &amp;quot;file=@$cert.crt&amp;quot; &amp;quot;https://$FW_HOST/api/?key=$API_KEY&amp;amp;type=import&amp;amp;category=certificate&amp;amp;certificate-name=$cert&amp;amp;format=pem&amp;quot;
    curl -k -X POST -F &amp;quot;file=@$cert.key&amp;quot; &amp;quot;https://$FW_HOST/api/?key=$API_KEY&amp;amp;type=import&amp;amp;category=private-key&amp;amp;certificate-name=$cert&amp;amp;format=pem&amp;amp;passphrase=P@ssw0rd!&amp;quot;
done &amp;lt; &amp;lt;(kubectl get certificates -A -o custom-columns=NAMESPACE:.metadata.namespace,SECRET:.spec.secretName --no-headers --sort-by=.metadata.namespace | awk &#39;{print $1 &amp;quot; &amp;quot; $2}&#39;)
&lt;/code&gt;&lt;/pre&gt;
</description>
    </item>
    
  </channel>
</rss>
