Automation in the context of multifactor authentication: Difference between revisions

Marked this version for translation
(Marked this version for translation)
Line 82: Line 82:
{{Command|rsync -a datadir/a robot:scratch/testdata}}
{{Command|rsync -a datadir/a robot:scratch/testdata}}


= IPv4 vs IPv6 issue =
= IPv4 vs IPv6 issue = <!--T:17-->


<!--T:18-->
When connecting to the robot node the SSH client on your computer may choose to use the '''IPv6 addressing''' over the older '''IPv4'''.
When connecting to the robot node the SSH client on your computer may choose to use the '''IPv6 addressing''' over the older '''IPv4'''.
This seems to be more probably in Windows environment.  
This seems to be more probably in Windows environment.  
Line 89: Line 90:
matches the type your computer will be using when connecting to the node.
matches the type your computer will be using when connecting to the node.


<!--T:19-->
You can check your addresses using this web site: https://test-ipv6.com/ .
You can check your addresses using this web site: https://test-ipv6.com/ .


<!--T:20-->
* An IPv4 address would look like '''199.241.166.5'''.
* An IPv4 address would look like '''199.241.166.5'''.
* An IPv6 address could be similar to '''2620:123:7002:4::5'''.
* An IPv6 address could be similar to '''2620:123:7002:4::5'''.


<!--T:21-->
The possible problem is that if you put the IPv4 address mask, '''199.241.166.*''' into the CCDB SSH key, and  
The possible problem is that if you put the IPv4 address mask, '''199.241.166.*''' into the CCDB SSH key, and  
your SSH client will be connecting the the robot node using IPv6 address, the source address will not match the mask in the key
your SSH client will be connecting the the robot node using IPv6 address, the source address will not match the mask in the key
and the key will not be accepted by the robot node.  
and the key will not be accepted by the robot node.  


=== How to identify the problem ===
=== How to identify the problem === <!--T:22-->


<!--T:23-->
If you are having difficulties to make the SSH connection to a robot node working.
If you are having difficulties to make the SSH connection to a robot node working.
Try this test command:
Try this test command:
  ssh -i ~/.ssh/automation_key -vvv username@robot.graham.alliancecan.ca "ls -l"  
  ssh -i ~/.ssh/automation_key -vvv username@robot.graham.alliancecan.ca "ls -l"  


<!--T:24-->
This command tries to connect to the robot node on Graham cluster and execute the <code>ls -l</code> command  
This command tries to connect to the robot node on Graham cluster and execute the <code>ls -l</code> command  
using the <code>~/.ssh/automation_key</code> SSH key.
using the <code>~/.ssh/automation_key</code> SSH key.
Then it prints the list of files in your home directory on Graham to screen.
Then it prints the list of files in your home directory on Graham to screen.


<!--T:25-->
This command will produce a lot of debug output due to the <code>-vvv</code> option (be Very Very Verbose).
This command will produce a lot of debug output due to the <code>-vvv</code> option (be Very Very Verbose).
Look for the '''Connecting to...''' message there.
Look for the '''Connecting to...''' message there.
Line 113: Line 120:
  debug1: Connecting to robot.graham.alliancecan.ca [199.241.166.5] port 22.
  debug1: Connecting to robot.graham.alliancecan.ca [199.241.166.5] port 22.


<!--T:26-->
it means the IPv4 is being used.
it means the IPv4 is being used.
If the message is similar to  
If the message is similar to  
  debug1: Connecting to robot.graham.alliancecan.ca [2620:123:7002:4::5] port 22.
  debug1: Connecting to robot.graham.alliancecan.ca [2620:123:7002:4::5] port 22.


<!--T:27-->
then IPv6 is being used to make the connection.
then IPv6 is being used to make the connection.


=== Possible solutions ===
=== Possible solutions === <!--T:28-->


<!--T:29-->
* You can make the SSH client to '''explicitly use either IPv4 or IPv6''' using the <code>-4</code> and <code>-6</code> options, respectively, to match the format you used for the key in CCDB.
* You can make the SSH client to '''explicitly use either IPv4 or IPv6''' using the <code>-4</code> and <code>-6</code> options, respectively, to match the format you used for the key in CCDB.


<!--T:30-->
* You can try using an '''IP address instead of the name''' to point to the robot node. Using Graham example, try using the  
* You can try using an '''IP address instead of the name''' to point to the robot node. Using Graham example, try using the  
: <code>ssh -i ~/.ssh/automation_key -vvv username@199.241.166.5 "ls -l"</code>
: <code>ssh -i ~/.ssh/automation_key -vvv username@199.241.166.5 "ls -l"</code>
: instead, to force SSH to use the IPv4 addresses.
: instead, to force SSH to use the IPv4 addresses.


<!--T:31-->
* You can try to '''disable the IPv6 addressing''' for your system, to make sure that only IPv4 is used.
* You can try to '''disable the IPv6 addressing''' for your system, to make sure that only IPv4 is used.
: Currently, there should not be any negative impact on your system. However, Microsoft does not recommend this, and this should be your '''last resort''' method, if nothing else works.
: Currently, there should not be any negative impact on your system. However, Microsoft does not recommend this, and this should be your '''last resort''' method, if nothing else works.
: How to disable IPv6 will depend on your system and the operating system.
: How to disable IPv6 will depend on your system and the operating system.


= Automation using Python and Paramiko =
= Automation using Python and Paramiko = <!--T:32-->


<!--T:33-->
If you are using the [https://www.paramiko.org/index.html Paramiko Python module] to automate your workflow, this is how you can make it work with the robot nodes:
If you are using the [https://www.paramiko.org/index.html Paramiko Python module] to automate your workflow, this is how you can make it work with the robot nodes:
<source lang=python>
<source lang=python>
Line 142: Line 155:
# ====================================================================================================
# ====================================================================================================


<!--T:34-->
key = paramiko.Ed25519Key.from_private_key_file("/home/username/.ssh/cc_allowed")
key = paramiko.Ed25519Key.from_private_key_file("/home/username/.ssh/cc_allowed")


<!--T:35-->
user = "username"
user = "username"
host = "robot.graham.alliancecan.ca"
host = "robot.graham.alliancecan.ca"


<!--T:36-->
ssh = paramiko.SSHClient()
ssh = paramiko.SSHClient()


<!--T:37-->
# If the host is not known, it is OK.
# If the host is not known, it is OK.
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())


<!--T:38-->
ssh.connect(hostname=host, username=user, pkey=key)
ssh.connect(hostname=host, username=user, pkey=key)


<!--T:39-->
cmd = "ls -l"
cmd = "ls -l"
stdin, stdout, stderr = ssh.exec_command(cmd)
stdin, stdout, stderr = ssh.exec_command(cmd)


<!--T:40-->
print("".join(stdout.readlines()))
print("".join(stdout.readlines()))


<!--T:41-->
ssh.close()
ssh.close()
# ====================================================================================================
# ====================================================================================================
Line 166: Line 187:
Then prints the list to the screen.
Then prints the list to the screen.


<!--T:42-->
Note, that it is important to install '''paramiko''' with the
Note, that it is important to install '''paramiko''' with the
  $ pip install paramiko[all]
  $ pip install paramiko[all]


<!--T:43-->
command. This will make sure that the support for the '''Ed25519''' key type will also be installed.
command. This will make sure that the support for the '''Ed25519''' key type will also be installed.


</translate>
</translate>
rsnt_translations
56,420

edits