Skip to content

Instantly share code, notes, and snippets.

@sayan3296
Created April 21, 2023 16:28
Show Gist options
  • Save sayan3296/35b552b5b5f189c966452692d307cf61 to your computer and use it in GitHub Desktop.
Save sayan3296/35b552b5b5f189c966452692d307cf61 to your computer and use it in GitHub Desktop.
Mimic connection to pulp remote in pulp3 based on pulp_id of repos from core_remote
#!/bin/bash
remote_id=$1
if [ ! -z $remote_id ]
then
psql_core_remote() {
# the trailing sed: we need to replace null value output \N by empty string
su - postgres -c "psql pulpcore -c \"COPY (SELECT $1 FROM core_remote WHERE pulp_id = '${remote_id}') TO STDOUT;\"" | sed 's!^\\N$!!1'
}
else
exit 1
fi
## Collect data from DB
feed=$(psql_core_remote "url")
ssl_ca_cert=$(psql_core_remote "ca_cert")
ssl_client_cert=$(psql_core_remote "client_cert")
## Store certs in individual files.
echo -e "${ssl_ca_cert}" > /tmp/ssl_ca_cert.${remote_id}.crt
echo -e "${ssl_client_cert}" > /tmp/ssl_client_cert.${remote_id}.crt
PULP_SETTINGS=/etc/pulp/settings.py pulpcore-manager shell << EOF > /tmp/ssl_client_key.${remote_id}.crt
from pulp_rpm.app.models.repository import Remote
key = Remote.objects.get(pulp_id='$remote_id').client_key
print(key)
EOF
## Show and run command:
cmd="curl -L -vvv --cacert /tmp/ssl_ca_cert.${remote_id}.crt --cert /tmp/ssl_client_cert.${remote_id}.crt --key /tmp/ssl_client_key.${remote_id}.crt $feed/repodata/repomd.xml"
echo $cmd
$cmd
echo -e "\n\nShowing the CA details: \n\n"
awk -v cmd='openssl x509 -noout -subject -issuer -dates -fingerprint' ' /BEGIN/{close(cmd)};{print | cmd}' < /tmp/ssl_ca_cert.${remote_id}.crt
echo -e "\n\nShowing the signed cert details: \n\n"
awk -v cmd='openssl x509 -noout -subject -issuer -dates -fingerprint' ' /BEGIN/{close(cmd)};{print | cmd}' < /tmp/ssl_client_cert.${remote_id}.crt
echo -e "\n\n"
rct cat-cert /tmp/ssl_client_cert.${remote_id}.crt
echo -e "\n\nShowing the RHSM certguard CA details: \n\n"
echo "COPY(select ca_certificate from certguard_rhsmcertguard) TO STDOUT;" | su - postgres -c "psql pulpcore"| sed 's/\\n/\n/g' > /tmp/certguard_ca.pem
awk -v cmd='openssl x509 -noout -subject -issuer -dates -fingerprint' ' /BEGIN/{close(cmd)};{print | cmd}' < /tmp/certguard_ca.pem
echo -e "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment