0

I'm trying to create a script that retreives a secret from a keepass database. The script uses Expect to get secret via the keepass cli. Here after my script:

 #!/bin/bash

 set +x

 entry="$1"
 keepass_password="azerty"
 keepass_db="canadaplatfomsecretsdb.kdbx"
 keepass_entry_dir="canadaplatfomsecretsdb/k8s-enabling"
 kubesecretname="artifactoryregcred"
 kubenamespace="dev"


echo -e "\n"
echo "Connecting to keepass Database..."

function get_creds {
  expect -d <<EOF
     set timeout 10
     match_max 100000000
     spawn kpcli
     expect  "kpcli:/>"
     send    "open $keepass_db\n"
     expect  "password:"
     send    "$keepass_password\n"
     expect  ">"
     send    "cd $keepass_entry_dir\n"
     expect  "k8s-enabling>"
     send    "show -f $entry\n"
     expect  ">"
EOF

}
  
credentials=$(get_creds)

Here after the output form the gitlab-ci job logs

$ bash getcredsfromkeepass.sh ${entry}
Connecting to keepass Database...
expect version 5.45.4
argv[0] = expect  argv[1] = -d  
set argc 0
set argv0 "expect"
set argv ""
executing commands from command file
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {3855}
expect: does "" (spawn_id exp3) match glob pattern "kpcli:/>"? no
expect: does "No usable Term::ReadLine::* modules found.\r\nThis list was tried:\r\n * Term::ReadLine::Gnu\r\n * Term::ReadLine::Perl\r\n * Term::ReadLine::Perl5\r\nFor more information, read the documentation: perldoc kpcli\r\n" (spawn_id exp3) match glob pattern "kpcli:/>"? no
expect: read eof
expect: set expect_out(spawn_id) "exp3"

What is causing the problem and how can it be fixed?

starball
  • 20,030
  • 7
  • 43
  • 238
MScastra
  • 1
  • 1
  • kpcli cannot start properly because the require perl modules are not found. – glenn jackman Mar 15 '22 at 15:03
  • Hello, i have already installed all the dependencies in the docker image. The docker image is fine, when i start the container locally and run the script from inside the container it works. Only on gitlab-ci it is not working. – MScastra Mar 16 '22 at 01:01

0 Answers0