SSH authentication with gitfn_clone (SAS function) - sas

I'm looking to set up a batch process using a github deploy key.
Registering a key using any of the following:
ssh-keygen
ssh-keygen -t rsa -b 4096
ssh-keygen -t rsa -b 4096 -E sha512
And running the following code:
%let dirOut = %sysfunc(pathname(work))/package;
data _null_;
rc=GITFN_CLONE(
"git#github.com:allanbowe/sasjscore.git",
"&dirOut",
"git",
"",
"/home/sasjssrv/.ssh/id_rsa.pub",
"/home/sasjssrv/.ssh/id_rsa"
);
put rc=;
run;
Results in:
ERROR: Return code from GIT is (23). ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
The following algorithms:
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519
ssh-keygen -t ed25519 -C "mygithubemail#provider.com"
ssh-keygen -t rsa -b 2048 -E sha512
Return -3 from gitfn_clone() with the following message:
ERROR: Failed to authenticate with the remote repository.
A regular git clone works fine with ALL of the keys:
git clone git#github.com:allanbowe/sasjscore.git
Cloning into 'sasjscore'...
warning: You appear to have cloned an empty repository.
I also tried with git_clone() (after noticing gitfn_clone() was deprecated) but, same result.
Any ideas?
55 %put %sysfunc(GIT_VERSION()) &=sysvlong &=sysscp;
0.27 SYSVLONG=9.04.01M7P080520 SYSSCP=LIN X64
Running Centos 7 as described here.

The issue is the use of an older version of GIT in 9.4m7. This should be fixed in 9.4m8, and is already fixed in Viya 4.
Thanks to the support of several internal SAS employees (you know who you are!) I can document TWO steps to address.
The first - to fix in m7 - just apply the following two hotfixes:
I9R087
I9R088
Then, regenerate using an appropriate cypher, eg: ssh-keygen -t ecdsa -b 521 and add that public key to github.
The second approach, which I didn't get round to trying as it would have meant creating a new github account, was to use OpenAuth Access Tokens. More information on that here and here.
Many thanks, Danny / Alexey / David!
EDIT - further to #joe's comment, I provide the logs from the hotfixes (/opt/sas9/SASHome/InstallMisc/InstallLogs):
base_lax_9.4_M7_HFI9R087_en_Install_preexec.log:
Installation Date 17/10/22 15:36 / User ID sasinstaller / IP Address 44.44.44.44 / Host CentOS-79-64-minimal
Skipped Files
There were no files to be processed.
Added Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so.1.0.1
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so
Backup Files
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R087/SASHome/en/SASFoundation/9.4/sasexe/libssh2.so.1
Changed Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so.1
Removed Files
There were no files to be processed.
base_lax_9.4_M7_HFI9R087_en_Install_postexec.log:
Installation Date 17/10/22 15:37 / User ID sasinstaller / IP Address 44.44.44.44 / Host CentOS-79-64-minimal
Added Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so.1.0.1
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so
Backup Files
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R087/SASHome/en/SASFoundation/9.4/sasexe/libssh2.so.1
Changed Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/libssh2.so.1
/opt/sas9/SASHome/SASFoundation/9.4/sasv9.cfg
Removed Files
There were no files to be processed.
base_lax_9.4_M7_HFI9R088_en_Install_preexec.log :
Installation Date 17/10/22 15:36 / User ID sasinstaller / IP Address 44.44.44.44 / Host CentOS-79-64-minimal
Skipped Files
There were no files to be processed.
Added Files
There were no files to be processed.
Backup Files
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugitfn
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_f
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_v
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_i
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_c
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_s
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_b
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_r
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_d
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_p
Changed Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugitfn
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_f
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_v
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_i
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_c
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_s
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_b
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_r
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_d
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_p
Removed Files
There were no files to be processed.
And /opt/sas9/SASHome/InstallMisc/InstallLogs/base_lax_9.4_M7_HFI9R088_en_Install_postexec.log:
Installation Date 17/10/22 15:37 / User ID sasinstaller / IP Address 44.44.44.44 / Host CentOS-79-64-minimal
Added Files
There were no files to be processed.
Backup Files
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugitfn
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_f
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_v
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_i
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_c
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_s
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_b
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_r
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_d
/opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R088/SASHome/en/SASFoundation/9.4/sasexe/uwugit_p
Changed Files
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugitfn
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_f
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_v
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_i
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_c
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_s
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_b
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_r
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_d
/opt/sas9/SASHome/SASFoundation/9.4/sasexe/uwugit_p
/opt/sas9/SASHome/SASFoundation/9.4/sasv9.cfg
Removed Files
There were no files to be processed.
After searching a bit harder I found this (showing only the extract due to log size) in file IT_2022-10-17-16.17.52.log:
2022-10-17 16:22:43 Controller - Marshalling deployment.xml to /opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R005/Metadata/en/deployment.xml
2022-10-17 16:22:43 InstallationTask - All constrainBy tests met: true
2022-10-17 16:22:43 EntryData - backed up /opt/sas9/SASHome/SASFoundation/9.4/sasexe/libgit2.so to /opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R005/SASHome/en/SASFoundation/9.4/sasexe/libgit2.so
2022-10-17 16:22:43 InstallationTask - sasexe/libgit2.so (0 bytes) has been successfully Backed up
2022-10-17 16:22:43 InstallationTask - sasexe/libgit2.so (1180370 bytes) has been successfully Changed
2022-10-17 16:22:43 ExtractTask - Created uninstall zip metadata at /opt/sas9/SASHome/SASFoundation/9.4/installs/base_lax_9.4_M7_HFI9R005/Metadata/en/en_sasexe.xml
So - it would seem, the answer is yes!
EDIT 2 - further feedback (thanks, Sundaresh) has shown that the -m PEM option can avoid the git (23) error, eg:
ssh-keygen -t ecdsa -b 256 -m PEM -C "you#mail.com"

Related

How to back up and restore drupal 8 site?

I follow the below steps to back up and restore drupal 7 site.
1) On the source server, upload the backup and migrate module
2) On the source server, take a backup of the database using the back up and migrate module
3) Copy all the site files - Drupal core, modules, themes, and your files folder, and migrate them to the target server in the exact same folder structure as the source server.
4) After that, delete settings.php, and make a copy default.settings.php called settings.php
5) Install Drupal as a new installation on the target server
6) Enable the backup and migrate module on the target server
7) Use the B&M module to import the database backup from step 2
I did follow the same steps to backup and restore in drupal 8 but I am running into issues. Does the backup and restore site in drupal 8 work the same way?
More or less.
Maybe could more simple if you have a backup copy.
If you can create a backup before, using drush, it will be the best way.
So assuming you have a backup copy
From the linux command line, change to the directory where we want to restore our Drupal project.
to create the database in the system:
$ mysqladmin -u [username] -h [host] -p create [database]
so the copy of the database will restored from the .sql file that you generated when you backed up:
$ mysql -u [username] -h [host] -p [database]
Set the database password.
next go to the rigth directory
cd /folder/site/drupal
and unzip the site in the righ place where you need it.
$ tar -xzvf /folder/where/create/backup/filename-backup.tar.gz -C / folder / site / drupal

gitlab CI : Error loading key : invalid format

I'm stuck with this problem since 2 days.
Tried with id_rsa.pub and id_rsa from my production server, still the same error...
SSH_PRIVATE_KEY is a variable I created in the CI/CD Settings on GitLab.
edit : not protected, not masked.
# This file is a template, and might need editing before it works on your project.
# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:alpine
stages:
- deploy
deploy:
stage: deploy
before_script:
# Install ssh-agent if not already installed, it is required by Docker.
# (change apt-get to yum if you use a CentOS-based image)
- 'which ssh-agent || ( apk add --update openssh )'
# Add bash
- apk add --update bash
# Add git
- apk add --update git
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- echo "$SSH_PRIVATE_KEY"
- echo "$SSH_PRIVATE_KEY" | ssh-add -
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
script:
- npm i -g pm2
- pm2 deploy ecosystem.config.js production
only:
- master
And when I run the pipeline, I still get this error...
$ echo "$SSH_PRIVATE_KEY" | ssh-add -
Error loading key "(stdin)": invalid format
Could you please help ? I'm helpless, clueless, hopeless loading...
Thanks very much !
SSH_PRIVATE_KEY is a variable I created in the CI/CD Settings on GitLab.
This is documented here
in the Value field paste the content of your private key that you created earlier.
So make sure you have pasted the id_rsa full content, including -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- (with 5 final -)
(And, as MrDuk comments, a final newline)
Stephane Paquet adds in the comments:
cat ~/.ssh/id_rsa | pbcopy
to make sure you copy all the required information.
Just as an FYI for anyone else doing this, I had the same problem but had missed the final dash off the END RSA PRIVATE KEY section. It must have 5 dashes as the dividers, apparently.
Also just as an FYI, my issue was that my SSH key was an OpenSSH format key (ex. -----BEGIN OPENSSH PRIVATE KEY-----) instead of a PEM format key (-----BEGIN RSA PRIVATE KEY-----), if you want instructions on how to convert an OpenSSH key to a PEM key you can find the answer here: Openssh Private Key to RSA Private Key
My solution was to change CI/CD Variable type from Variable to File.
And instead of sourcing from the variable, did the sourcing from the file where SSH_PRIVATE_KEY is pointing
chmod 600 $SSH_PRIVATE_KEY
ssh-add $SSH_PRIVATE_KEY

Define CA Info at Compile Time for libcurl

I have built libcurl for Windows x64 with OpenSSL. If I specify the CA Info with the libcurl command as shown below I am able to post my data via https.
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, "C:\\cacert.pem");
My question is regards to option 3 under the heading “Certificate Verification” found here: https://curl.haxx.se/docs/sslcerts.html
3) Add the CA cert for your server to the existing default CA certificate store. The default CA certificate store can changed at compile time with the following configure options:
--with-ca-bundle=FILE: use the specified file as CA certificate store. CA certificates need to be concatenated in PEM format into this file.
--with-ca-path=PATH: use the specified path as CA certificate store. CA certificates need to be stored as individual PEM files in this directory. You may need to run c_rehash after adding files there.
Do these settings only apply to command line or can libcurl be configured at compile time to always use the same CA info?
Thanks!
Do these settings only apply to command line or can libcurl be configured at compile time to always use the same CA info?
cURL has the same settings for compile time. More accurately, they are Autotools options.
curl-7.57.0$ ./configure --help
`configure' configures curl - to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
...
--with-ca-bundle=FILE Path to a file containing CA certificates (example:
/etc/ca-bundle.crt)
--without-ca-bundle Don't use a default CA bundle
--with-ca-path=DIRECTORY
Path to a directory containing CA certificates
stored individually, with their filenames in a hash
format. This option can be used with OpenSSL, GnuTLS
and PolarSSL backends. Refer to OpenSSL c_rehash for
details. (example: /etc/certificates)
--without-ca-path Don't use a default CA path
--with-ca-fallback Use the built in CA store of the SSL library
--without-ca-fallback Don't use the built in CA store of the SSL library
I build cURL on occasion for testing on older systems like CentOS 5. I find it is easiest to download an updated cacert.pem, and then use --with-ca-bundle.
If you want to use --with-ca-path, then that is the one where each certificate is hashed. So you will have a directory with 120 or 150 files in it. The files will have names like NNNNNNNN.0, NNNNNNNN.1 and so on. NNNNNNNN will be a hash, and collisions are resolved by incrementing the suffix.
I keep my script for building cURL online at Build-Scripts | build-curl.sh.

Could not upload files error in GitFTP

I'm following tutorial on http://anantgarg.com/2013/09/25/git-ftp-for-windows/ and get error:
$ git ftp init
There are 720 files to sync:
[1 of 720] Buffered for upload '.gitignore'.
[2 of 720] Buffered for upload 'wp-config-sample.php'.
....
[24 of 720] Buffered for upload 'wp-content/plugins/woocommerce/admin/post-types/writepanels/order-item-html.php'.
Uploading ...
fatal: Could not upload files., exiting...
what could be the problem? I've set the password using quotes ( 'mypassword' ) but same error still occur
You can see output of the exact error by using the '-v' flag for super-verbose output.
The problem could be one of the following
Incorrect FTP credentials - check that the server, username, and password are all correct.
URL/server: make sure to include the protocol with the URL if not standard FTP
(sftp://ftp.domain.com:22).
Password: Try also removing the quotes around the password
The server path is not set or incorrect. Often, an FTP login takes you to the server root. You may not have write-privileges there. You'll need to set the site root path.
try setting path with in the URL argument ftp://ftp.domain.com/public_html
Try doing an 'init' via command-line arguments instead (NOT via Git config settings) and set verbose output using '-v':
git ftp init -u username -p 'password' -v ftpserverurl.com
I think you should use ftp-git, it's a GUI tool to push changed files in git repository to ftp server. And it's more error-friendly.
You can check the changed files in GUI way, and it can save your ftp connection details for future use.

Error during raising review request in ReviewBoard

I have installed reviewboard. I added local GIT repository to it. During creation of review requests, the repository is available to be selected. But, when I am selecting a file from the repository and trying to add it as a Diff it says 'The selected file does not appear to be a diff.'. Please let me know if anyone has any answer for the question. Thanks....
git diff <filename1> ><filename2>.diff
This can be used for generating the diff file.
Some helpful tips for reviewboard are:
Log Settings:
Check/Tick - Enable logging
Log directory: /var/www/reviewboard
Log Level: Debug
Review board git configuration steps::
$ git config --global user.name "Chalpat Rauth"
$ git config --global user.email chalpat.rauth#ap.sony.com
You can veryify the entries in vim ~/.gitconfig
$ ssh-keygen -t rsa
copy the public key ./root/.ssh/id_rsa.pub to gitlab as a new key
chmod 700 -R /root/.ssh/
git clone git#gitlab.csx.sony.co.jp:testtest.git
During configuration in ReviewBoard:
Hosting service: None - Custom Repository
Repository Type: Git
Path: /var/www/reviewboard/code/testtest/.git
Note the below:
In path: /var/www/reviewboard/code/testtest/helloworld/src/test/java/com/sony/csx
git add <file_name>
git commit -m "This is second commit"
git push
git diff HEAD >DiffForReview
LDAP Settings::
Check/Tick - Allow anonymous read-only access
Authentication Method: LDAP
LDAP Server: ldap://ldap.csx.sony.co.jp
LDAP Base DN: dc=csx,dc=sony,dc=co,dc=jp
Surname Attribute: csxUsername1
Full Name Attribute: csxUsernameF
E-Mail LDAP Attribute: mail
User Mask: uid=%s